From 5b379f7ffaf74f1fc669564a2ef626244d0c0925 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 15 Jun 2016 19:03:00 +0200 Subject: [PATCH] Client id added to creds, no more username/pass, cleanup, HelpString added to creds (-h command). No more support for normal user accounts. --- .../Administration/AdministrationModule.cs | 4 +- .../Modules/Conversations/Conversations.cs | 35 +--------------- .../Modules/Help/Commands/HelpCommand.cs | 17 ++++---- NadekoBot/NadekoBot.cs | 40 +++---------------- NadekoBot/_Models/JSONModels/Configuration.cs | 11 +++++ NadekoBot/_Models/JSONModels/_JSONModels.cs | 22 +++++----- NadekoBot/bin/Debug/credentials_example.json | 3 +- NadekoBot/bin/Debug/data/config_example.json | 3 +- 8 files changed, 43 insertions(+), 92 deletions(-) diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index 922bdc00..2b53821c 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -728,7 +728,7 @@ namespace NadekoBot.Modules.Administration { if (e.GetArg("new_name") == null) return; - await client.CurrentUser.Edit(NadekoBot.Creds.Password, e.GetArg("new_name")).ConfigureAwait(false); + await client.CurrentUser.Edit("", e.GetArg("new_name")).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "newavatar") @@ -744,7 +744,7 @@ namespace NadekoBot.Modules.Administration var avatarAddress = e.GetArg("img"); var imageStream = await SearchHelper.GetResponseStreamAsync(avatarAddress).ConfigureAwait(false); var image = System.Drawing.Image.FromStream(imageStream); - await client.CurrentUser.Edit(NadekoBot.Creds.Password, avatar: image.ToStream()).ConfigureAwait(false); + await client.CurrentUser.Edit("", avatar: image.ToStream()).ConfigureAwait(false); // Send confirm. await e.Channel.SendMessage("New avatar set.").ConfigureAwait(false); diff --git a/NadekoBot/Modules/Conversations/Conversations.cs b/NadekoBot/Modules/Conversations/Conversations.cs index 7ce103f5..52d1b29a 100644 --- a/NadekoBot/Modules/Conversations/Conversations.cs +++ b/NadekoBot/Modules/Conversations/Conversations.cs @@ -4,18 +4,13 @@ using Discord.Modules; using NadekoBot.Classes.Conversations.Commands; using NadekoBot.DataModels; using NadekoBot.Extensions; -using NadekoBot.Classes; -using System.Drawing.Drawing2D; +using NadekoBot.Modules.Conversations.Commands; using NadekoBot.Modules.Permissions.Classes; -using NadekoBot.Properties; using System; using System.Diagnostics; -using System.Drawing; -using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Threading.Tasks; -using NadekoBot.Modules.Conversations.Commands; namespace NadekoBot.Modules.Conversations { @@ -188,32 +183,6 @@ namespace NadekoBot.Modules.Conversations await e.Channel.SendMessage(str).ConfigureAwait(false); }); - - if (!NadekoBot.Config.DontJoinServers) - { - cgb.CreateCommand("j") - .Description("Joins a server using a code.") - .Parameter("id", ParameterType.Required) - .Do(async e => - { - var invite = await client.GetInvite(e.Args[0]).ConfigureAwait(false); - if (invite != null) - { - try - { - await invite.Accept().ConfigureAwait(false); - } - catch - { - await e.Channel.SendMessage("Failed to accept invite.").ConfigureAwait(false); - } - await e.Channel.SendMessage("I got in!").ConfigureAwait(false); - return; - } - await e.Channel.SendMessage("Invalid code.").ConfigureAwait(false); - }); - } - cgb.CreateCommand("slm") .Description("Shows the message where you were last mentioned in this channel (checks last 10k messages)") .Do(async e => @@ -306,7 +275,7 @@ namespace NadekoBot.Modules.Conversations } - + private static Func SayYes() => async e => await e.Channel.SendMessage("Yes. :)").ConfigureAwait(false); } diff --git a/NadekoBot/Modules/Help/Commands/HelpCommand.cs b/NadekoBot/Modules/Help/Commands/HelpCommand.cs index 706dac39..bfb99d7d 100644 --- a/NadekoBot/Modules/Help/Commands/HelpCommand.cs +++ b/NadekoBot/Modules/Help/Commands/HelpCommand.cs @@ -28,15 +28,14 @@ namespace NadekoBot.Classes.Help.Commands await e.Channel.SendMessage($"`Help for '{com.Text}':` {com.Description}").ConfigureAwait(false); }).ConfigureAwait(false); }; - public static string HelpString => (NadekoBot.IsBot - ? $"To add me to your server, use this link -> \n" - : $"To invite me to your server, just send me an invite link here.") + - $"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\n" + - "**LIST OF COMMANDS CAN BE FOUND ON THIS LINK**\n\n \n\n" + - "Nadeko Support Server: "; + public static string HelpString { + get { + var str = string.IsNullOrWhiteSpace(NadekoBot.Creds.ClientId) && !NadekoBot.Config.DontJoinServers + ? String.Format("To add me to your server, use this link -> \n", NadekoBot.Creds.ClientId) + : ""; + return str + String.Format(NadekoBot.Config.HelpString, NadekoBot.Config.CommandPrefixes.Help); + } + } public static string DMHelpString => NadekoBot.Config.DMHelpString; diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 91c74874..1f3cd52f 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -40,7 +40,6 @@ 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; } @@ -88,10 +87,10 @@ namespace NadekoBot } //if password is not entered, prompt for password - if (string.IsNullOrWhiteSpace(Creds.Password) && string.IsNullOrWhiteSpace(Creds.Token)) + if (string.IsNullOrWhiteSpace(Creds.Token)) { - Console.WriteLine("Password blank. Please enter your password:\n"); - Creds.Password = Console.ReadLine(); + Console.WriteLine("Token blank. Please enter your bot's token:\n"); + Creds.Token = Console.ReadLine(); } Console.WriteLine(string.IsNullOrWhiteSpace(Creds.GoogleAPIKey) @@ -182,20 +181,11 @@ namespace NadekoBot { try { - if (string.IsNullOrWhiteSpace(Creds.Token)) - await Client.Connect(Creds.Username, Creds.Password).ConfigureAwait(false); - else - { - await Client.Connect(Creds.Token).ConfigureAwait(false); - IsBot = true; - } + await Client.Connect(Creds.Token).ConfigureAwait(false); } catch (Exception ex) { - if (string.IsNullOrWhiteSpace(Creds.Token)) - Console.WriteLine($"Probably wrong EMAIL or PASSWORD."); - else - Console.WriteLine($"Token is wrong. Don't set a token if you don't have an official BOT account."); + Console.WriteLine($"Token is wrong. Don't set a token if you don't have an official BOT account."); Console.WriteLine(ex); Console.ReadKey(); return; @@ -253,31 +243,13 @@ namespace NadekoBot if (ConfigHandler.IsBlackListed(e)) return; - if (!NadekoBot.Config.DontJoinServers && !IsBot) - { - try - { - await (await Client.GetInvite(e.Message.Text).ConfigureAwait(false)).Accept().ConfigureAwait(false); - await e.Channel.SendMessage("I got in!").ConfigureAwait(false); - return; - } - catch - { - if (e.User.Id == 109338686889476096) - { //carbonitex invite - await e.Channel.SendMessage("Failed to join the server.").ConfigureAwait(false); - return; - } - } - } - if (Config.ForwardMessages && !NadekoBot.Creds.OwnerIds.Contains(e.User.Id) && OwnerPrivateChannel != null) await OwnerPrivateChannel.SendMessage(e.User + ": ```\n" + e.Message.Text + "\n```").ConfigureAwait(false); if (repliedRecently) return; repliedRecently = true; - if (e.Message.RawText != "-h") + if (e.Message.RawText != NadekoBot.Config.CommandPrefixes.Help + "h") await e.Channel.SendMessage(HelpCommand.DMHelpString).ConfigureAwait(false); await Task.Delay(2000).ConfigureAwait(false); repliedRecently = false; diff --git a/NadekoBot/_Models/JSONModels/Configuration.cs b/NadekoBot/_Models/JSONModels/Configuration.cs index df601db0..7bd638a0 100644 --- a/NadekoBot/_Models/JSONModels/Configuration.cs +++ b/NadekoBot/_Models/JSONModels/Configuration.cs @@ -131,6 +131,17 @@ namespace NadekoBot.Classes.JSONModels public string CurrencySign { get; set; } = "🌸"; public string CurrencyName { get; set; } = "NadekoFlower"; public string DMHelpString { get; set; } = "Type `-h` for help."; + public string HelpString { get; set; } = @"You can use `{0}modules` command to see a list of all modules. +You can use `{0}commands ModuleName` +(for example `{0}commands Administration`) to see a list of all of the commands in that module. +For a specific command help, use `{0}h ""Command name""` (for example `-h ""!m q""`) + + +**LIST OF COMMANDS CAN BE FOUND ON THIS LINK** + + + +Nadeko Support Server: "; } public class CommandPrefixesModel diff --git a/NadekoBot/_Models/JSONModels/_JSONModels.cs b/NadekoBot/_Models/JSONModels/_JSONModels.cs index 7b6c3dfa..4cac2e44 100644 --- a/NadekoBot/_Models/JSONModels/_JSONModels.cs +++ b/NadekoBot/_Models/JSONModels/_JSONModels.cs @@ -6,17 +6,17 @@ namespace NadekoBot.Classes.JSONModels { public class Credentials { - public string Username = "myemail@email.com"; - public string Password = "xxxxxxx"; - public string Token = ""; - public ulong BotId = 1231231231231; - public string GoogleAPIKey = ""; - public ulong[] OwnerIds = { 123123123123, 5675675679845 }; - public string TrelloAppKey = ""; - public string SoundCloudClientID = ""; - public string MashapeKey = ""; - public string LOLAPIKey = ""; - public string CarbonKey = ""; + public string Token { get; set; } = ""; + public string ClientId { get; set; } = ""; + public ulong BotId { get; set; } = 1231231231231; + public string GoogleAPIKey { get; set; } = ""; + public ulong[] OwnerIds { get; set; } = { 123123123123, 5675675679845 }; + public string TrelloAppKey { get; set; } = ""; + public string SoundCloudClientID { get; set; } = ""; + public string MashapeKey { get; set; } = ""; + public string LOLAPIKey { get; set; } = ""; + public string CarbonKey { get; set; } = ""; + } [DebuggerDisplay("{items[0].id.playlistId}")] public class YoutubePlaylistSearch diff --git a/NadekoBot/bin/Debug/credentials_example.json b/NadekoBot/bin/Debug/credentials_example.json index 5761a5f8..dff2ef79 100644 --- a/NadekoBot/bin/Debug/credentials_example.json +++ b/NadekoBot/bin/Debug/credentials_example.json @@ -1,7 +1,6 @@ { - "Username": "myemail@email.com", - "Password": "xxxxxxx", "Token": "", + "ClientId": "", "BotId": 1231231231231, "GoogleAPIKey": "", "OwnerIds": [ diff --git a/NadekoBot/bin/Debug/data/config_example.json b/NadekoBot/bin/Debug/data/config_example.json index 4496c5ff..ffbe7121 100644 --- a/NadekoBot/bin/Debug/data/config_example.json +++ b/NadekoBot/bin/Debug/data/config_example.json @@ -120,5 +120,6 @@ ], "CurrencySign": "🌸", "CurrencyName": "NadekoFlower", - "DMHelpString": "Type `-h` for help." + "DMHelpString": "Type `-h` for help.", + "HelpString": "You can use `{0}modules` command to see a list of all modules.\r\nYou can use `{0}commands ModuleName`\r\n(for example `{0}commands Administration`) to see a list of all of the commands in that module.\r\nFor a specific command help, use `{0}h \"Command name\"` (for example `-h \"!m q\"`)\r\n\r\n\r\n**LIST OF COMMANDS CAN BE FOUND ON THIS LINK**\r\n\r\n\r\n\r\nNadeko Support Server: " } \ No newline at end of file