Moved Help to its own file, created administration module which now contains help. I will add more commands to it in the future.
This commit is contained in:
parent
b393a5932f
commit
654099afa4
@ -32,8 +32,8 @@ namespace NadekoBot
|
||||
public abstract Func<CommandEventArgs,Task> DoFunc();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the CommandBuilder with values
|
||||
/// Initializes the CommandBuilder with values using CommandGroupBuilder
|
||||
/// </summary>
|
||||
public abstract void Init(CommandGroupBuilder cgb);
|
||||
public abstract void Init(CommandGroupBuilder cgb);
|
||||
}
|
||||
}
|
||||
|
46
NadekoBot/Commands/HelpCommand.cs
Normal file
46
NadekoBot/Commands/HelpCommand.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
|
||||
namespace NadekoBot
|
||||
{
|
||||
class HelpCommand : DiscordCommand
|
||||
{
|
||||
public override Func<CommandEventArgs, Task> 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;
|
||||
}
|
||||
}
|
||||
}
|
20
NadekoBot/Modules/Administration.cs
Normal file
20
NadekoBot/Modules/Administration.cs
Normal file
@ -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));
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -91,6 +91,8 @@
|
||||
<Compile Include="Commands\DiscordCommand.cs" />
|
||||
<Compile Include="Commands\DrawCommand.cs" />
|
||||
<Compile Include="Commands\FlipCoinCommand.cs" />
|
||||
<Compile Include="Commands\HelpCommand.cs" />
|
||||
<Compile Include="Modules\Administration.cs" />
|
||||
<Compile Include="Modules\Conversations.cs" />
|
||||
<Compile Include="Modules\DiscordModule.cs" />
|
||||
<Compile Include="Modules\Gambling.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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user