mirror of
https://github.com/NoiTheCat/WorldTime.git
synced 2024-11-21 14:34:36 +00:00
Implement code style suggestions
This commit is contained in:
parent
095cf95308
commit
cc32d534dc
4 changed files with 12 additions and 8 deletions
|
@ -76,9 +76,9 @@ public class UserCommands : CommandsBase {
|
||||||
// Generate time and zone names to be displayed, group with associated user IDs
|
// Generate time and zone names to be displayed, group with associated user IDs
|
||||||
var sortedlist = new SortedDictionary<string, List<ulong>>();
|
var sortedlist = new SortedDictionary<string, List<ulong>>();
|
||||||
var ampm = db.GuildSettings.Where(s => s.GuildId == Context.Guild.Id).SingleOrDefault()?.Use12HourTime ?? false;
|
var ampm = db.GuildSettings.Where(s => s.GuildId == Context.Guild.Id).SingleOrDefault()?.Use12HourTime ?? false;
|
||||||
foreach ((string area, List<ulong> users) in userlist.OrderByDescending(o => o.Value.Count)) {
|
foreach ((var area, List<ulong> users) in userlist.OrderByDescending(o => o.Value.Count)) {
|
||||||
var areaprint = TzPrint(area, ampm);
|
var areaprint = TzPrint(area, ampm);
|
||||||
if (!sortedlist.ContainsKey(areaprint)) sortedlist.Add(areaprint, new List<ulong>());
|
if (!sortedlist.ContainsKey(areaprint)) sortedlist[areaprint] = [];
|
||||||
sortedlist[areaprint].AddRange(users);
|
sortedlist[areaprint].AddRange(users);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,10 +87,10 @@ public class UserCommands : CommandsBase {
|
||||||
|
|
||||||
// Build zone listings with users
|
// Build zone listings with users
|
||||||
var outputlines = new List<string>();
|
var outputlines = new List<string>();
|
||||||
foreach ((string area, List<ulong> users) in sortedlist) {
|
foreach ((var area, List<ulong> users) in sortedlist) {
|
||||||
var buffer = new StringBuilder();
|
var buffer = new StringBuilder();
|
||||||
buffer.Append(area[6..] + ": ");
|
buffer.Append(area[6..] + ": ");
|
||||||
bool empty = true;
|
var empty = true;
|
||||||
foreach (var userid in users) {
|
foreach (var userid in users) {
|
||||||
var userinstance = Context.Guild.GetUser(userid);
|
var userinstance = Context.Guild.GetUser(userid);
|
||||||
if (userinstance == null) continue;
|
if (userinstance == null) continue;
|
||||||
|
@ -107,7 +107,7 @@ public class UserCommands : CommandsBase {
|
||||||
|
|
||||||
// Prepare for output - send buffers out if they become too large
|
// Prepare for output - send buffers out if they become too large
|
||||||
outputlines.Sort();
|
outputlines.Sort();
|
||||||
bool hasOutputOneLine = false;
|
var hasOutputOneLine = false;
|
||||||
// First output is shown as an interaction response, followed then as regular channel messages
|
// First output is shown as an interaction response, followed then as regular channel messages
|
||||||
async Task doOutput(Embed msg) {
|
async Task doOutput(Embed msg) {
|
||||||
if (!hasOutputOneLine) {
|
if (!hasOutputOneLine) {
|
||||||
|
@ -137,7 +137,7 @@ public class UserCommands : CommandsBase {
|
||||||
using var db = DbContext;
|
using var db = DbContext;
|
||||||
var result = db.GetUserZone(parameter);
|
var result = db.GetUserZone(parameter);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
bool isself = Context.User.Id == parameter.Id;
|
var isself = Context.User.Id == parameter.Id;
|
||||||
if (isself) await RespondAsync(":x: You do not have a time zone. Set it with `tz.set`.", ephemeral: true);
|
if (isself) await RespondAsync(":x: You do not have a time zone. Set it with `tz.set`.", ephemeral: true);
|
||||||
else await RespondAsync(":x: The given user does not have a time zone set.", ephemeral: true);
|
else await RespondAsync(":x: The given user does not have a time zone set.", ephemeral: true);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class BotDatabaseContext : DbContext {
|
||||||
select Tuple.Create(entry.TimeZone, (ulong)entry.UserId);
|
select Tuple.Create(entry.TimeZone, (ulong)entry.UserId);
|
||||||
var resultSet = new Dictionary<string, List<ulong>>();
|
var resultSet = new Dictionary<string, List<ulong>>();
|
||||||
foreach (var (tz, user) in query) {
|
foreach (var (tz, user) in query) {
|
||||||
if (!resultSet.ContainsKey(tz)) resultSet.Add(tz, new List<ulong>());
|
if (!resultSet.ContainsKey(tz)) resultSet[tz] = [];
|
||||||
resultSet[tz].Add(user);
|
resultSet[tz].Add(user);
|
||||||
}
|
}
|
||||||
return resultSet;
|
return resultSet;
|
||||||
|
|
4
Data/Migrations/.editorconfig
Normal file
4
Data/Migrations/.editorconfig
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[*.cs]
|
||||||
|
generated_code = true
|
||||||
|
dotnet_analyzer_diagnostic.category-CodeQuality.severity = none
|
||||||
|
dotnet_diagnostic.CS1591.severity = none
|
|
@ -104,7 +104,7 @@ internal class WorldTime : IDisposable {
|
||||||
// Discord Bots
|
// Discord Bots
|
||||||
if (!string.IsNullOrEmpty(Config.DBotsToken)) {
|
if (!string.IsNullOrEmpty(Config.DBotsToken)) {
|
||||||
try {
|
try {
|
||||||
string dBotsApiUrl = $"https://discord.bots.gg/api/v1/bots/{ botId }/stats";
|
var dBotsApiUrl = $"https://discord.bots.gg/api/v1/bots/{ botId }/stats";
|
||||||
var body = $"{{ \"guildCount\": {guildCount} }}";
|
var body = $"{{ \"guildCount\": {guildCount} }}";
|
||||||
var uri = new Uri(string.Format(dBotsApiUrl));
|
var uri = new Uri(string.Format(dBotsApiUrl));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue