diff --git a/NadekoBot/Classes/JSONModels/Config.cs b/NadekoBot/Classes/JSONModels/Config.cs index aa427aac..2b643ebf 100644 --- a/NadekoBot/Classes/JSONModels/Config.cs +++ b/NadekoBot/Classes/JSONModels/Config.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace NadekoBot.Classes.JSONModels { - internal class Config { + internal class LocalizedStrings { + public string[] _8BallAnswers { get; set; } } } diff --git a/NadekoBot/Classes/NadekoStats.cs b/NadekoBot/Classes/NadekoStats.cs index d2acb85e..19da43d8 100644 --- a/NadekoBot/Classes/NadekoStats.cs +++ b/NadekoBot/Classes/NadekoStats.cs @@ -26,7 +26,6 @@ namespace NadekoBot { private NadekoStats() { var commandService = NadekoBot.Client.GetService(); - statsStopwatch = new Stopwatch(); statsStopwatch.Start(); commandService.CommandExecuted += StatsCollector_RanCommand; @@ -44,16 +43,14 @@ namespace NadekoBot { ServerCount++; TextChannelsCount += e.Server.TextChannels.Count(); VoiceChannelsCount += e.Server.VoiceChannels.Count(); - } - catch { } + } catch { } }; NadekoBot.Client.LeftServer += (s, e) => { try { ServerCount--; TextChannelsCount -= e.Server.TextChannels.Count(); VoiceChannelsCount -= e.Server.VoiceChannels.Count(); - } - catch { } + } catch { } }; NadekoBot.Client.ChannelCreated += (s, e) => { try { @@ -63,8 +60,7 @@ namespace NadekoBot { TextChannelsCount++; else if (e.Channel.Type == ChannelType.Voice) VoiceChannelsCount++; - } - catch { } + } catch { } }; NadekoBot.Client.ChannelDestroyed += (s, e) => { try { @@ -74,8 +70,7 @@ namespace NadekoBot { VoiceChannelsCount++; else if (e.Channel.Type == ChannelType.Voice) VoiceChannelsCount--; - } - catch { } + } catch { } }; } @@ -129,8 +124,7 @@ namespace NadekoBot { ConnectedServers = connectedServers, DateAdded = DateTime.Now }); - } - catch { + } catch { Console.WriteLine("DB Exception in stats collecting."); break; } @@ -142,17 +136,16 @@ namespace NadekoBot { try { commandsRan++; Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Command { - ServerId = (long) e.Server.Id, + ServerId = (long)e.Server.Id, ServerName = e.Server.Name, - ChannelId = (long) e.Channel.Id, + ChannelId = (long)e.Channel.Id, ChannelName = e.Channel.Name, - UserId = (long) e.User.Id, + UserId = (long)e.User.Id, UserName = e.User.Name, CommandName = e.Command.Text, DateAdded = DateTime.Now }); - } - catch { + } catch { Console.WriteLine("Error in ran command DB write."); } }); diff --git a/NadekoBot/Classes/Permissions/PermissionsHandler.cs b/NadekoBot/Classes/Permissions/PermissionsHandler.cs index 08b0af16..d360c378 100644 --- a/NadekoBot/Classes/Permissions/PermissionsHandler.cs +++ b/NadekoBot/Classes/Permissions/PermissionsHandler.cs @@ -4,7 +4,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Discord.Commands; diff --git a/NadekoBot/Classes/SearchHelper.cs b/NadekoBot/Classes/SearchHelper.cs index b3b7baec..c7bf18dc 100644 --- a/NadekoBot/Classes/SearchHelper.cs +++ b/NadekoBot/Classes/SearchHelper.cs @@ -7,7 +7,6 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; using System.Security.Authentication; using System.Text.RegularExpressions; using System.Threading.Tasks; diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 10d8f5ef..4b185689 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -7,13 +7,10 @@ using NadekoBot.Extensions; using System.Threading.Tasks; using NadekoBot.Commands; using System.IO; -using System.Collections.Concurrent; using Newtonsoft.Json.Linq; -using System.Collections.Generic; using NadekoBot.Classes; using NadekoBot.Classes.Permissions; using NadekoBot.Classes._DataModels; -using Timer = System.Timers.Timer; namespace NadekoBot.Modules { internal class Administration : DiscordModule { @@ -178,20 +175,10 @@ namespace NadekoBot.Modules { await usr.Server.Ban(usr); await e.Channel.SendMessage("Banned user " + usr.Name + " Id: " + usr.Id); } - } catch (Exception ex) { } - }); - - cgb.CreateCommand(".ub").Alias(".unban") - .Parameter("everything", ParameterType.Unparsed) - .Description("Unbans a mentioned user.") - .Do(async e => { - try { - if (e.User.ServerPermissions.BanMembers && e.Message.MentionedUsers.Any()) { - var usr = e.Message.MentionedUsers.First(); - await usr.Server.Unban(usr); - await e.Channel.SendMessage("Unbanned user " + usr.Name + " Id: " + usr.Id); - } - } catch { } + } + catch (Exception ex) { + + } }); cgb.CreateCommand(".k").Alias(".kick") @@ -389,15 +376,6 @@ namespace NadekoBot.Modules { var heap = Task.Run(() => NadekoStats.Instance.Heap()); await e.Channel.SendMessage($"`Heap Size:` {heap}"); }); - - /* - cgb.CreateCommand(".leaveall") - .Description("Nadeko leaves all servers **OWNER ONLY**") - .Do(e => { - if (NadekoBot.IsOwner(e.User.Id)) - NadekoBot.client.Servers.ForEach(async s => { if (s.Name == e.Server.Name) return; await s.Leave(); }); - }); - */ cgb.CreateCommand(".prune") .Parameter("num", ParameterType.Required) .Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 5") diff --git a/NadekoBot/Modules/Conversations.cs b/NadekoBot/Modules/Conversations.cs index 4267a3be..4ef2f7d2 100644 --- a/NadekoBot/Modules/Conversations.cs +++ b/NadekoBot/Modules/Conversations.cs @@ -4,7 +4,6 @@ using Discord.Modules; using System; using System.Collections.Generic; using System.Linq; -using System.Timers; using System.Threading.Tasks; using System.Diagnostics; using System.Drawing; diff --git a/NadekoBot/Modules/Help.cs b/NadekoBot/Modules/Help.cs index f432dad9..063c363e 100644 --- a/NadekoBot/Modules/Help.cs +++ b/NadekoBot/Modules/Help.cs @@ -6,7 +6,7 @@ using NadekoBot.Commands; namespace NadekoBot.Modules { internal class Help : DiscordModule { - public Help() { + public Help() { commands.Add(new HelpCommand()); } @@ -27,13 +27,14 @@ namespace NadekoBot.Modules { .Description("List all of the bot's commands from a certain module.") .Parameter("module", ParameterType.Unparsed) .Do(async e => { - var commands = NadekoBot.Client.GetService().AllCommands + var cmds = NadekoBot.Client.GetService().AllCommands .Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower()); - if (commands == null || commands.Count() == 0) { + var cmdsArray = cmds as Command[] ?? cmds.ToArray(); + if (!cmdsArray.Any()) { await e.Channel.SendMessage("That module does not exist."); return; } - await e.Channel.SendMessage("`List of commands:` \n• " + string.Join("\n• ", commands.Select(c => c.Text))); + await e.Channel.SendMessage("`List of commands:` \n• " + string.Join("\n• ", cmdsArray.Select(c => c.Text))); }); }); } diff --git a/NadekoBot/Modules/Trello.cs b/NadekoBot/Modules/Trello.cs index b22f3fbe..ba154f8c 100644 --- a/NadekoBot/Modules/Trello.cs +++ b/NadekoBot/Modules/Trello.cs @@ -6,9 +6,11 @@ using Manatee.Trello.ManateeJson; using Manatee.Trello; using System.Timers; using NadekoBot.Extensions; +using Action = Manatee.Trello.Action; namespace NadekoBot.Modules { internal class Trello : DiscordModule { + private readonly Timer t = new Timer() { Interval = 2000 }; public override void Install(ModuleManager manager) { var client = manager.Client; @@ -24,8 +26,6 @@ namespace NadekoBot.Modules { Discord.Channel bound = null; Board board = null; - Timer t = new Timer(); - t.Interval = 2000; List last5ActionIDs = null; t.Elapsed += async (s, e) => { try { @@ -33,31 +33,26 @@ namespace NadekoBot.Modules { return; //do nothing if there is no bound board board.Refresh(); - IEnumerable cur5Actions; - if (board.Actions.Count() < 5) - cur5Actions = board.Actions.Take(board.Actions.Count()); - else - cur5Actions = board.Actions.Take(5); + var cur5Actions = board.Actions.Take(board.Actions.Count() < 5 ? board.Actions.Count() : 5); + var cur5ActionsArray = cur5Actions as Action[] ?? cur5Actions.ToArray(); if (last5ActionIDs == null) { - last5ActionIDs = new List(); - foreach (var a in cur5Actions) - last5ActionIDs.Add(a.Id); + last5ActionIDs = cur5ActionsArray.Select(a => a.Id).ToList(); return; } - foreach (var a in cur5Actions.Where(ca => !last5ActionIDs.Contains(ca.Id))) { + + foreach (var a in cur5ActionsArray.Where(ca => !last5ActionIDs.Contains(ca.Id))) { await bound.Send("**--TRELLO NOTIFICATION--**\n" + a.ToString()); } last5ActionIDs.Clear(); - foreach (var a in cur5Actions) - last5ActionIDs.Add(a.Id); + last5ActionIDs.AddRange(cur5ActionsArray.Select(a => a.Id)); } catch (Exception ex) { Console.WriteLine("Timer failed " + ex.ToString()); } }; - manager.CreateCommands("", cgb => { - + manager.CreateCommands("trello ", cgb => { + cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); cgb.CreateCommand("join") @@ -124,7 +119,7 @@ namespace NadekoBot.Modules { if (success && num <= board.Lists.Count() && num > 0) list = board.Lists[num - 1]; else - list = board.Lists.Where(l => l.Name == e.GetArg("list_name")).FirstOrDefault(); + list = board.Lists.FirstOrDefault(l => l.Name == e.GetArg("list_name")); if (list != null) diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index c0af279e..036152ec 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -6,11 +6,9 @@ using Discord.Commands; using NadekoBot.Modules; using Discord.Modules; using Discord.Audio; -using System.Timers; using System.Linq; using System.Text; using System.Threading.Tasks; -using NadekoBot.Classes; using NadekoBot.Classes.JSONModels; using NadekoBot.Commands;