moved .commands and .modules to help, -h takes a command name optionaly. Fixes.

This commit is contained in:
Master Kwoth 2016-02-25 02:44:39 +01:00
parent c13eebb69d
commit b08e37f89d
8 changed files with 56 additions and 32 deletions

View File

@ -36,7 +36,7 @@ namespace NadekoBot.Classes.Music {
public float Volume => MusicControls?.Volume ?? 1.0f; public float Volume => MusicControls?.Volume ?? 1.0f;
public bool RadioLink { get; private set; } public bool RadioLink { get; }
public MusicControls MusicControls; public MusicControls MusicControls;

View File

@ -27,7 +27,7 @@ namespace NadekoBot.Classes.Permissions {
} }
public bool CanRun(Command command, User user, Channel channel, out string error) { public bool CanRun(Command command, User user, Channel channel, out string error) {
error = null; error = String.Empty;
if (timeBlackList.ContainsKey(user)) if (timeBlackList.ContainsKey(user))
return false; return false;
@ -86,11 +86,11 @@ namespace NadekoBot.Classes.Permissions {
return true; return true;
} }
if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
Task.Run(() => channel.SendMessage(msg)); error = msg;
return false; return false;
} catch (Exception ex) { } catch (Exception ex) {
if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
Task.Run(() => channel.SendMessage(ex.Message)); error = ex.Message;
return false; return false;
} }
} }

View File

@ -81,15 +81,14 @@ namespace NadekoBot.Classes.Trivia {
private async Task End() { private async Task End() {
ShouldStopGame = true; ShouldStopGame = true;
await _channel.SendMessage("**Trivia game ended**"); await _channel.SendMessage("**Trivia game ended**\n"+GetLeaderboard());
await _channel.SendMessage(GetLeaderboard());
TriviaGame throwAwayValue; TriviaGame throwAwayValue;
Commands.Trivia.runningTrivias.TryRemove(_server, out throwAwayValue); Commands.Trivia.runningTrivias.TryRemove(_server, out throwAwayValue);
} }
public void StopGame() { public async void StopGame() {
if (!ShouldStopGame) if (!ShouldStopGame)
_channel.SendMessage(":exclamation: Trivia will stop after this question."); await _channel.SendMessage(":exclamation: Trivia will stop after this question.");
ShouldStopGame = true; ShouldStopGame = true;
} }

View File

@ -3,13 +3,14 @@ using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.IO; using System.IO;
using System.Linq;
namespace NadekoBot namespace NadekoBot
{ {
class HelpCommand : DiscordCommand class HelpCommand : DiscordCommand
{ {
public override Func<CommandEventArgs, Task> DoFunc() => async e => public override Func<CommandEventArgs, Task> DoFunc() => async e => {
{ #region OldHelp
/* /*
string helpstr = "**COMMANDS DO NOT WORK IN PERSONAL MESSAGES**\nOfficial repo: **github.com/Kwoth/NadekoBot/**"; string helpstr = "**COMMANDS DO NOT WORK IN PERSONAL MESSAGES**\nOfficial repo: **github.com/Kwoth/NadekoBot/**";
@ -33,7 +34,23 @@ namespace NadekoBot
await Task.Delay(200); await Task.Delay(200);
} }
*/ */
#endregion OldHelp
if (string.IsNullOrWhiteSpace(e.GetArg("command"))) {
await e.User.Send("**LIST OF COMMANDS CAN BE FOUND ON THIS LINK**\n\n <https://gist.github.com/Kwoth/1ab3a38424f208802b74>"); await e.User.Send("**LIST OF COMMANDS CAN BE FOUND ON THIS LINK**\n\n <https://gist.github.com/Kwoth/1ab3a38424f208802b74>");
return;
}
else {
await Task.Run(async () => {
var comToFind = e.GetArg("command");
var com = NadekoBot.client.GetService<CommandService>().AllCommands
.Where(c => c.Text.ToLower().Equals(comToFind))
.FirstOrDefault();
if (com != null)
await e.Channel.SendMessage($"`Help for '{com.Text}:'` **{com.Description}**");
});
}
}; };
public Action<CommandEventArgs> DoGitFunc() => e => { public Action<CommandEventArgs> DoGitFunc() => e => {
@ -64,7 +81,8 @@ namespace NadekoBot
{ {
cgb.CreateCommand("-h") cgb.CreateCommand("-h")
.Alias(new string[] { "-help", NadekoBot.botMention + " help", NadekoBot.botMention + " h", "~h" }) .Alias(new string[] { "-help", NadekoBot.botMention + " help", NadekoBot.botMention + " h", "~h" })
.Description("Help command") .Description("Either shows a help for a single command, or PMs you help link if no arguments are specified.\n**Usage**: '-h !m q' or just '-h' ")
.Parameter("command",ParameterType.Unparsed)
.Do(DoFunc()); .Do(DoFunc());
cgb.CreateCommand("-hgit") cgb.CreateCommand("-hgit")
.Description("Help command stylized for github readme") .Description("Help command stylized for github readme")

View File

@ -160,25 +160,6 @@ namespace NadekoBot.Modules {
await e.Channel.SendMessage("`List of roles:` \n• " + string.Join("\n• ", e.Server.Roles).Replace("@everyone", "මeveryone")); await e.Channel.SendMessage("`List of roles:` \n• " + string.Join("\n• ", e.Server.Roles).Replace("@everyone", "මeveryone"));
}); });
cgb.CreateCommand(".modules")
.Description("List all bot modules.")
.Do(async e => {
await e.Channel.SendMessage("`List of modules:` \n• " + string.Join("\n• ", NadekoBot.client.GetService<ModuleService>().Modules.Select(m => m.Name)));
});
cgb.CreateCommand(".commands")
.Description("List all of the bot's commands from a certain module.")
.Parameter("module", ParameterType.Unparsed)
.Do(async e => {
var commands = NadekoBot.client.GetService<CommandService>().AllCommands
.Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower());
if (commands == null || commands.Count() == 0) {
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)));
});
cgb.CreateCommand(".b").Alias(".ban") cgb.CreateCommand(".b").Alias(".ban")
.Parameter("everything", ParameterType.Unparsed) .Parameter("everything", ParameterType.Unparsed)
.Description("Bans a mentioned user.") .Description("Bans a mentioned user.")

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Modules; using Discord.Modules;
using Discord.Commands;
namespace NadekoBot.Modules { namespace NadekoBot.Modules {
class Help : DiscordModule { class Help : DiscordModule {
@ -16,6 +17,27 @@ namespace NadekoBot.Modules {
manager.CreateCommands("", cgb => { manager.CreateCommands("", cgb => {
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
commands.ForEach(com => com.Init(cgb)); commands.ForEach(com => com.Init(cgb));
cgb.CreateCommand(".modules")
.Alias("-modules")
.Description("List all bot modules.")
.Do(async e => {
await e.Channel.SendMessage("`List of modules:` \n• " + string.Join("\n• ", NadekoBot.client.GetService<ModuleService>().Modules.Select(m => m.Name)));
});
cgb.CreateCommand(".commands")
.Alias("-commands")
.Description("List all of the bot's commands from a certain module.")
.Parameter("module", ParameterType.Unparsed)
.Do(async e => {
var commands = NadekoBot.client.GetService<CommandService>().AllCommands
.Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower());
if (commands == null || commands.Count() == 0) {
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)));
});
}); });
} }
} }

View File

@ -74,6 +74,11 @@ namespace NadekoBot {
AllowMentionPrefix = false, AllowMentionPrefix = false,
CustomPrefixHandler = m => 0, CustomPrefixHandler = m => 0,
HelpMode = HelpMode.Disabled, HelpMode = HelpMode.Disabled,
ErrorHandler = async (s, e) => {
if (e.ErrorType != CommandErrorType.BadPermissions)
return;
await e.Channel.SendMessage(e.Exception.Message);
}
}); });
//reply to personal messages and forward if enabled. //reply to personal messages and forward if enabled.

View File

@ -180,7 +180,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
<None Include="NadekoBot_TemporaryKey.pfx" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>