diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index 4ae9ecfc..178dbb53 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -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; diff --git a/NadekoBot/Classes/Permissions/PermissionChecker.cs b/NadekoBot/Classes/Permissions/PermissionChecker.cs index 19b32ee8..272d0e40 100644 --- a/NadekoBot/Classes/Permissions/PermissionChecker.cs +++ b/NadekoBot/Classes/Permissions/PermissionChecker.cs @@ -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; } } diff --git a/NadekoBot/Classes/Trivia/TriviaGame.cs b/NadekoBot/Classes/Trivia/TriviaGame.cs index a16e28e3..04d024ab 100644 --- a/NadekoBot/Classes/Trivia/TriviaGame.cs +++ b/NadekoBot/Classes/Trivia/TriviaGame.cs @@ -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; } diff --git a/NadekoBot/Commands/HelpCommand.cs b/NadekoBot/Commands/HelpCommand.cs index a5f2ece3..812fbda2 100644 --- a/NadekoBot/Commands/HelpCommand.cs +++ b/NadekoBot/Commands/HelpCommand.cs @@ -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 DoFunc() => async e => - { + public override Func 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 "); + #endregion OldHelp + + if (string.IsNullOrWhiteSpace(e.GetArg("command"))) { + await e.User.Send("**LIST OF COMMANDS CAN BE FOUND ON THIS LINK**\n\n "); + return; + } + else { + await Task.Run(async () => { + var comToFind = e.GetArg("command"); + + var com = NadekoBot.client.GetService().AllCommands + .Where(c => c.Text.ToLower().Equals(comToFind)) + .FirstOrDefault(); + if (com != null) + await e.Channel.SendMessage($"`Help for '{com.Text}:'` **{com.Description}**"); + }); + } }; public Action 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") diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index ca662364..c9d2a323 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -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().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().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.") diff --git a/NadekoBot/Modules/Help.cs b/NadekoBot/Modules/Help.cs index f9c2f7b7..12d4c34e 100644 --- a/NadekoBot/Modules/Help.cs +++ b/NadekoBot/Modules/Help.cs @@ -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().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().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))); + }); }); } } diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index b89510aa..88ee5e8f 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -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. diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 0f051d41..91bd6d86 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -180,7 +180,6 @@ -