diff --git a/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs b/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs index fd954a4b..fe4a328b 100644 --- a/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs @@ -74,8 +74,8 @@ namespace NadekoBot.Modules.Administration var title = $"DM from [{msg.Author}]({msg.Author.Id})"; if (ForwardDMsToAllOwners) { - var msgs = await Task.WhenAll(ownerChannels.Where(ch => ch.Recipient.Id != msg.Author.Id) - .Select(ch => ch.SendConfirmAsync(title, msg.Content))).ConfigureAwait(false); + await Task.WhenAll(ownerChannels.Where(ch => ch.Recipient.Id != msg.Author.Id) + .Select(ch => ch.SendConfirmAsync(title, msg.Content))).ConfigureAwait(false); } else { diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 4219ff98..c5183692 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -35,19 +35,15 @@ namespace NadekoBot.Modules.Administration private static ConcurrentDictionary> PresenceUpdates { get; } = new ConcurrentDictionary>(); private static Timer timerReference { get; } - private IGoogleApiService _google { get; } static LogCommands() { _client = NadekoBot.Client; _log = LogManager.GetCurrentClassLogger(); var sw = Stopwatch.StartNew(); - - using (var uow = DbHandler.UnitOfWork()) - { - GuildLogSettings = new ConcurrentDictionary(NadekoBot.AllGuildConfigs - .ToDictionary(g => g.GuildId, g => g.LogSetting)); - } + + GuildLogSettings = new ConcurrentDictionary(NadekoBot.AllGuildConfigs + .ToDictionary(g => g.GuildId, g => g.LogSetting)); timerReference = new Timer(async (state) => { @@ -59,7 +55,11 @@ namespace NadekoBot.Modules.Administration { List messages; if (PresenceUpdates.TryRemove(key, out messages)) - try { await key.SendConfirmAsync("Presence Updates", string.Join(Environment.NewLine, messages)); } catch { } + try { await key.SendConfirmAsync("Presence Updates", string.Join(Environment.NewLine, messages)); } + catch + { + // ignored + } })); } catch (Exception ex) @@ -159,7 +159,9 @@ namespace NadekoBot.Modules.Administration //} } catch - { } + { + // ignored + } } private static async Task _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after) @@ -188,7 +190,7 @@ namespace NadekoBot.Modules.Administration var str = ""; if (beforeVch?.Guild == afterVch?.Guild) { - str = $"{usr.Username} moved from {beforeVch.Name} to {afterVch.Name}"; + str = $"{usr.Username} moved from {beforeVch?.Name} to {afterVch?.Name}"; } else if (beforeVch == null) { @@ -201,7 +203,10 @@ namespace NadekoBot.Modules.Administration var toDelete = await logChannel.SendMessageAsync(str, true).ConfigureAwait(false); toDelete.DeleteAfter(5); } - catch { } + catch + { + // ignored + } } private static async void MuteCommands_UserMuted(IGuildUser usr, MuteCommands.MuteType muteType) @@ -216,7 +221,7 @@ namespace NadekoBot.Modules.Administration ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) return; - string mutes = ""; + var mutes = ""; switch (muteType) { case MuteCommands.MuteType.Voice: diff --git a/src/NadekoBot/Modules/Administration/Commands/Migration.cs b/src/NadekoBot/Modules/Administration/Commands/Migration.cs index 3a917698..883e5d4b 100644 --- a/src/NadekoBot/Modules/Administration/Commands/Migration.cs +++ b/src/NadekoBot/Modules/Administration/Commands/Migration.cs @@ -103,11 +103,8 @@ namespace NadekoBot.Modules.Administration var greetChannel = (ulong)(long)reader["GreetChannelId"]; var greetMsg = (string)reader["GreetText"]; var bye = (long)reader["Bye"] == 1; - var byeDM = (long)reader["ByePM"] == 1; var byeChannel = (ulong)(long)reader["ByeChannelId"]; var byeMsg = (string)reader["ByeText"]; - var grdel = false; - var byedel = grdel; var gc = uow.GuildConfigs.For(gid, set => set); if (greetDM) @@ -121,7 +118,6 @@ namespace NadekoBot.Modules.Administration gc.ByeMessageChannelId = byeChannel; gc.ChannelByeMessageText = byeMsg; - gc.AutoDeleteGreetMessagesTimer = gc.AutoDeleteByeMessagesTimer = grdel ? 30 : 0; _log.Info(++i); } } @@ -129,12 +125,12 @@ namespace NadekoBot.Modules.Administration _log.Warn("Greet/bye messages won't be migrated"); } var com2 = db.CreateCommand(); - com.CommandText = "SELECT * FROM CurrencyState GROUP BY UserId"; + com2.CommandText = "SELECT * FROM CurrencyState GROUP BY UserId"; i = 0; try { - var reader2 = com.ExecuteReader(); + var reader2 = com2.ExecuteReader(); while (reader2.Read()) { _log.Info(++i); @@ -203,7 +199,6 @@ namespace NadekoBot.Modules.Administration guildConfig.ExclusiveSelfAssignedRoles = data.ExclusiveSelfAssignedRoles; guildConfig.GenerateCurrencyChannelIds = new HashSet(data.GenerateCurrencyChannels.Select(gc => new GCChannelId() { ChannelId = gc.Key })); selfAssRoles.AddRange(data.ListOfSelfAssignableRoles.Select(r => new SelfAssignedRole() { GuildId = guildConfig.GuildId, RoleId = r }).ToArray()); - var logSetting = guildConfig.LogSetting; guildConfig.LogSetting.IgnoredChannels = new HashSet(data.LogserverIgnoreChannels.Select(id => new IgnoredLogChannel() { ChannelId = id })); guildConfig.LogSetting.LogUserPresenceId = data.LogPresenceChannel; @@ -249,7 +244,7 @@ namespace NadekoBot.Modules.Administration private void MigratePermissions0_9(IUnitOfWork uow) { - var PermissionsDict = new ConcurrentDictionary(); + var permissionsDict = new ConcurrentDictionary(); if (!Directory.Exists("data/permissions/")) { _log.Warn("No data from permissions will be migrated."); @@ -263,12 +258,15 @@ namespace NadekoBot.Modules.Administration if (string.IsNullOrWhiteSpace(strippedFileName)) continue; var id = ulong.Parse(strippedFileName); var data = JsonConvert.DeserializeObject(File.ReadAllText(file)); - PermissionsDict.TryAdd(id, data); + permissionsDict.TryAdd(id, data); + } + catch + { + // ignored } - catch { } } var i = 0; - PermissionsDict + permissionsDict .Select(p => new { data = p.Value, gconfig = uow.GuildConfigs.For(p.Key) }) .AsParallel() .ForAll(perms => diff --git a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs index f37a26ec..89ef6ec6 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs @@ -36,8 +36,6 @@ namespace NadekoBot.Modules.Administration static MuteCommands() { - var _log = LogManager.GetCurrentClassLogger(); - var configs = NadekoBot.AllGuildConfigs; GuildMuteRoles = new ConcurrentDictionary(configs .Where(c => !string.IsNullOrWhiteSpace(c.MuteRoleName)) diff --git a/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs index 7639a4dc..ff671a98 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs @@ -402,8 +402,6 @@ namespace NadekoBot.Modules.Administration [RequireContext(ContextType.Guild)] public async Task AntiList() { - var channel = (ITextChannel)Context.Channel; - AntiSpamStats spam; antiSpamGuilds.TryGetValue(Context.Guild.Id, out spam); diff --git a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs index ccff187d..8ed81849 100644 --- a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs @@ -37,26 +37,22 @@ namespace NadekoBot.Modules.Administration public bool CheckUserRatelimit(ulong id) { - RatelimitedUser usr = Users.GetOrAdd(id, (key) => new RatelimitedUser() { UserId = id }); + var usr = Users.GetOrAdd(id, (key) => new RatelimitedUser() { UserId = id }); if (usr.MessageCount == MaxMessages) { return true; } - else + usr.MessageCount++; + var _ = Task.Run(async () => { - usr.MessageCount++; - var t = Task.Run(async () => + try { - try - { - await Task.Delay(PerSeconds * 1000, cancelSource.Token); - } - catch (OperationCanceledException) { } - usr.MessageCount--; - }); - return false; - } - + await Task.Delay(PerSeconds * 1000, cancelSource.Token); + } + catch (OperationCanceledException) { } + usr.MessageCount--; + }); + return false; } } diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs index 6c1be19e..7c58fbfd 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs @@ -18,10 +18,10 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class ServerGreetCommands : ModuleBase + public class ServerGreetCommands : NadekoSubmodule { //make this to a field in the guildconfig table - class GreetSettings + private class GreetSettings { public int AutoDeleteGreetMessagesTimer { get; set; } public int AutoDeleteByeMessagesTimer { get; set; } @@ -129,7 +129,10 @@ namespace NadekoBot.Modules.Administration catch (Exception ex) { _log.Warn(ex); } } } - catch { } + catch + { + // ignored + } }); return Task.CompletedTask; } @@ -212,7 +215,10 @@ namespace NadekoBot.Modules.Administration } } } - catch { } + catch + { + // ignored + } }); return Task.CompletedTask; } @@ -222,7 +228,6 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task GreetDel(int timer = 30) { - var channel = (ITextChannel)Context.Channel; if (timer < 0 || timer > 600) return; @@ -375,7 +380,7 @@ namespace NadekoBot.Modules.Administration await Context.Channel.SendConfirmAsync("🆗 New DM greet message **set**.").ConfigureAwait(false); if (!sendGreetEnabled) - await Context.Channel.SendConfirmAsync($"ℹī¸ Enable DM greet messsages by typing `{NadekoBot.ModulePrefixes[typeof(Administration).Name]}greetdm`").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"ℹī¸ Enable DM greet messsages by typing `{Prefix}greetdm`").ConfigureAwait(false); } public static bool SetGreetDmMessage(ulong guildId, ref string message) @@ -450,7 +455,7 @@ namespace NadekoBot.Modules.Administration await Context.Channel.SendConfirmAsync("🆗 New bye message **set**.").ConfigureAwait(false); if (!sendByeEnabled) - await Context.Channel.SendConfirmAsync($"ℹī¸ Enable bye messsages by typing `{NadekoBot.ModulePrefixes[typeof(Administration).Name]}bye`").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"ℹī¸ Enable bye messsages by typing `{Prefix}bye`").ConfigureAwait(false); } public static bool SetByeMessage(ulong guildId, ref string message) diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index 392b4e88..dba5bb3a 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -30,10 +30,8 @@ namespace NadekoBot.Modules.Administration { var _log = LogManager.GetCurrentClassLogger(); var sw = Stopwatch.StartNew(); - using (var uow = DbHandler.UnitOfWork()) - { - voicePlusTextCache = new ConcurrentHashSet(NadekoBot.AllGuildConfigs.Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId)); - } + + voicePlusTextCache = new ConcurrentHashSet(NadekoBot.AllGuildConfigs.Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId)); NadekoBot.Client.UserVoiceStateUpdated += UserUpdatedEventHandler; sw.Stop(); diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index 1ed31a6e..37f07efa 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -23,12 +23,8 @@ namespace NadekoBot.Modules.ClashOfClans private static Timer checkWarTimer { get; } - private static new readonly Logger _log; - static ClashOfClans() { - _log = LogManager.GetCurrentClassLogger(); - var sw = Stopwatch.StartNew(); using (var uow = DbHandler.UnitOfWork()) { ClashWars = new ConcurrentDictionary>( @@ -244,7 +240,6 @@ namespace NadekoBot.Modules.ClashOfClans SaveWar(war); await ReplyConfirmLocalized("war_ended", warsInfo.Item1[warsInfo.Item2].ShortPrint()).ConfigureAwait(false); - var size = warsInfo.Item1[warsInfo.Item2].Size; warsInfo.Item1.RemoveAt(warsInfo.Item2); } diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index 295d7e37..ebeb4922 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -165,7 +165,7 @@ namespace NadekoBot.Modules.CustomReactions } else { - var reactions = GuildReactions.AddOrUpdate(Context.Guild.Id, + GuildReactions.AddOrUpdate(Context.Guild.Id, new CustomReaction[] { cr }, (k, old) => { diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index f2b6404c..78de87e6 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -17,7 +17,7 @@ namespace NadekoBot.Modules.Gambling public partial class Gambling { [Group] - public class AnimalRacing : ModuleBase + public class AnimalRacing : NadekoSubmodule { public static ConcurrentDictionary AnimalRaces { get; } = new ConcurrentDictionary(); @@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Gambling [RequireContext(ContextType.Guild)] public async Task Race() { - var ar = new AnimalRace(Context.Guild.Id, (ITextChannel)Context.Channel); + var ar = new AnimalRace(Context.Guild.Id, (ITextChannel)Context.Channel, Prefix); if (ar.Fail) await Context.Channel.SendErrorAsync("🏁 `Failed starting a race. Another race is probably running.`").ConfigureAwait(false); @@ -59,13 +59,16 @@ namespace NadekoBot.Modules.Gambling public List participants = new List(); private ulong serverId; private int messagesSinceGameStarted = 0; + private readonly string _prefix; + private Logger _log { get; } public ITextChannel raceChannel { get; set; } public bool Started { get; private set; } = false; - public AnimalRace(ulong serverId, ITextChannel ch) + public AnimalRace(ulong serverId, ITextChannel ch, string prefix) { + this._prefix = prefix; this._log = LogManager.GetCurrentClassLogger(); this.serverId = serverId; this.raceChannel = ch; @@ -74,11 +77,8 @@ namespace NadekoBot.Modules.Gambling Fail = true; return; } - - using (var uow = DbHandler.UnitOfWork()) - { - animals = new ConcurrentQueue(NadekoBot.BotConfig.RaceAnimals.Select(ra => ra.Icon).Shuffle()); - } + + animals = new ConcurrentQueue(NadekoBot.BotConfig.RaceAnimals.Select(ra => ra.Icon).Shuffle()); var cancelSource = new CancellationTokenSource(); @@ -91,7 +91,7 @@ namespace NadekoBot.Modules.Gambling try { await raceChannel.SendConfirmAsync("Animal Race", $"Starting in 20 seconds or when the room is full.", - footer: $"Type {NadekoBot.ModulePrefixes[typeof(Gambling).Name]}jr to join the race."); + footer: $"Type {_prefix}jr to join the race."); } catch (Exception ex) { @@ -280,9 +280,7 @@ namespace NadekoBot.Modules.Gambling public override bool Equals(object obj) { var p = obj as Participant; - return p == null ? - false : - p.User == User; + return p != null && p.User == User; } public override string ToString() diff --git a/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs b/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs index 5647b3e4..02c8803e 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs @@ -43,22 +43,15 @@ namespace NadekoBot.Modules.Gambling [OwnerOnly] public async Task StartEvent(CurrencyEvent e, int arg = -1) { - var channel = (ITextChannel)Context.Channel; - try + switch (e) { - switch (e) - { - case CurrencyEvent.FlowerReaction: - await FlowerReactionEvent(Context).ConfigureAwait(false); - break; - case CurrencyEvent.SneakyGameStatus: - await SneakyGameStatusEvent(Context, arg).ConfigureAwait(false); - break; - default: - break; - } + case CurrencyEvent.FlowerReaction: + await FlowerReactionEvent(Context).ConfigureAwait(false); + break; + case CurrencyEvent.SneakyGameStatus: + await SneakyGameStatusEvent(Context, arg).ConfigureAwait(false); + break; } - catch { } } public static async Task SneakyGameStatusEvent(CommandContext Context, int? arg) @@ -77,8 +70,7 @@ namespace NadekoBot.Modules.Gambling { _secretCode += _sneakyGameStatusChars[rng.Next(0, _sneakyGameStatusChars.Length)]; } - - var game = NadekoBot.Client.Game?.Name; + await NadekoBot.Client.SetGameAsync($"type {_secretCode} for " + NadekoBot.BotConfig.CurrencyPluralName) .ConfigureAwait(false); try @@ -88,7 +80,10 @@ namespace NadekoBot.Modules.Gambling $"Lasts {num} seconds. Don't tell anyone. Shhh.") .ConfigureAwait(false); } - catch { } + catch + { + // ignored + } NadekoBot.Client.MessageReceived += SneakyGameMessageReceivedEventHandler; @@ -114,15 +109,18 @@ namespace NadekoBot.Modules.Gambling .ConfigureAwait(false); try { await arg.DeleteAsync(new RequestOptions() { RetryMode = RetryMode.AlwaysFail }).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } }); } return Task.Delay(0); } - public static Task FlowerReactionEvent(CommandContext Context) => - new FlowerReactionEvent().Start(Context); + public static Task FlowerReactionEvent(CommandContext context) => + new FlowerReactionEvent().Start(context); } } @@ -163,7 +161,7 @@ namespace NadekoBot.Modules.Gambling if (msg?.Id == id) { _log.Warn("Stopping flower reaction event because message is deleted."); - Task.Run(() => End()); + var __ = Task.Run(End); } return Task.CompletedTask; @@ -194,10 +192,14 @@ namespace NadekoBot.Modules.Gambling { if (r.Emoji.Name == "🌸" && r.User.IsSpecified && ((DateTime.UtcNow - r.User.Value.CreatedAt).TotalDays > 5) && _flowerReactionAwardedUsers.Add(r.User.Value.Id)) { - try { await CurrencyHandler.AddCurrencyAsync(r.User.Value, "Flower Reaction Event", 100, false).ConfigureAwait(false); } catch { } + await CurrencyHandler.AddCurrencyAsync(r.User.Value, "Flower Reaction Event", 100, false) + .ConfigureAwait(false); } } - catch { } + catch + { + // ignored + } })) { try diff --git a/src/NadekoBot/Modules/Gambling/Commands/Slots.cs b/src/NadekoBot/Modules/Gambling/Commands/Slots.cs index 989d3789..bd977e9b 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/Slots.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/Slots.cs @@ -260,7 +260,7 @@ namespace NadekoBot.Modules.Gambling } finally { - var t = Task.Run(async () => + var _ = Task.Run(async () => { await Task.Delay(2000); runningUsers.Remove(Context.User.Id); diff --git a/src/NadekoBot/Modules/Gambling/Commands/WaifuClaimCommands.cs b/src/NadekoBot/Modules/Gambling/Commands/WaifuClaimCommands.cs index 1d1f414f..1426bebd 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/WaifuClaimCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/WaifuClaimCommands.cs @@ -197,8 +197,6 @@ namespace NadekoBot.Modules.Gambling [RequireContext(ContextType.Guild)] public async Task Divorce([Remainder]IUser target) { - var channel = (ITextChannel)Context.Channel; - if (target.Id == Context.User.Id) return; diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 555f55cb..6bcf5654 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -103,7 +103,6 @@ namespace NadekoBot.Modules.Gambling [Priority(0)] public async Task Award(int amount, [Remainder] IRole role) { - var channel = (ITextChannel)Context.Channel; var users = (await Context.Guild.GetUsersAsync()) .Where(u => u.GetRoles().Contains(role)) .ToList(); diff --git a/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs b/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs index b6544256..0541a4ae 100644 --- a/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs @@ -21,12 +21,6 @@ namespace NadekoBot.Modules.Games { private static Logger _log { get; } - class CleverAnswer - { - public string Status { get; set; } - public string Response { get; set; } - } - public static ConcurrentDictionary> CleverbotGuilds { get; } = new ConcurrentDictionary>(); static CleverBotCommands() @@ -34,14 +28,12 @@ namespace NadekoBot.Modules.Games _log = LogManager.GetCurrentClassLogger(); var sw = Stopwatch.StartNew(); - using (var uow = DbHandler.UnitOfWork()) - { - var bot = ChatterBotFactory.Create(ChatterBotType.CLEVERBOT); - CleverbotGuilds = new ConcurrentDictionary>( - NadekoBot.AllGuildConfigs - .Where(gc => gc.CleverbotEnabled) - .ToDictionary(gc => gc.GuildId, gc => new Lazy(() => bot.CreateSession(), true))); - } + + var bot = ChatterBotFactory.Create(ChatterBotType.CLEVERBOT); + CleverbotGuilds = new ConcurrentDictionary>( + NadekoBot.AllGuildConfigs + .Where(gc => gc.CleverbotEnabled) + .ToDictionary(gc => gc.GuildId, gc => new Lazy(() => bot.CreateSession(), true))); sw.Stop(); _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); diff --git a/src/NadekoBot/Modules/Games/Commands/HangmanCommands.cs b/src/NadekoBot/Modules/Games/Commands/HangmanCommands.cs index 4d499301..83637a62 100644 --- a/src/NadekoBot/Modules/Games/Commands/HangmanCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/HangmanCommands.cs @@ -23,7 +23,8 @@ namespace NadekoBot.Modules.Games static HangmanCommands() { _log = LogManager.GetCurrentClassLogger(); - typesStr = $"`List of \"{NadekoBot.ModulePrefixes[typeof(Games).Name]}hangman\" term types:`\n" + String.Join(", ", HangmanTermPool.data.Keys); + typesStr = + string.Format("`List of \"{0}hangman\" term types:`\n", NadekoBot.ModulePrefixes[typeof(Games).Name]) + String.Join(", ", HangmanTermPool.data.Keys); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index f664a7f2..43cbf52f 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -29,7 +29,7 @@ namespace NadekoBot.Modules.Games /// https://discord.gg/0TYNJfCU4De7YIk8 /// [Group] - public class PlantPickCommands : ModuleBase + public class PlantPickCommands : NadekoSubmodule { private static ConcurrentHashSet generationChannels { get; } = new ConcurrentHashSet(); //channelid/message @@ -103,7 +103,8 @@ namespace NadekoBot.Modules.Games var sent = await channel.SendFileAsync( fileStream, file.Key, - $"❗ {firstPart} Pick it up by typing `{NadekoBot.ModulePrefixes[typeof(Games).Name]}pick`") + string.Format("❗ {0} Pick it up by typing `{1}pick`", firstPart, + NadekoBot.ModulePrefixes[typeof(Games).Name])) .ConfigureAwait(false); msgs[0] = sent; @@ -160,7 +161,7 @@ namespace NadekoBot.Modules.Games var imgData = GetRandomCurrencyImage(); var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(NadekoBot.BotConfig.CurrencyName[0]); - var msgToSend = $"Oh how Nice! **{Context.User.Username}** planted {(amount == 1 ? (vowelFirst ? "an" : "a") : amount.ToString())} {(amount > 1 ? NadekoBot.BotConfig.CurrencyPluralName : NadekoBot.BotConfig.CurrencyName)}. Pick it using {NadekoBot.ModulePrefixes[typeof(Games).Name]}pick"; + var msgToSend = $"Oh how Nice! **{Context.User.Username}** planted {(amount == 1 ? (vowelFirst ? "an" : "a") : amount.ToString())} {(amount > 1 ? NadekoBot.BotConfig.CurrencyPluralName : NadekoBot.BotConfig.CurrencyName)}. Pick it using {Prefix}pick"; IUserMessage msg; using (var toSend = imgData.Value.ToStream()) diff --git a/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs b/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs index 4879793b..de36fe3b 100644 --- a/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs +++ b/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs @@ -307,7 +307,7 @@ namespace NadekoBot.Modules.Games var del2 = previousMessage?.DeleteAsync(); try { previousMessage = await _channel.EmbedAsync(GetEmbed(reason)); } catch { } try { await del1; } catch { } - try { await del2; } catch { } + try { if (del2 != null) await del2; } catch { } }); curUserIndex ^= 1; diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index e0dbb2c3..b10869b8 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -32,7 +32,6 @@ namespace NadekoBot.Modules.Games { if (string.IsNullOrWhiteSpace(question)) return; - var rng = new NadekoRandom(); await Context.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor) .AddField(efb => efb.WithName("❓ Question").WithValue(question).WithIsInline(false)) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index bae06919..fa7012fd 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -415,27 +415,26 @@ namespace NadekoBot.Modules.Music var arg = directory; if (string.IsNullOrWhiteSpace(arg)) return; - try + var dir = new DirectoryInfo(arg); + var fileEnum = dir.GetFiles("*", SearchOption.AllDirectories) + .Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)); + var gusr = (IGuildUser)Context.User; + foreach (var file in fileEnum) { - var dir = new DirectoryInfo(arg); - var fileEnum = dir.GetFiles("*", SearchOption.AllDirectories) - .Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)); - var gusr = (IGuildUser)Context.User; - foreach (var file in fileEnum) + try { - try - { - await QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false); - } - catch (PlaylistFullException) - { - break; - } - catch { } + await QueueSong(gusr, (ITextChannel)Context.Channel, gusr.VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false); + } + catch (PlaylistFullException) + { + break; + } + catch + { + // ignored } - await Context.Channel.SendConfirmAsync("đŸŽĩ Directory queue complete.").ConfigureAwait(false); } - catch { } + await Context.Channel.SendConfirmAsync("đŸŽĩ Directory queue complete.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs index fbb41acd..80b8067b 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs @@ -101,23 +101,23 @@ namespace NadekoBot.Modules.Permissions { return true; } - else + activeCdsForGuild.Add(new ActiveCooldown() { - activeCdsForGuild.Add(new ActiveCooldown() + UserId = user.Id, + Command = cmd.Aliases.First().ToLowerInvariant(), + }); + var _ = Task.Run(async () => + { + try { - UserId = user.Id, - Command = cmd.Aliases.First().ToLowerInvariant(), - }); - var t = Task.Run(async () => + await Task.Delay(cdRule.Seconds * 1000); + activeCdsForGuild.RemoveWhere(ac => ac.Command == cmd.Aliases.First().ToLowerInvariant() && ac.UserId == user.Id); + } + catch { - try - { - await Task.Delay(cdRule.Seconds * 1000); - activeCdsForGuild.RemoveWhere(ac => ac.Command == cmd.Aliases.First().ToLowerInvariant() && ac.UserId == user.Id); - } - catch { } - }); - } + // ignored + } + }); } return false; } diff --git a/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs index 2d0376e1..2576ac78 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs @@ -42,23 +42,19 @@ namespace NadekoBot.Modules.Permissions static FilterCommands() { - using (var uow = DbHandler.UnitOfWork()) - { - var guildConfigs = NadekoBot.AllGuildConfigs; + var guildConfigs = NadekoBot.AllGuildConfigs; - InviteFilteringServers = new ConcurrentHashSet(guildConfigs.Where(gc => gc.FilterInvites).Select(gc => gc.GuildId)); - InviteFilteringChannels = new ConcurrentHashSet(guildConfigs.SelectMany(gc => gc.FilterInvitesChannelIds.Select(fci => fci.ChannelId))); + InviteFilteringServers = new ConcurrentHashSet(guildConfigs.Where(gc => gc.FilterInvites).Select(gc => gc.GuildId)); + InviteFilteringChannels = new ConcurrentHashSet(guildConfigs.SelectMany(gc => gc.FilterInvitesChannelIds.Select(fci => fci.ChannelId))); - var dict = guildConfigs.ToDictionary(gc => gc.GuildId, gc => new ConcurrentHashSet(gc.FilteredWords.Select(fw => fw.Word))); + var dict = guildConfigs.ToDictionary(gc => gc.GuildId, gc => new ConcurrentHashSet(gc.FilteredWords.Select(fw => fw.Word))); - ServerFilteredWords = new ConcurrentDictionary>(dict); + ServerFilteredWords = new ConcurrentDictionary>(dict); - var serverFiltering = guildConfigs.Where(gc => gc.FilterWords); - WordFilteringServers = new ConcurrentHashSet(serverFiltering.Select(gc => gc.GuildId)); + var serverFiltering = guildConfigs.Where(gc => gc.FilterWords); + WordFilteringServers = new ConcurrentHashSet(serverFiltering.Select(gc => gc.GuildId)); - WordFilteringChannels = new ConcurrentHashSet(guildConfigs.SelectMany(gc => gc.FilterWordsChannelIds.Select(fwci => fwci.ChannelId))); - - } + WordFilteringChannels = new ConcurrentHashSet(guildConfigs.SelectMany(gc => gc.FilterWordsChannelIds.Select(fwci => fwci.ChannelId))); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs index c1d2eef9..bf05f0ac 100644 --- a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs @@ -230,7 +230,7 @@ namespace NadekoBot.Modules.Searches var link = "http://anilist.co/api/anime/search/" + Uri.EscapeUriString(query); using (var http = new HttpClient()) { - var res = await http.GetStringAsync("http://anilist.co/api/anime/search/" + Uri.EscapeUriString(query) + $"?access_token={anilistToken}").ConfigureAwait(false); + var res = await http.GetStringAsync(link + $"?access_token={anilistToken}").ConfigureAwait(false); var smallObj = JArray.Parse(res)[0]; var aniData = await http.GetStringAsync("http://anilist.co/api/anime/" + smallObj["id"] + $"?access_token={anilistToken}").ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs index e70381b2..77e88289 100644 --- a/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs @@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Searches var rankimg = $"{model.Competitive.rank_img}"; var rank = $"{model.Competitive.rank}"; - var competitiveplay = $"{model.Games.Competitive.played}"; + //var competitiveplay = $"{model.Games.Competitive.played}"; if (string.IsNullOrWhiteSpace(rank)) { var embed = new EmbedBuilder() diff --git a/src/NadekoBot/Modules/Searches/Commands/PlaceCommands.cs b/src/NadekoBot/Modules/Searches/Commands/PlaceCommands.cs index af8a1fb3..bd22733b 100644 --- a/src/NadekoBot/Modules/Searches/Commands/PlaceCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/PlaceCommands.cs @@ -12,7 +12,8 @@ namespace NadekoBot.Modules.Searches [Group] public class PlaceCommands : ModuleBase { - private static string typesStr { get; } = $"`List of \"{NadekoBot.ModulePrefixes[typeof(Searches).Name]}place\" tags:`\n" + String.Join(", ", Enum.GetNames(typeof(PlaceType))); + private static string typesStr { get; } = + string.Format("`List of \"{0}place\" tags:`\n", NadekoBot.ModulePrefixes[typeof(Searches).Name]) + String.Join(", ", Enum.GetNames(typeof(PlaceType))); public enum PlaceType { diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index 3fc7a34b..86411634 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -103,19 +103,23 @@ namespace NadekoBot.Modules.Searches oldStatus.IsLive != newStatus.IsLive) { var server = NadekoBot.Client.GetGuild(fs.GuildId); - if (server == null) - return; - var channel = server.GetTextChannel(fs.ChannelId); + var channel = server?.GetTextChannel(fs.ChannelId); if (channel == null) return; try { var msg = await channel.EmbedAsync(fs.GetEmbed(newStatus)).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } } - catch { } + catch + { + // ignored + } })); FirstPass = false; diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index d612299c..b250e57f 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -499,12 +499,12 @@ namespace NadekoBot.Modules.Searches var data = JsonConvert.DeserializeObject(res); - var sense = data.Results.Where(x => x.Senses != null && x.Senses[0].Definition != null).FirstOrDefault()?.Senses[0]; + var sense = data.Results.FirstOrDefault(x => x.Senses?[0].Definition != null)?.Senses[0]; if (sense?.Definition == null) return; - string definition = sense.Definition.ToString(); + var definition = sense.Definition.ToString(); if (!(sense.Definition is string)) definition = ((JArray)JToken.Parse(sense.Definition.ToString())).First.ToString(); @@ -536,7 +536,7 @@ namespace NadekoBot.Modules.Searches } await Context.Channel.TriggerTypingAsync().ConfigureAwait(false); - string res = ""; + var res = ""; using (var http = new HttpClient()) { http.DefaultRequestHeaders.Clear(); @@ -548,7 +548,7 @@ namespace NadekoBot.Modules.Searches { var items = JObject.Parse(res); var item = items["defs"]["def"]; - var hashtag = item["hashtag"].ToString(); + //var hashtag = item["hashtag"].ToString(); var link = item["uri"].ToString(); var desc = item["text"].ToString(); await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() diff --git a/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs b/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs index 8131bf16..0eedba24 100644 --- a/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs @@ -32,7 +32,6 @@ namespace NadekoBot.Modules.Utility var voicechn = (await guild.GetVoiceChannelsAsync()).Count(); var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(guild.Id >> 22); - var sb = new StringBuilder(); var users = await guild.GetUsersAsync().ConfigureAwait(false); var features = string.Join("\n", guild.Features); if (string.IsNullOrWhiteSpace(features)) @@ -45,13 +44,13 @@ namespace NadekoBot.Modules.Utility .AddField(fb => fb.WithName("**Members**").WithValue(users.Count.ToString()).WithIsInline(true)) .AddField(fb => fb.WithName("**Text Channels**").WithValue(textchn.ToString()).WithIsInline(true)) .AddField(fb => fb.WithName("**Voice Channels**").WithValue(voicechn.ToString()).WithIsInline(true)) - .AddField(fb => fb.WithName("**Created At**").WithValue($"{createdAt.ToString("dd.MM.yyyy HH:mm")}").WithIsInline(true)) + .AddField(fb => fb.WithName("**Created At**").WithValue($"{createdAt:dd.MM.yyyy HH:mm}").WithIsInline(true)) .AddField(fb => fb.WithName("**Region**").WithValue(guild.VoiceRegionId.ToString()).WithIsInline(true)) .AddField(fb => fb.WithName("**Roles**").WithValue((guild.Roles.Count - 1).ToString()).WithIsInline(true)) .AddField(fb => fb.WithName("**Features**").WithValue(features).WithIsInline(true)) .WithImageUrl(guild.IconUrl) .WithColor(NadekoBot.OkColor); - if (guild.Emojis.Count() > 0) + if (guild.Emojis.Any()) { embed.AddField(fb => fb.WithName($"**Custom Emojis ({guild.Emojis.Count})**").WithValue(string.Join(" ", guild.Emojis.Shuffle().Take(25).Select(e => $"{e.Name} <:{e.Name}:{e.Id}>")))); } @@ -71,7 +70,7 @@ namespace NadekoBot.Modules.Utility .WithTitle(ch.Name) .WithDescription(ch.Topic?.SanitizeMentions()) .AddField(fb => fb.WithName("**ID**").WithValue(ch.Id.ToString()).WithIsInline(true)) - .AddField(fb => fb.WithName("**Created At**").WithValue($"{createdAt.ToString("dd.MM.yyyy HH:mm")}").WithIsInline(true)) + .AddField(fb => fb.WithName("**Created At**").WithValue($"{createdAt:dd.MM.yyyy HH:mm}").WithIsInline(true)) .AddField(fb => fb.WithName("**Users**").WithValue(usercount.ToString()).WithIsInline(true)) .WithColor(NadekoBot.OkColor); await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); @@ -81,7 +80,6 @@ namespace NadekoBot.Modules.Utility [RequireContext(ContextType.Guild)] public async Task UserInfo(IGuildUser usr = null) { - var channel = (ITextChannel)Context.Channel; var user = usr ?? Context.User as IGuildUser; if (user == null) @@ -95,7 +93,7 @@ namespace NadekoBot.Modules.Utility } embed.AddField(fb => fb.WithName("**ID**").WithValue(user.Id.ToString()).WithIsInline(true)) .AddField(fb => fb.WithName("**Joined Server**").WithValue($"{user.JoinedAt?.ToString("dd.MM.yyyy HH:mm") ?? "unavail."}").WithIsInline(true)) - .AddField(fb => fb.WithName("**Joined Discord**").WithValue($"{user.CreatedAt.ToString("dd.MM.yyyy HH:mm")}").WithIsInline(true)) + .AddField(fb => fb.WithName("**Joined Discord**").WithValue($"{user.CreatedAt:dd.MM.yyyy HH:mm}").WithIsInline(true)) .AddField(fb => fb.WithName("**Roles**").WithValue($"**({user.RoleIds.Count - 1})** - {string.Join("\n", user.GetRoles().Take(10).Where(r => r.Id != r.Guild.EveryoneRole.Id).Select(r => r.Name)).SanitizeMentions()}").WithIsInline(true)) .WithColor(NadekoBot.OkColor); diff --git a/src/NadekoBot/Modules/Utility/Commands/MessageRepeater.cs b/src/NadekoBot/Modules/Utility/Commands/MessageRepeater.cs index 1167cab7..e767bbcf 100644 --- a/src/NadekoBot/Modules/Utility/Commands/MessageRepeater.cs +++ b/src/NadekoBot/Modules/Utility/Commands/MessageRepeater.cs @@ -91,7 +91,7 @@ namespace NadekoBot.Modules.Utility public void Reset() { source.Cancel(); - var t = Task.Run(Run); + var _ = Task.Run(Run); } public void Stop() diff --git a/src/NadekoBot/Modules/Utility/Commands/Remind.cs b/src/NadekoBot/Modules/Utility/Commands/Remind.cs index 94521dd6..10d43352 100644 --- a/src/NadekoBot/Modules/Utility/Commands/Remind.cs +++ b/src/NadekoBot/Modules/Utility/Commands/Remind.cs @@ -45,15 +45,15 @@ namespace NadekoBot.Modules.Utility foreach (var r in reminders) { - try { var t = StartReminder(r); } catch (Exception ex) { _log.Warn(ex); } + Task.Run(() => StartReminder(r)); } } private static async Task StartReminder(Reminder r) { var now = DateTime.Now; - var twoMins = new TimeSpan(0, 2, 0); - TimeSpan time = r.When - now; + + var time = r.When - now; if (time.TotalMilliseconds > int.MaxValue) return; diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 1705d934..d627d956 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -468,7 +468,6 @@ namespace NadekoBot.Modules.Utility [OwnerOnly] public async Task SaveChat(int cnt) { - var sb = new StringBuilder(); var msgs = new List(cnt); await Context.Channel.GetMessagesAsync(cnt).ForEachAsync(dled => msgs.AddRange(dled)).ConfigureAwait(false); diff --git a/src/NadekoBot/Services/Database/NadekoContext.cs b/src/NadekoBot/Services/Database/NadekoContext.cs index 102c6703..4efb6150 100644 --- a/src/NadekoBot/Services/Database/NadekoContext.cs +++ b/src/NadekoBot/Services/Database/NadekoContext.cs @@ -132,7 +132,7 @@ namespace NadekoBot.Services.Database { #region QUOTES - var quoteEntity = modelBuilder.Entity(); + //var quoteEntity = modelBuilder.Entity(); #endregion @@ -166,7 +166,7 @@ namespace NadekoBot.Services.Database #endregion #region BotConfig - var botConfigEntity = modelBuilder.Entity(); + //var botConfigEntity = modelBuilder.Entity(); //botConfigEntity // .HasMany(c => c.ModulePrefixes) // .WithOne(mp => mp.BotConfig) diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index d8995c59..7c6d2201 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -96,18 +96,21 @@ namespace NadekoBot.Services.Impl content.Headers.Clear(); content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); - var res = await http.PostAsync("https://www.carbonitex.net/discord/data/botdata.php", content).ConfigureAwait(false); + await http.PostAsync("https://www.carbonitex.net/discord/data/botdata.php", content).ConfigureAwait(false); } }; } - catch { } + catch + { + // ignored + } }, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1)); } public void Initialize() { - var guilds = this.client.GetGuilds(); - _textChannels = guilds.Sum(g => g.Channels.Where(cx => cx is ITextChannel).Count()); + var guilds = this.client.GetGuilds().ToArray(); + _textChannels = guilds.Sum(g => g.Channels.Count(cx => cx is ITextChannel)); _voiceChannels = guilds.Sum(g => g.Channels.Count) - _textChannels; } diff --git a/src/NadekoBot/Services/NadekoRandom.cs b/src/NadekoBot/Services/NadekoRandom.cs index 0d42c065..f1af50c1 100644 --- a/src/NadekoBot/Services/NadekoRandom.cs +++ b/src/NadekoBot/Services/NadekoRandom.cs @@ -41,7 +41,6 @@ namespace NadekoBot.Services return minValue; var bytes = new byte[sizeof(int)]; rng.GetBytes(bytes); - var num = BitConverter.ToInt32(bytes, 0); var sign = Math.Sign(BitConverter.ToInt32(bytes, 0)); return (sign * BitConverter.ToInt32(bytes, 0)) % (maxValue - minValue) + minValue; }