diff --git a/NadekoBot/Commands/DiscordCommand.cs b/NadekoBot/Commands/DiscordCommand.cs index b32b79ba..fccda6c5 100644 --- a/NadekoBot/Commands/DiscordCommand.cs +++ b/NadekoBot/Commands/DiscordCommand.cs @@ -32,8 +32,8 @@ namespace NadekoBot public abstract Func DoFunc(); /// - /// Initializes the CommandBuilder with values + /// Initializes the CommandBuilder with values using CommandGroupBuilder /// - public abstract void Init(CommandGroupBuilder cgb); + public abstract void Init(CommandGroupBuilder cgb); } } diff --git a/NadekoBot/Commands/HelpCommand.cs b/NadekoBot/Commands/HelpCommand.cs new file mode 100644 index 00000000..e9c0fa92 --- /dev/null +++ b/NadekoBot/Commands/HelpCommand.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using Discord.Commands; + +namespace NadekoBot +{ + class HelpCommand : DiscordCommand + { + public override Func DoFunc() + { + return async e => + { + string helpstr = ""; + foreach (var com in client.Commands().AllCommands) + { + helpstr += "&###**#" + com.Category + "#**\n"; + helpstr += PrintCommandHelp(com); + } + while (helpstr.Length > 2000) + { + var curstr = helpstr.Substring(0, 2000); + await client.SendPrivateMessage(e.User, curstr.Substring(0, curstr.LastIndexOf("&"))); + helpstr = curstr.Substring(curstr.LastIndexOf("&")) + helpstr.Substring(2000); + } + await client.SendPrivateMessage(e.User, helpstr); + }; + } + + public override void Init(CommandGroupBuilder cgb) + { + cgb.CreateCommand("-h") + .Alias(new string[] { "-help", NadekoBot.botMention + " help", NadekoBot.botMention + " h" }) + .Description("Help command") + .Do(DoFunc()); + } + + private string PrintCommandHelp(Command com) + { + var str = "`" + com.Text + "`\n"; + foreach (var a in com.Aliases) + str += "`" + a + "`\n"; + str += "Description: " + com.Description + "\n"; + return str; + } + } +} diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs new file mode 100644 index 00000000..fb9e3155 --- /dev/null +++ b/NadekoBot/Modules/Administration.cs @@ -0,0 +1,20 @@ +using Discord.Modules; + +namespace NadekoBot.Modules +{ + class Administration : DiscordModule + { + public Administration() : base() { + commands.Add(new HelpCommand()); + } + + public override void Install(ModuleManager manager) + { + manager.CreateCommands("", cgb => + { + commands.ForEach(com => com.Init(cgb)); + }); + + } + } +} diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index ef7c106a..f15e8d95 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -58,30 +58,12 @@ namespace NadekoBot //add command service var commands = client.AddService(commandService); - - //help command - commands.CreateCommand("-h") - .Alias(new string[]{"-help",NadekoBot.botMention+" help", NadekoBot.botMention+" h"}) - .Description("Help command") - .Do(async e => - { - string helpstr = ""; - foreach (var com in client.Commands().AllCommands) { - helpstr += "&###**#" + com.Category + "#**\n"; - helpstr += PrintCommandHelp(com); - } - while (helpstr.Length > 2000) { - var curstr = helpstr.Substring(0, 2000); - await client.SendPrivateMessage(e.User, curstr.Substring(0,curstr.LastIndexOf("&"))); - helpstr = curstr.Substring(curstr.LastIndexOf("&")) + helpstr.Substring(2000); - } - await client.SendPrivateMessage(e.User, helpstr); - }); //create module service var modules = client.AddService(new ModuleService()); //install modules + modules.Install(new Administration(), "Administration", FilterType.Unrestricted); modules.Install(new Conversations(), "Conversation", FilterType.Unrestricted); modules.Install(new Gambling(), "Gambling", FilterType.Unrestricted); modules.Install(new Games(), "Games", FilterType.Unrestricted); @@ -113,28 +95,6 @@ namespace NadekoBot client.SendMessage(e.Channel, Mention.User(e.User) + " Command failed. See help (-h)."); } - private static string PrintCommandHelp(Command com) - { - var str = "`" + com.Text + "`\n"; - foreach (var a in com.Aliases) - str += "`" + a + "`\n"; - str += "Description: " + com.Description + "\n"; - return str; - } - /* removed - private static void Crawl() - { - Timer t = new Timer(); - t.Interval = 5000; // start crawling after 5 seconds - t.Elapsed += (s, e) => { - var wc = new WebCrawler.WebCrawler(); - WebCrawler.WebCrawler.OnFoundInvite += inv => { TryJoin(inv); }; - t.Stop(); - }; - t.Start(); - } - */ - private static async void TryJoin(string code) { try diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index f3f22964..a17ef546 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -91,6 +91,8 @@ + + diff --git a/NadekoBot/StatsCollector.cs b/NadekoBot/StatsCollector.cs index c953c805..e5ff403c 100644 --- a/NadekoBot/StatsCollector.cs +++ b/NadekoBot/StatsCollector.cs @@ -27,18 +27,6 @@ namespace NadekoBot _service.RanCommand += StatsCollector_RanCommand; NadekoBot.client.MessageReceived += Client_MessageReceived; - /* - Timer t = new Timer(); - - t.Interval = 5000; - - t.Elapsed += (s,e) => - { - FillConsole(); - }; - - t.Start(); - */ StartCollecting(); }