From fb5a52de3a2f5e2d48a0e1b580bda3faa586fcd9 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 14 Apr 2016 22:09:19 +0200 Subject: [PATCH] Better support for bot accounts --- NadekoBot/Commands/HelpCommand.cs | 11 ++++++----- NadekoBot/Modules/Help.cs | 28 ++++++++++++++++++---------- NadekoBot/NadekoBot.cs | 12 ++++++++---- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/NadekoBot/Commands/HelpCommand.cs b/NadekoBot/Commands/HelpCommand.cs index 9e142135..48a05f13 100644 --- a/NadekoBot/Commands/HelpCommand.cs +++ b/NadekoBot/Commands/HelpCommand.cs @@ -50,11 +50,12 @@ namespace NadekoBot.Commands var com = NadekoBot.Client.GetService().AllCommands .FirstOrDefault(c => c.Text.ToLower().Equals(comToFind)); if (com != null) - await e.Channel.SendMessage($"`Help for '{com.Text}:'` **{com.Description}**"); + await e.Channel.SendMessage($"`Help for '{com.Text}':` **{com.Description}**"); }); }; - public static string HelpString => $"You can use `{NadekoBot.Config.CommandPrefixes.Help}modules` command to see a list of all modules.\n" + + public static string HelpString => NadekoBot.IsBot ? $"To invite {NadekoBot.Client.CurrentUser.Name} to your server, go here: <>\n" : "" + + $"You can use `{NadekoBot.Config.CommandPrefixes.Help}modules` command to see a list of all modules.\n" + $"You can use `{NadekoBot.Config.CommandPrefixes.Help}commands ModuleName`" + $" (for example `{NadekoBot.Config.CommandPrefixes.Help}commands Administration`) to see a list of all of the commands in that module.\n" + $"For a specific command help, use `{NadekoBot.Config.CommandPrefixes.Help}h \"Command name\"` (for example `-h \"!m q\"`)\n" + @@ -121,11 +122,11 @@ Version: `{NadekoStats.Instance.BotVersion}`"; .Do(async e => { await e.Channel.SendMessage( -@"I've created a **paypal** email for nadeko, so if you wish to support the project, you can send your donations to `nadekodiscordbot@gmail.com` +$@"I've created a **paypal** email for nadeko, so if you wish to support the project, you can send your donations to `nadekodiscordbot@gmail.com` Don't forget to leave your discord name or id in the message, so that I can reward people who help out. -You can join nadekobot server by simply private messaging NadekoBot, and you will get an invite. +You can join nadekobot server by typing {Module.Prefix}h and you will get an invite in a private message. -*If you want to support in some other way or on a different platform, please message me there*" +*If you want to support in some other way or on a different platform, please message me*" ); }); } diff --git a/NadekoBot/Modules/Help.cs b/NadekoBot/Modules/Help.cs index 8cc383df..78bea65f 100644 --- a/NadekoBot/Modules/Help.cs +++ b/NadekoBot/Modules/Help.cs @@ -1,27 +1,33 @@ -using System.Linq; +using Discord.Commands; using Discord.Modules; -using Discord.Commands; using NadekoBot.Commands; using NadekoBot.Extensions; +using System.Linq; -namespace NadekoBot.Modules { - internal class Help : DiscordModule { +namespace NadekoBot.Modules +{ + internal class Help : DiscordModule + { - public Help() { + public Help() + { commands.Add(new HelpCommand(this)); } public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Help; - public override void Install(ModuleManager manager) { - manager.CreateCommands("", cgb => { + public override void Install(ModuleManager manager) + { + manager.CreateCommands("", cgb => + { cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); commands.ForEach(com => com.Init(cgb)); cgb.CreateCommand(Prefix + "modules") .Alias(".modules") .Description("List all bot modules.") - .Do(async e => { + .Do(async e => + { await e.Channel.SendMessage("`List of modules:` \n• " + string.Join("\n• ", NadekoBot.Client.GetService().Modules.Select(m => m.Name))); }); @@ -29,11 +35,13 @@ namespace NadekoBot.Modules { .Alias(".commands") .Description("List all of the bot's commands from a certain module.") .Parameter("module", ParameterType.Unparsed) - .Do(async e => { + .Do(async e => + { var cmds = NadekoBot.Client.GetService().AllCommands .Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower()); var cmdsArray = cmds as Command[] ?? cmds.ToArray(); - if (!cmdsArray.Any()) { + if (!cmdsArray.Any()) + { await e.Channel.SendMessage("That module does not exist."); return; } diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 506fcd0d..a2f0cddf 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -28,6 +28,7 @@ namespace NadekoBot public static LocalizedStrings Locale { get; set; } = new LocalizedStrings(); public static string BotMention { get; set; } = ""; public static bool Ready { get; set; } = false; + public static bool IsBot { get; set; } = false; private static Channel OwnerPrivateChannel { get; set; } @@ -90,7 +91,7 @@ namespace NadekoBot } //if password is not entered, prompt for password - if (string.IsNullOrWhiteSpace(Creds.Password) && !string.IsNullOrWhiteSpace(Creds.Token)) + if (string.IsNullOrWhiteSpace(Creds.Password) && string.IsNullOrWhiteSpace(Creds.Token)) { Console.WriteLine("Password blank. Please enter your password:\n"); Creds.Password = Console.ReadLine(); @@ -185,7 +186,11 @@ namespace NadekoBot if (string.IsNullOrWhiteSpace(Creds.Token)) await Client.Connect(Creds.Username, Creds.Password); else + { await Client.Connect(Creds.Token); + IsBot = true; + } + } catch (Exception ex) { @@ -197,6 +202,7 @@ namespace NadekoBot Console.ReadKey(); return; } + Console.WriteLine("-----------------"); Console.WriteLine(await NadekoStats.Instance.GetStats()); Console.WriteLine("-----------------"); @@ -218,8 +224,6 @@ namespace NadekoBot if (string.IsNullOrWhiteSpace(request.Content)) e.Cancel = true; }; - - //await Task.Delay(90000); Classes.Permissions.PermissionsHandler.Initialize(); NadekoBot.Ready = true; }); @@ -245,7 +249,7 @@ namespace NadekoBot if (ConfigHandler.IsBlackListed(e)) return; - if (!NadekoBot.Config.DontJoinServers) + if (!NadekoBot.Config.DontJoinServers && !IsBot) { try {