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 bool RadioLink { get; private set; }
public bool RadioLink { get; }
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) {
error = null;
error = String.Empty;
if (timeBlackList.ContainsKey(user))
return false;
@ -86,11 +86,11 @@ namespace NadekoBot.Classes.Permissions {
return true;
}
if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
Task.Run(() => channel.SendMessage(msg));
error = msg;
return false;
} catch (Exception ex) {
if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
Task.Run(() => channel.SendMessage(ex.Message));
error = ex.Message;
return false;
}
}

View File

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

View File

@ -3,13 +3,14 @@ using System.Threading.Tasks;
using Discord.Commands;
using NadekoBot.Extensions;
using System.IO;
using System.Linq;
namespace NadekoBot
{
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/**";
@ -33,7 +34,23 @@ namespace NadekoBot
await Task.Delay(200);
}
*/
await e.User.Send("**LIST OF COMMANDS CAN BE FOUND ON THIS LINK**\n\n <https://gist.github.com/Kwoth/1ab3a38424f208802b74>");
#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>");
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 => {
@ -64,7 +81,8 @@ namespace NadekoBot
{
cgb.CreateCommand("-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());
cgb.CreateCommand("-hgit")
.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"));
});
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")
.Parameter("everything", ParameterType.Unparsed)
.Description("Bans a mentioned user.")

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord.Modules;
using Discord.Commands;
namespace NadekoBot.Modules {
class Help : DiscordModule {
@ -16,6 +17,27 @@ namespace NadekoBot.Modules {
manager.CreateCommands("", cgb => {
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
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,
CustomPrefixHandler = m => 0,
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.

View File

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