From dada0b64c59404ce0be742a3d6a673e494997591 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 15 Jun 2016 16:12:34 +0200 Subject: [PATCH 01/19] cleanup + `.softban` added --- .../Administration/AdministrationModule.cs | 82 +++--- .../Commands/MessageRepeater.cs | 8 +- .../Commands/RatelimitCommand.cs | 6 - NadekoBot/Modules/Music/MusicModule.cs | 32 +-- .../Translator/Helpers/GoogleTranslator.cs | 258 +++++++++--------- 5 files changed, 185 insertions(+), 201 deletions(-) diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index 57a68dc6..922bdc00 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -6,9 +6,7 @@ using NadekoBot.DataModels; using NadekoBot.Extensions; using NadekoBot.Modules.Administration.Commands; using NadekoBot.Modules.Permissions.Classes; -using Newtonsoft.Json.Linq; using System; -using System.IO; using System.Linq; using System.Threading.Tasks; @@ -37,7 +35,7 @@ namespace NadekoBot.Modules.Administration public override void Install(ModuleManager manager) { - + manager.CreateCommands("", cgb => { @@ -315,6 +313,42 @@ namespace NadekoBot.Modules.Administration } }); + cgb.CreateCommand(Prefix + "sb").Alias(Prefix + "softban") + .Parameter("user", ParameterType.Required) + .Parameter("msg", ParameterType.Optional) + .Description("Bans and then unbans a user by id or name with an optional message.\n**Usage**: .sb \"@some Guy\" Your behaviour is toxic.") + .Do(async e => + { + var msg = e.GetArg("msg"); + var user = e.GetArg("user"); + if (e.User.ServerPermissions.BanMembers) + { + var usr = e.Server.FindUsers(user).FirstOrDefault(); + if (usr == null) + { + await e.Channel.SendMessage("User not found.").ConfigureAwait(false); + return; + } + if (!string.IsNullOrWhiteSpace(msg)) + { + await usr.SendMessage($"**You have been SOFT-BANNED from `{e.Server.Name}` server.**\n" + + $"Reason: {msg}").ConfigureAwait(false); + await Task.Delay(2000).ConfigureAwait(false); // temp solution; give time for a message to be send, fu volt + } + try + { + await e.Server.Ban(usr, 7).ConfigureAwait(false); + await e.Server.Unban(usr).ConfigureAwait(false); + + await e.Channel.SendMessage("Soft-Banned user " + usr.Name + " Id: " + usr.Id).ConfigureAwait(false); + } + catch + { + await e.Channel.SendMessage("Error. Most likely I don't have sufficient permissions.").ConfigureAwait(false); + } + } + }); + cgb.CreateCommand(Prefix + "k").Alias(Prefix + "kick") .Parameter("user") .Parameter("msg", ParameterType.Unparsed) @@ -685,18 +719,6 @@ namespace NadekoBot.Modules.Administration Environment.Exit(0); }); - //cgb.CreateCommand(Prefix + "newnick") - // .Alias(Prefix + "setnick") - // .Description("Give the bot a new nickname. You need manage server permissions.") - // .Parameter("new_nick", ParameterType.Unparsed) - // .AddCheck(SimpleCheckers.ManageServer()) - // .Do(async e => - // { - // if (e.GetArg("new_nick") == null) return; - - // await client.CurrentUser.Edit(NadekoBot.Creds.Password, e.GetArg("new_nick")).ConfigureAwait(false); - // }); - cgb.CreateCommand(Prefix + "newname") .Alias(Prefix + "setname") .Description("Give the bot a new name. **Owner Only!**") @@ -880,21 +902,6 @@ namespace NadekoBot.Modules.Administration }).ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "parsetosql") - .Description("Loads exported parsedata from /data/parsedata/ into sqlite database.") - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - await Task.Run(() => - { - SaveParseToDb("data/parsedata/Announcements.json"); - SaveParseToDb("data/parsedata/CommandsRan.json"); - SaveParseToDb("data/parsedata/Requests.json"); - SaveParseToDb("data/parsedata/Stats.json"); - SaveParseToDb("data/parsedata/TypingArticles.json"); - }).ConfigureAwait(false); - }); - cgb.CreateCommand(Prefix + "unstuck") .Description("Clears the message queue. **Owner Only!**") .AddCheck(SimpleCheckers.OwnerOnly()) @@ -917,7 +924,6 @@ namespace NadekoBot.Modules.Administration }).ConfigureAwait(false); }); - //THIS IS INTENTED TO BE USED ONLY BY THE ORIGINAL BOT OWNER cgb.CreateCommand(Prefix + "adddon") .Alias(Prefix + "donadd") .Description("Add a donator to the database.") @@ -1019,19 +1025,5 @@ namespace NadekoBot.Modules.Administration }); } - - public void SaveParseToDb(string where) where T : IDataModel - { - try - { - var data = File.ReadAllText(where); - var arr = JObject.Parse(data)["results"] as JArray; - if (arr == null) - return; - var objects = arr.Select(x => x.ToObject()); - DbHandler.Instance.InsertMany(objects); - } - catch { } - } } } diff --git a/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index 1a8ebb52..abcf35e5 100644 --- a/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -85,10 +85,12 @@ namespace NadekoBot.Modules.Administration.Commands // if both null, disable if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr)) { - await e.Channel.SendMessage("Repeating disabled").ConfigureAwait(false); + Repeater rep; - if (repeaters.TryRemove(e.Server, out rep)) - rep.MessageTimer.Stop(); + if (!repeaters.TryRemove(e.Server, out rep)) + return; + rep.MessageTimer.Stop(); + await e.Channel.SendMessage("Repeating disabled").ConfigureAwait(false); return; } int minutes; diff --git a/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs b/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs index d300e29a..22e0d695 100644 --- a/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs @@ -42,15 +42,9 @@ namespace NadekoBot.Modules.Administration.Commands { cgb.CreateCommand(Module.Prefix + "slowmode") .Description("Toggles slow mode. When ON, users will be able to send only 1 message every 5 seconds.") - .Parameter("minutes", ParameterType.Optional) .AddCheck(SimpleCheckers.ManageMessages()) .Do(async e => { - //var minutesStr = e.GetArg("minutes"); - //if (string.IsNullOrWhiteSpace(minutesStr)) { - // RatelimitingChannels.Remove(e.Channel.Id); - // return; - //} ConcurrentDictionary throwaway; if (RatelimitingChannels.TryRemove(e.Channel.Id, out throwaway)) { diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index cecf4555..4fcf3a36 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -23,22 +23,6 @@ namespace NadekoBot.Modules.Music public MusicModule() { - // ready for 1.0 - //NadekoBot.Client.UserUpdated += (s, e) => - //{ - // try - // { - // if (e.Before.VoiceChannel != e.After.VoiceChannel && - // e.Before.VoiceChannel.Members.Count() == 0) - // { - // MusicPlayer musicPlayer; - // if (!MusicPlayers.TryRemove(e.Server, out musicPlayer)) return; - // musicPlayer.Destroy(); - // } - // } - // catch { } - //}; - } public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Music; @@ -129,6 +113,7 @@ namespace NadekoBot.Modules.Music cgb.CreateCommand("lq") .Alias("ls").Alias("lp") .Description("Lists up to 15 currently queued songs.\n**Usage**: `!m lq`") + .Parameter("page", ParameterType.Optional) .Do(async e => { MusicPlayer musicPlayer; @@ -137,6 +122,13 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage("🎵 No active music player.").ConfigureAwait(false); return; } + + int page; + if (!int.TryParse(e.GetArg("page"), out page) || page <= 0) + { + page = 1; + } + var currentSong = musicPlayer.CurrentSong; if (currentSong == null) return; @@ -145,13 +137,15 @@ namespace NadekoBot.Modules.Music toSend += "🔂"; else if (musicPlayer.RepeatPlaylist) toSend += "🔁"; - toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued.` "; + toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued. Showing page {page}` "; if (musicPlayer.Playlist.Count >= MusicPlayer.MaximumPlaylistSize) toSend += "**Song queue is full!**\n"; else toSend += "\n"; - var number = 1; - await e.Channel.SendMessage(toSend + string.Join("\n", musicPlayer.Playlist.Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); + const int itemsPerPage = 15; + int startAt = itemsPerPage * (page - 1); + var number = 1 + startAt; + await e.Channel.SendMessage(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); }); cgb.CreateCommand("np") diff --git a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs index eb0e466c..44f311dc 100644 --- a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs +++ b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs @@ -110,7 +110,8 @@ namespace NadekoBot.Modules.Translator.Helpers } } } - else { + else + { // Translation of phrase text = text.Substring(0, index); text = text.Replace("],[", ","); @@ -180,134 +181,135 @@ namespace NadekoBot.Modules.Translator.Helpers { if (GoogleTranslator._languageModeMap == null) { - GoogleTranslator._languageModeMap = new Dictionary(); - GoogleTranslator._languageModeMap.Add("afrikaans", "af"); - GoogleTranslator._languageModeMap.Add("albanian", "sq"); - GoogleTranslator._languageModeMap.Add("arabic", "ar"); - GoogleTranslator._languageModeMap.Add("armenian", "hy"); - GoogleTranslator._languageModeMap.Add("azerbaijani", "az"); - GoogleTranslator._languageModeMap.Add("basque", "eu"); - GoogleTranslator._languageModeMap.Add("belarusian", "be"); - GoogleTranslator._languageModeMap.Add("bengali", "bn"); - GoogleTranslator._languageModeMap.Add("bulgarian", "bg"); - GoogleTranslator._languageModeMap.Add("catalan", "ca"); - GoogleTranslator._languageModeMap.Add("chinese", "zh-CN"); - GoogleTranslator._languageModeMap.Add("croatian", "hr"); - GoogleTranslator._languageModeMap.Add("czech", "cs"); - GoogleTranslator._languageModeMap.Add("danish", "da"); - GoogleTranslator._languageModeMap.Add("dutch", "nl"); - GoogleTranslator._languageModeMap.Add("english", "en"); - GoogleTranslator._languageModeMap.Add("esperanto", "eo"); - GoogleTranslator._languageModeMap.Add("estonian", "et"); - GoogleTranslator._languageModeMap.Add("filipino", "tl"); - GoogleTranslator._languageModeMap.Add("finnish", "fi"); - GoogleTranslator._languageModeMap.Add("french", "fr"); - GoogleTranslator._languageModeMap.Add("galician", "gl"); - GoogleTranslator._languageModeMap.Add("german", "de"); - GoogleTranslator._languageModeMap.Add("georgian", "ka"); - GoogleTranslator._languageModeMap.Add("greek", "el"); - GoogleTranslator._languageModeMap.Add("haitian Creole", "ht"); - GoogleTranslator._languageModeMap.Add("hebrew", "iw"); - GoogleTranslator._languageModeMap.Add("hindi", "hi"); - GoogleTranslator._languageModeMap.Add("hungarian", "hu"); - GoogleTranslator._languageModeMap.Add("icelandic", "is"); - GoogleTranslator._languageModeMap.Add("indonesian", "id"); - GoogleTranslator._languageModeMap.Add("irish", "ga"); - GoogleTranslator._languageModeMap.Add("italian", "it"); - GoogleTranslator._languageModeMap.Add("japanese", "ja"); - GoogleTranslator._languageModeMap.Add("korean", "ko"); - GoogleTranslator._languageModeMap.Add("lao", "lo"); - GoogleTranslator._languageModeMap.Add("latin", "la"); - GoogleTranslator._languageModeMap.Add("latvian", "lv"); - GoogleTranslator._languageModeMap.Add("lithuanian", "lt"); - GoogleTranslator._languageModeMap.Add("macedonian", "mk"); - GoogleTranslator._languageModeMap.Add("malay", "ms"); - GoogleTranslator._languageModeMap.Add("maltese", "mt"); - GoogleTranslator._languageModeMap.Add("norwegian", "no"); - GoogleTranslator._languageModeMap.Add("persian", "fa"); - GoogleTranslator._languageModeMap.Add("polish", "pl"); - GoogleTranslator._languageModeMap.Add("portuguese", "pt"); - GoogleTranslator._languageModeMap.Add("romanian", "ro"); - GoogleTranslator._languageModeMap.Add("russian", "ru"); - GoogleTranslator._languageModeMap.Add("serbian", "sr"); - GoogleTranslator._languageModeMap.Add("slovak", "sk"); - GoogleTranslator._languageModeMap.Add("slovenian", "sl"); - GoogleTranslator._languageModeMap.Add("spanish", "es"); - GoogleTranslator._languageModeMap.Add("swahili", "sw"); - GoogleTranslator._languageModeMap.Add("swedish", "sv"); - GoogleTranslator._languageModeMap.Add("tamil", "ta"); - GoogleTranslator._languageModeMap.Add("telugu", "te"); - GoogleTranslator._languageModeMap.Add("thai", "th"); - GoogleTranslator._languageModeMap.Add("turkish", "tr"); - GoogleTranslator._languageModeMap.Add("ukrainian", "uk"); - GoogleTranslator._languageModeMap.Add("urdu", "ur"); - GoogleTranslator._languageModeMap.Add("vietnamese", "vi"); - GoogleTranslator._languageModeMap.Add("welsh", "cy"); - GoogleTranslator._languageModeMap.Add("yiddish", "yi"); + GoogleTranslator._languageModeMap = new Dictionary() { + { "afrikaans", "af"}, + { "albanian", "sq"}, + { "arabic", "ar"}, + { "armenian", "hy"}, + { "azerbaijani", "az"}, + { "basque", "eu"}, + { "belarusian", "be"}, + { "bengali", "bn"}, + { "bulgarian", "bg"}, + { "catalan", "ca"}, + { "chinese", "zh-CN"}, + { "croatian", "hr"}, + { "czech", "cs"}, + { "danish", "da"}, + { "dutch", "nl"}, + { "english", "en"}, + { "esperanto", "eo"}, + { "estonian", "et"}, + { "filipino", "tl"}, + { "finnish", "fi"}, + { "french", "fr"}, + { "galician", "gl"}, + { "german", "de"}, + { "georgian", "ka"}, + { "greek", "el"}, + { "haitian Creole", "ht"}, + { "hebrew", "iw"}, + { "hindi", "hi"}, + { "hungarian", "hu"}, + { "icelandic", "is"}, + { "indonesian", "id"}, + { "irish", "ga"}, + { "italian", "it"}, + { "japanese", "ja"}, + { "korean", "ko"}, + { "lao", "lo"}, + { "latin", "la"}, + { "latvian", "lv"}, + { "lithuanian", "lt"}, + { "macedonian", "mk"}, + { "malay", "ms"}, + { "maltese", "mt"}, + { "norwegian", "no"}, + { "persian", "fa"}, + { "polish", "pl"}, + { "portuguese", "pt"}, + { "romanian", "ro"}, + { "russian", "ru"}, + { "serbian", "sr"}, + { "slovak", "sk"}, + { "slovenian", "sl"}, + { "spanish", "es"}, + { "swahili", "sw"}, + { "swedish", "sv"}, + { "tamil", "ta"}, + { "telugu", "te"}, + { "thai", "th"}, + { "turkish", "tr"}, + { "ukrainian", "uk"}, + { "urdu", "ur"}, + { "vietnamese", "vi"}, + { "welsh", "cy"}, + { "yiddish", "yi"}, - GoogleTranslator._languageModeMap.Add("af", "af"); - GoogleTranslator._languageModeMap.Add("sq", "sq"); - GoogleTranslator._languageModeMap.Add("ar", "ar"); - GoogleTranslator._languageModeMap.Add("hy", "hy"); - GoogleTranslator._languageModeMap.Add("az", "az"); - GoogleTranslator._languageModeMap.Add("eu", "eu"); - GoogleTranslator._languageModeMap.Add("be", "be"); - GoogleTranslator._languageModeMap.Add("bn", "bn"); - GoogleTranslator._languageModeMap.Add("bg", "bg"); - GoogleTranslator._languageModeMap.Add("ca", "ca"); - GoogleTranslator._languageModeMap.Add("zh-CN", "zh-CN"); - GoogleTranslator._languageModeMap.Add("hr", "hr"); - GoogleTranslator._languageModeMap.Add("cs", "cs"); - GoogleTranslator._languageModeMap.Add("da", "da"); - GoogleTranslator._languageModeMap.Add("nl", "nl"); - GoogleTranslator._languageModeMap.Add("en", "en"); - GoogleTranslator._languageModeMap.Add("eo", "eo"); - GoogleTranslator._languageModeMap.Add("et", "et"); - GoogleTranslator._languageModeMap.Add("tl", "tl"); - GoogleTranslator._languageModeMap.Add("fi", "fi"); - GoogleTranslator._languageModeMap.Add("fr", "fr"); - GoogleTranslator._languageModeMap.Add("gl", "gl"); - GoogleTranslator._languageModeMap.Add("de", "de"); - GoogleTranslator._languageModeMap.Add("ka", "ka"); - GoogleTranslator._languageModeMap.Add("el", "el"); - GoogleTranslator._languageModeMap.Add("ht", "ht"); - GoogleTranslator._languageModeMap.Add("iw", "iw"); - GoogleTranslator._languageModeMap.Add("hi", "hi"); - GoogleTranslator._languageModeMap.Add("hu", "hu"); - GoogleTranslator._languageModeMap.Add("is", "is"); - GoogleTranslator._languageModeMap.Add("id", "id"); - GoogleTranslator._languageModeMap.Add("ga", "ga"); - GoogleTranslator._languageModeMap.Add("it", "it"); - GoogleTranslator._languageModeMap.Add("ja", "ja"); - GoogleTranslator._languageModeMap.Add("ko", "ko"); - GoogleTranslator._languageModeMap.Add("lo", "lo"); - GoogleTranslator._languageModeMap.Add("la", "la"); - GoogleTranslator._languageModeMap.Add("lv", "lv"); - GoogleTranslator._languageModeMap.Add("lt", "lt"); - GoogleTranslator._languageModeMap.Add("mk", "mk"); - GoogleTranslator._languageModeMap.Add("ms", "ms"); - GoogleTranslator._languageModeMap.Add("mt", "mt"); - GoogleTranslator._languageModeMap.Add("no", "no"); - GoogleTranslator._languageModeMap.Add("fa", "fa"); - GoogleTranslator._languageModeMap.Add("pl", "pl"); - GoogleTranslator._languageModeMap.Add("pt", "pt"); - GoogleTranslator._languageModeMap.Add("ro", "ro"); - GoogleTranslator._languageModeMap.Add("ru", "ru"); - GoogleTranslator._languageModeMap.Add("sr", "sr"); - GoogleTranslator._languageModeMap.Add("sk", "sk"); - GoogleTranslator._languageModeMap.Add("sl", "sl"); - GoogleTranslator._languageModeMap.Add("es", "es"); - GoogleTranslator._languageModeMap.Add("sw", "sw"); - GoogleTranslator._languageModeMap.Add("sv", "sv"); - GoogleTranslator._languageModeMap.Add("ta", "ta"); - GoogleTranslator._languageModeMap.Add("te", "te"); - GoogleTranslator._languageModeMap.Add("th", "th"); - GoogleTranslator._languageModeMap.Add("tr", "tr"); - GoogleTranslator._languageModeMap.Add("uk", "uk"); - GoogleTranslator._languageModeMap.Add("ur", "ur"); - GoogleTranslator._languageModeMap.Add("vi", "vi"); - GoogleTranslator._languageModeMap.Add("cy", "cy"); - GoogleTranslator._languageModeMap.Add("yi", "yi"); + { "af", "af"}, + { "sq", "sq"}, + { "ar", "ar"}, + { "hy", "hy"}, + { "az", "az"}, + { "eu", "eu"}, + { "be", "be"}, + { "bn", "bn"}, + { "bg", "bg"}, + { "ca", "ca"}, + { "zh-CN", "zh-CN"}, + { "hr", "hr"}, + { "cs", "cs"}, + { "da", "da"}, + { "nl", "nl"}, + { "en", "en"}, + { "eo", "eo"}, + { "et", "et"}, + { "tl", "tl"}, + { "fi", "fi"}, + { "fr", "fr"}, + { "gl", "gl"}, + { "de", "de"}, + { "ka", "ka"}, + { "el", "el"}, + { "ht", "ht"}, + { "iw", "iw"}, + { "hi", "hi"}, + { "hu", "hu"}, + { "is", "is"}, + { "id", "id"}, + { "ga", "ga"}, + { "it", "it"}, + { "ja", "ja"}, + { "ko", "ko"}, + { "lo", "lo"}, + { "la", "la"}, + { "lv", "lv"}, + { "lt", "lt"}, + { "mk", "mk"}, + { "ms", "ms"}, + { "mt", "mt"}, + { "no", "no"}, + { "fa", "fa"}, + { "pl", "pl"}, + { "pt", "pt"}, + { "ro", "ro"}, + { "ru", "ru"}, + { "sr", "sr"}, + { "sk", "sk"}, + { "sl", "sl"}, + { "es", "es"}, + { "sw", "sw"}, + { "sv", "sv"}, + { "ta", "ta"}, + { "te", "te"}, + { "th", "th"}, + { "tr", "tr"}, + { "uk", "uk"}, + { "ur", "ur"}, + { "vi", "vi"}, + { "cy", "cy"}, + { "yi", "yi"}, + }; } } From c9a0b39d6942b5f48a887043fffc9ce68b324a58 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 15 Jun 2016 16:49:30 +0200 Subject: [PATCH 02/19] moved help module to the top for convenience --- NadekoBot/NadekoBot.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 88e3443d..91c74874 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -159,8 +159,8 @@ namespace NadekoBot })); //install modules - modules.Add(new AdministrationModule(), "Administration", ModuleFilter.None); modules.Add(new HelpModule(), "Help", ModuleFilter.None); + modules.Add(new AdministrationModule(), "Administration", ModuleFilter.None); modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None); modules.Add(new Conversations(), "Conversations", ModuleFilter.None); modules.Add(new GamblingModule(), "Gambling", ModuleFilter.None); From 5b379f7ffaf74f1fc669564a2ef626244d0c0925 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 15 Jun 2016 19:03:00 +0200 Subject: [PATCH 03/19] 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 From 3633c83e53b69b18293be71534fb27d83c7fba32 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 15 Jun 2016 20:01:53 +0200 Subject: [PATCH 04/19] default to nadeko's clientId. Reordered credentials from most to least important --- NadekoBot/_Models/JSONModels/_JSONModels.cs | 7 +++---- NadekoBot/bin/Debug/credentials_example.json | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/NadekoBot/_Models/JSONModels/_JSONModels.cs b/NadekoBot/_Models/JSONModels/_JSONModels.cs index 4cac2e44..d5e57d41 100644 --- a/NadekoBot/_Models/JSONModels/_JSONModels.cs +++ b/NadekoBot/_Models/JSONModels/_JSONModels.cs @@ -7,16 +7,15 @@ namespace NadekoBot.Classes.JSONModels public class Credentials { public string Token { get; set; } = ""; - public string ClientId { get; set; } = ""; + public string ClientId { get; set; } = "116275390695079945"; 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 GoogleAPIKey { get; set; } = ""; public string SoundCloudClientID { get; set; } = ""; public string MashapeKey { get; set; } = ""; public string LOLAPIKey { get; set; } = ""; + public string TrelloAppKey { 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 dff2ef79..d8d8fb33 100644 --- a/NadekoBot/bin/Debug/credentials_example.json +++ b/NadekoBot/bin/Debug/credentials_example.json @@ -1,15 +1,15 @@ { "Token": "", - "ClientId": "", + "ClientId": "116275390695079945", "BotId": 1231231231231, - "GoogleAPIKey": "", "OwnerIds": [ 123123123123, 5675675679845 ], - "TrelloAppKey": "", + "GoogleAPIKey": "", "SoundCloudClientID": "", "MashapeKey": "", "LOLAPIKey": "", + "TrelloAppKey": "", "CarbonKey": "" } \ No newline at end of file From 831d802c125702f152eb5935e78dfe8c5ede4265 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 15 Jun 2016 22:53:43 +0200 Subject: [PATCH 05/19] Owner only -> Bot owner only, Cleanup, removed requests, --- .../Administration/AdministrationModule.cs | 48 +++---- .../Commands/CustomReactionsCommands.cs | 2 +- .../Administration/Commands/LogCommand.cs | 8 +- .../Modules/Administration/Commands/Remind.cs | 2 +- .../Administration/Commands/SelfCommands.cs | 16 +-- .../Conversations/Commands/RequestsCommand.cs | 133 ------------------ .../Modules/Conversations/Conversations.cs | 1 - NadekoBot/Modules/Gambling/GamblingModule.cs | 4 +- .../Modules/Help/Commands/HelpCommand.cs | 2 +- NadekoBot/Modules/Music/MusicModule.cs | 6 +- 10 files changed, 41 insertions(+), 181 deletions(-) delete mode 100644 NadekoBot/Modules/Conversations/Commands/RequestsCommand.cs diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index 2b53821c..6d6ffacf 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -630,7 +630,7 @@ namespace NadekoBot.Modules.Administration }); cgb.CreateCommand(Prefix + "heap") - .Description("Shows allocated memory - **Owner Only!**") + .Description("Shows allocated memory - **Bot Owner Only!**") .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { @@ -710,7 +710,7 @@ namespace NadekoBot.Modules.Administration cgb.CreateCommand(Prefix + "die") .Alias(Prefix + "graceful") - .Description("Shuts the bot down and notifies users about the restart. **Owner Only!**") + .Description("Shuts the bot down and notifies users about the restart. **Bot Owner Only!**") .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { @@ -721,7 +721,7 @@ namespace NadekoBot.Modules.Administration cgb.CreateCommand(Prefix + "newname") .Alias(Prefix + "setname") - .Description("Give the bot a new name. **Owner Only!**") + .Description("Give the bot a new name. **Bot Owner Only!**") .Parameter("new_name", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => @@ -733,7 +733,7 @@ namespace NadekoBot.Modules.Administration cgb.CreateCommand(Prefix + "newavatar") .Alias(Prefix + "setavatar") - .Description("Sets a new avatar image for the NadekoBot. **Owner Only!**") + .Description("Sets a new avatar image for the NadekoBot. **Bot Owner Only!**") .Parameter("img", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => @@ -754,7 +754,7 @@ namespace NadekoBot.Modules.Administration }); cgb.CreateCommand(Prefix + "setgame") - .Description("Sets the bots game. **Owner Only!**") + .Description("Sets the bots game. **Bot Owner Only!**") .Parameter("set_game", ParameterType.Unparsed) .Do(e => { @@ -781,23 +781,23 @@ namespace NadekoBot.Modules.Administration Channel commsChannel = null; cgb.CreateCommand(Prefix + "commsuser") - .Description("Sets a user for through-bot communication. Only works if server is set. Resets commschannel. **Owner Only!**") - .Parameter("name", ParameterType.Unparsed) - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - commsUser = commsServer?.FindUsers(e.GetArg("name")).FirstOrDefault(); - if (commsUser != null) - { - commsChannel = null; - await e.Channel.SendMessage("User for comms set.").ConfigureAwait(false); - } - else - await e.Channel.SendMessage("No server specified or user.").ConfigureAwait(false); - }); + .Description("Sets a user for through-bot communication. Only works if server is set. Resets commschannel. **Bot Owner Only!**") + .Parameter("name", ParameterType.Unparsed) + .AddCheck(SimpleCheckers.OwnerOnly()) + .Do(async e => + { + commsUser = commsServer?.FindUsers(e.GetArg("name")).FirstOrDefault(); + if (commsUser != null) + { + commsChannel = null; + await e.Channel.SendMessage("User for comms set.").ConfigureAwait(false); + } + else + await e.Channel.SendMessage("No server specified or user.").ConfigureAwait(false); + }); cgb.CreateCommand(Prefix + "commsserver") - .Description("Sets a server for through-bot communication. **Owner Only!**") + .Description("Sets a server for through-bot communication. **Bot Owner Only!**") .Parameter("server", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => @@ -810,7 +810,7 @@ namespace NadekoBot.Modules.Administration }); cgb.CreateCommand(Prefix + "commschannel") - .Description("Sets a channel for through-bot communication. Only works if server is set. Resets commsuser. **Owner Only!**") + .Description("Sets a channel for through-bot communication. Only works if server is set. Resets commsuser. **Bot Owner Only!**") .Parameter("ch", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => @@ -826,7 +826,7 @@ namespace NadekoBot.Modules.Administration }); cgb.CreateCommand(Prefix + "send") - .Description("Send a message to someone on a different server through the bot. **Owner Only!**\n**Usage**: .send Message text multi word!") + .Description("Send a message to someone on a different server through the bot. **Bot Owner Only!**\n**Usage**: .send Message text multi word!") .Parameter("msg", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => @@ -903,7 +903,7 @@ namespace NadekoBot.Modules.Administration }); cgb.CreateCommand(Prefix + "unstuck") - .Description("Clears the message queue. **Owner Only!**") + .Description("Clears the message queue. **Bot Owner Only!**") .AddCheck(SimpleCheckers.OwnerOnly()) .Do(e => { @@ -974,7 +974,7 @@ namespace NadekoBot.Modules.Administration }); cgb.CreateCommand(Prefix + "announce") - .Description($"Sends a message to all servers' general channel bot is connected to.**Owner Only!**\n**Usage**: {Prefix}announce Useless spam") + .Description($"Sends a message to all servers' general channel bot is connected to.**Bot Owner Only!**\n**Usage**: {Prefix}announce Useless spam") .Parameter("msg", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => diff --git a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs index 09fe9d57..dcda6459 100644 --- a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs +++ b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs @@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Administration.Commands cgb.CreateCommand(Prefix + "addcustomreaction") .Alias(Prefix + "acr") - .Description($"Add a custom reaction. Guide here: **Owner Only!** \n**Usage**: {Prefix}acr \"hello\" I love saying hello to %user%") + .Description($"Add a custom reaction. Guide here: **Bot Owner Only!** \n**Usage**: {Prefix}acr \"hello\" I love saying hello to %user%") .AddCheck(SimpleCheckers.OwnerOnly()) .Parameter("name", ParameterType.Required) .Parameter("message", ParameterType.Unparsed) diff --git a/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/NadekoBot/Modules/Administration/Commands/LogCommand.cs index ad020ba4..7b7c1a48 100644 --- a/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -328,14 +328,13 @@ $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}` }); cgb.CreateCommand(Module.Prefix + "logserver") - .Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. **Owner Only!**") + .Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. **Bot Owner Only!**") .AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.ManageServer()) .Do(DoFunc()); cgb.CreateCommand(Module.Prefix + "userpresence") - .Description("Starts logging to this channel when someone from the server goes online/offline/idle. **Owner Only!**") - .AddCheck(SimpleCheckers.OwnerOnly()) + .Description("Starts logging to this channel when someone from the server goes online/offline/idle.") .AddCheck(SimpleCheckers.ManageServer()) .Do(async e => { @@ -351,9 +350,8 @@ $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}` }); cgb.CreateCommand(Module.Prefix + "voicepresence") - .Description("Toggles logging to this channel whenever someone joins or leaves a voice channel you are in right now. **Owner Only!**") + .Description("Toggles logging to this channel whenever someone joins or leaves a voice channel you are in right now.") .Parameter("all", ParameterType.Optional) - .AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.ManageServer()) .Do(async e => { diff --git a/NadekoBot/Modules/Administration/Commands/Remind.cs b/NadekoBot/Modules/Administration/Commands/Remind.cs index 667ef82b..8e171af5 100644 --- a/NadekoBot/Modules/Administration/Commands/Remind.cs +++ b/NadekoBot/Modules/Administration/Commands/Remind.cs @@ -180,7 +180,7 @@ namespace NadekoBot.Modules.Administration.Commands cgb.CreateCommand(Module.Prefix + "remindmsg") .Description("Sets message for when the remind is triggered. " + " Available placeholders are %user% - user who ran the command, %message% -" + - " Message specified in the remind, %target% - target channel of the remind. **Owner only!**") + " Message specified in the remind, %target% - target channel of the remind. **Bot Owner Only!**") .Parameter("msg", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => diff --git a/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs index 1530eee4..d6e3acd7 100644 --- a/NadekoBot/Modules/Administration/Commands/SelfCommands.cs +++ b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -1,11 +1,7 @@ -using NadekoBot.Classes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Discord.Commands; +using Discord.Commands; +using NadekoBot.Classes; using NadekoBot.Modules.Permissions.Classes; +using System.Linq; namespace NadekoBot.Modules.Administration.Commands { @@ -18,14 +14,14 @@ namespace NadekoBot.Modules.Administration.Commands internal override void Init(CommandGroupBuilder cgb) { cgb.CreateCommand(Module.Prefix + "leave") - .Description("Makes Nadeko leave the server. Either name or id required.\n**Usage**:.leave NSFW") + .Description("Makes Nadeko leave the server. Either name or id required.\n**Usage**: `.leave 123123123331`") .Parameter("arg", ParameterType.Required) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { - var arg = e.GetArg("arg")?.Trim(); + var arg = e.GetArg("arg").Trim(); var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? - NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault(); + NadekoBot.Client.FindServers(arg).FirstOrDefault(); if (server == null) { await e.Channel.SendMessage("Cannot find that server").ConfigureAwait(false); diff --git a/NadekoBot/Modules/Conversations/Commands/RequestsCommand.cs b/NadekoBot/Modules/Conversations/Commands/RequestsCommand.cs deleted file mode 100644 index c606feae..00000000 --- a/NadekoBot/Modules/Conversations/Commands/RequestsCommand.cs +++ /dev/null @@ -1,133 +0,0 @@ -using Discord.Commands; -using NadekoBot.Extensions; -using NadekoBot.Modules; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Threading.Tasks; - -namespace NadekoBot.Classes.Conversations.Commands -{ - internal class RequestsCommand : DiscordCommand - { - public void SaveRequest(CommandEventArgs e, string text) - { - DbHandler.Instance.InsertData(new DataModels.Request - { - RequestText = text, - UserName = e.User.Name, - UserId = (long)e.User.Id, - ServerId = (long)e.Server.Id, - ServerName = e.Server.Name, - DateAdded = DateTime.Now - }); - } - // todo what if it's too long? - public string GetRequests() - { - var task = DbHandler.Instance.GetAllRows(); - - var str = "Here are all current requests for NadekoBot:\n\n"; - foreach (var reqObj in task) - { - str += $"{reqObj.Id}. by **{reqObj.UserName}** from **{reqObj.ServerName}** at {reqObj.DateAdded.ToLocalTime()}\n" + - $"**{reqObj.RequestText}**\n----------\n"; - } - return str + "\n__Type [@NadekoBot clr] to clear all of my messages.__"; - } - - public bool DeleteRequest(int requestNumber) => - DbHandler.Instance.Delete(requestNumber) != null; - - /// - /// Delete a request with a number and returns that request object. - /// - /// RequestObject of the request. Null if none - public DataModels.Request ResolveRequest(int requestNumber) => - DbHandler.Instance.Delete(requestNumber); - - internal override void Init(CommandGroupBuilder cgb) - { - - cgb.CreateCommand("req") - .Alias("request") - .Description("Requests a feature for nadeko.\n**Usage**: @NadekoBot req new_feature") - .Parameter("all", ParameterType.Unparsed) - .Do(async e => - { - var str = e.Args[0]; - - try - { - SaveRequest(e, str); - } - catch - { - await e.Channel.SendMessage("Something went wrong.").ConfigureAwait(false); - return; - } - await e.Channel.SendMessage("Thank you for your request.").ConfigureAwait(false); - }); - - cgb.CreateCommand("lr") - .Description("PMs the user all current nadeko requests.") - .Do(async e => - { - var str = await Task.Run(() => GetRequests()).ConfigureAwait(false); - if (str.Trim().Length > 110) - await e.User.Send(str).ConfigureAwait(false); - else - await e.User.Send("No requests atm.").ConfigureAwait(false); - }); - - cgb.CreateCommand("dr") - .Description("Deletes a request. **Owner Only!**") - .Parameter("reqNumber", ParameterType.Required) - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - try - { - if (DeleteRequest(int.Parse(e.Args[0]))) - { - await e.Channel.SendMessage(e.User.Mention + " Request deleted.").ConfigureAwait(false); - } - else - { - await e.Channel.SendMessage("No request on that number.").ConfigureAwait(false); - } - } - catch - { - await e.Channel.SendMessage("Error deleting request, probably NaN error.").ConfigureAwait(false); - } - }); - - cgb.CreateCommand("rr") - .Description("Resolves a request. **Owner Only!**") - .Parameter("reqNumber", ParameterType.Required) - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - try - { - var sc = ResolveRequest(int.Parse(e.Args[0])); - if (sc != null) - { - await e.Channel.SendMessage(e.User.Mention + " Request resolved, notice sent.").ConfigureAwait(false); - await NadekoBot.Client.GetServer((ulong)sc.ServerId).GetUser((ulong)sc.UserId).Send("**This request of yours has been resolved:**\n" + sc.RequestText).ConfigureAwait(false); - } - else - { - await e.Channel.SendMessage("No request on that number.").ConfigureAwait(false); - } - } - catch - { - await e.Channel.SendMessage("Error resolving request, probably NaN error.").ConfigureAwait(false); - } - }); - } - - public RequestsCommand(DiscordModule module) : base(module) { } - } -} diff --git a/NadekoBot/Modules/Conversations/Conversations.cs b/NadekoBot/Modules/Conversations/Conversations.cs index 52d1b29a..bb928110 100644 --- a/NadekoBot/Modules/Conversations/Conversations.cs +++ b/NadekoBot/Modules/Conversations/Conversations.cs @@ -20,7 +20,6 @@ namespace NadekoBot.Modules.Conversations public Conversations() { commands.Add(new CopyCommand(this)); - commands.Add(new RequestsCommand(this)); commands.Add(new RipCommand(this)); } diff --git a/NadekoBot/Modules/Gambling/GamblingModule.cs b/NadekoBot/Modules/Gambling/GamblingModule.cs index 5c0c8919..668c1383 100644 --- a/NadekoBot/Modules/Gambling/GamblingModule.cs +++ b/NadekoBot/Modules/Gambling/GamblingModule.cs @@ -94,7 +94,7 @@ namespace NadekoBot.Modules.Gambling }); cgb.CreateCommand(Prefix + "award") - .Description("Gives someone a certain amount of flowers. **Owner only!**\n**Usage**: `$award 100 @person`") + .Description("Gives someone a certain amount of flowers. **Bot Owner Only!**\n**Usage**: `$award 100 @person`") .AddCheck(SimpleCheckers.OwnerOnly()) .Parameter("amount", ParameterType.Required) .Parameter("receiver", ParameterType.Unparsed) @@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Gambling }); cgb.CreateCommand(Prefix + "take") - .Description("Takes a certain amount of flowers from someone. **Owner only!**") + .Description("Takes a certain amount of flowers from someone. **Bot Owner Only!**") .AddCheck(SimpleCheckers.OwnerOnly()) .Parameter("amount", ParameterType.Required) .Parameter("rektperson", ParameterType.Unparsed) diff --git a/NadekoBot/Modules/Help/Commands/HelpCommand.cs b/NadekoBot/Modules/Help/Commands/HelpCommand.cs index bfb99d7d..21ef73a9 100644 --- a/NadekoBot/Modules/Help/Commands/HelpCommand.cs +++ b/NadekoBot/Modules/Help/Commands/HelpCommand.cs @@ -78,7 +78,7 @@ Version: `{NadekoStats.Instance.BotVersion}`"; .Parameter("command", ParameterType.Unparsed) .Do(HelpFunc()); cgb.CreateCommand(Module.Prefix + "hgit") - .Description("Generates the commandlist.md file. **Owner Only!**") + .Description("Generates the commandlist.md file. **Bot Owner Only!**") .AddCheck(SimpleCheckers.OwnerOnly()) .Do(DoGitFunc()); cgb.CreateCommand(Module.Prefix + "readme") diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index 4fcf3a36..220417ff 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -299,7 +299,7 @@ namespace NadekoBot.Modules.Music }); cgb.CreateCommand("lopl") - .Description("Queues all songs from a directory. **Owner Only!**\n**Usage**: `!m lopl C:/music/classical`") + .Description("Queues all songs from a directory. **Bot Owner Only!**\n**Usage**: `!m lopl C:/music/classical`") .Parameter("directory", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => @@ -339,7 +339,7 @@ namespace NadekoBot.Modules.Music }); cgb.CreateCommand("lo") - .Description("Queues a local file by specifying a full path. **Owner Only!**\n**Usage**: `!m lo C:/music/mysong.mp3`") + .Description("Queues a local file by specifying a full path. **Bot Owner Only!**\n**Usage**: `!m lo C:/music/mysong.mp3`") .Parameter("path", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => @@ -393,7 +393,7 @@ namespace NadekoBot.Modules.Music }); cgb.CreateCommand("cleanup") - .Description("Cleans up hanging voice connections. **Owner Only!**\n**Usage**: `!m cleanup`") + .Description("Cleans up hanging voice connections. **Bot Owner Only!**\n**Usage**: `!m cleanup`") .AddCheck(SimpleCheckers.OwnerOnly()) .Do(e => { From 91b9b9051cad16fc3d358f9132ea7df7d4f5f3c2 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 16 Jun 2016 15:08:28 +0200 Subject: [PATCH 06/19] removed this --- NadekoBot/NadekoBot.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 3876300b..904f2bf3 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -201,7 +201,6 @@ - From b8e90fd6c929ceb4ea1e11a4bc9f8fe870260c4c Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 17 Jun 2016 13:34:24 +0200 Subject: [PATCH 07/19] .iam error message --- .../Administration/Commands/SelfAssignedRolesCommand.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index e42aa270..1f5c06bb 100644 --- a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -121,7 +121,14 @@ namespace NadekoBot.Modules.Administration.Commands await e.Channel.SendMessage($":anger:You already have {role.Name} role.").ConfigureAwait(false); return; } - await e.User.AddRoles(role).ConfigureAwait(false); + try + { + await e.User.AddRoles(role).ConfigureAwait(false); + } + catch + { + await e.Channel.SendMessage($":anger:`I am unable to add that role to you. I can't add roles to owners or other roles higher than my role in the role hierarchy.`"); + } var msg = await e.Channel.SendMessage($":ok:You now have {role.Name} role.").ConfigureAwait(false); await Task.Delay(3000); await msg.Delete(); From 2081afdd2a858319d96bf4803b8db0999b0399c7 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 17 Jun 2016 14:03:26 +0200 Subject: [PATCH 08/19] Added buffer size to config. Added ConfigureAwait(false) to a lot of awaits. -commands is far prettier. --- .../Administration/AdministrationModule.cs | 22 +++++++++---------- .../Administration/Commands/AutoAssignRole.cs | 8 +++---- .../Commands/CustomReactionsCommands.cs | 10 ++++----- .../Commands/SelfAssignedRolesCommand.cs | 4 ++-- .../Administration/Commands/SelfCommands.cs | 6 ++--- NadekoBot/Modules/Help/HelpModule.cs | 4 ++-- NadekoBot/Modules/Music/Classes/Song.cs | 2 +- NadekoBot/_Models/JSONModels/Configuration.cs | 2 ++ NadekoBot/bin/Debug/data/config_example.json | 1 + 9 files changed, 31 insertions(+), 28 deletions(-) diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index 6d6ffacf..445f8bf1 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -150,7 +150,7 @@ namespace NadekoBot.Modules.Administration var roleToEdit = e.Server.FindRoles(r1).FirstOrDefault(); if (roleToEdit == null) { - await e.Channel.SendMessage("Can't find that role."); + await e.Channel.SendMessage("Can't find that role.").ConfigureAwait(false); return; } @@ -158,15 +158,15 @@ namespace NadekoBot.Modules.Administration { if (roleToEdit.Position > e.Server.CurrentUser.Roles.Max(r => r.Position)) { - await e.Channel.SendMessage("I can't edit roles higher than my highest role."); + await e.Channel.SendMessage("I can't edit roles higher than my highest role.").ConfigureAwait(false); return; } await roleToEdit.Edit(r2); - await e.Channel.SendMessage("Role renamed."); + await e.Channel.SendMessage("Role renamed.").ConfigureAwait(false); } catch (Exception) { - await e.Channel.SendMessage("Failed to rename role. Probably insufficient permissions."); + await e.Channel.SendMessage("Failed to rename role. Probably insufficient permissions.").ConfigureAwait(false); } }); @@ -945,7 +945,7 @@ namespace NadekoBot.Modules.Administration UserName = donator.Name, UserId = (long)donator.Id }); - e.Channel.SendMessage("Successfuly added a new donator. 👑"); + e.Channel.SendMessage("Successfuly added a new donator. 👑").ConfigureAwait(false); } catch { } }).ConfigureAwait(false); @@ -981,10 +981,10 @@ namespace NadekoBot.Modules.Administration { foreach (var ch in NadekoBot.Client.Servers.Select(s => s.DefaultChannel)) { - await ch.SendMessage(e.GetArg("msg")); + await ch.SendMessage(e.GetArg("msg")).ConfigureAwait(false); } - await e.Channel.SendMessage(":ok:"); + await e.Channel.SendMessage(":ok:").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "whoplays") @@ -1003,9 +1003,9 @@ namespace NadekoBot.Modules.Administration int i = 0; if (arr.Length == 0) - await e.Channel.SendMessage("Nobody. (not 100% sure)"); + await e.Channel.SendMessage("Nobody. (not 100% sure)").ConfigureAwait(false); else - await e.Channel.SendMessage("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"• {el,-35}")))) + "\n```"); + await e.Channel.SendMessage("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"• {el,-35}")))) + "\n```").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "leave") @@ -1019,8 +1019,8 @@ namespace NadekoBot.Modules.Administration { return; } - await srvr.Leave(); - await e.Channel.SendMessage("`Done.`"); + await srvr.Leave().ConfigureAwait(false); + await e.Channel.SendMessage("`Done.`").ConfigureAwait(false); }); }); diff --git a/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs b/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs index c6a5ab9a..c368aa0b 100644 --- a/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs +++ b/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs @@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Administration.Commands { if (!e.Server.CurrentUser.ServerPermissions.ManageRoles) { - await e.Channel.SendMessage("I do not have the permission to manage roles."); + await e.Channel.SendMessage("I do not have the permission to manage roles.").ConfigureAwait(false); return; } var r = e.GetArg("role")?.Trim(); @@ -52,19 +52,19 @@ namespace NadekoBot.Modules.Administration.Commands { config.AutoAssignedRole = 0; - await e.Channel.SendMessage("`Auto assign role on user join is now disabled.`"); + await e.Channel.SendMessage("`Auto assign role on user join is now disabled.`").ConfigureAwait(false); return; } var role = e.Server.FindRoles(r).FirstOrDefault(); if (role == null) { - await e.Channel.SendMessage("💢 `Role not found.`"); + await e.Channel.SendMessage("💢 `Role not found.`").ConfigureAwait(false); return; } config.AutoAssignedRole = role.Id; - await e.Channel.SendMessage("`Auto assigned role is set.`"); + await e.Channel.SendMessage("`Auto assigned role is set.`").ConfigureAwait(false); }); } diff --git a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs index dcda6459..81f9ab40 100644 --- a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs +++ b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs @@ -38,7 +38,7 @@ namespace NadekoBot.Modules.Administration.Commands NadekoBot.Config.CustomReactions[name].Add(message); else NadekoBot.Config.CustomReactions.Add(name, new System.Collections.Generic.List() { message }); - await Task.Run(() => Classes.JSONModels.ConfigHandler.SaveConfig()); + await Task.Run(() => Classes.JSONModels.ConfigHandler.SaveConfig()).ConfigureAwait(false); await e.Channel.SendMessage($"Added {name} : {message}").ConfigureAwait(false); }); @@ -52,7 +52,7 @@ namespace NadekoBot.Modules.Administration.Commands int num; if (!int.TryParse(e.GetArg("num"), out num) || num <= 0) return; string result = GetCustomsOnPage(num - 1); //People prefer starting with 1 - await e.Channel.SendMessage(result); + await e.Channel.SendMessage(result).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "deletecustomreaction") @@ -68,7 +68,7 @@ namespace NadekoBot.Modules.Administration.Commands return; if (!NadekoBot.Config.CustomReactions.ContainsKey(name)) { - await e.Channel.SendMessage("Could not find given commandname"); + await e.Channel.SendMessage("Could not find given commandname").ConfigureAwait(false); return; } string message = ""; @@ -94,8 +94,8 @@ namespace NadekoBot.Modules.Administration.Commands NadekoBot.Config.CustomReactions.Remove(name); message = $"Deleted custom reaction: `{name}`"; } - await Task.Run(() => Classes.JSONModels.ConfigHandler.SaveConfig()); - await e.Channel.SendMessage(message); + await Task.Run(() => Classes.JSONModels.ConfigHandler.SaveConfig()).ConfigureAwait(false); + await e.Channel.SendMessage(message).ConfigureAwait(false); }); } diff --git a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index 1f5c06bb..6b87b55f 100644 --- a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -127,14 +127,14 @@ namespace NadekoBot.Modules.Administration.Commands } catch { - await e.Channel.SendMessage($":anger:`I am unable to add that role to you. I can't add roles to owners or other roles higher than my role in the role hierarchy.`"); + await e.Channel.SendMessage($":anger:`I am unable to add that role to you. I can't add roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false); } var msg = await e.Channel.SendMessage($":ok:You now have {role.Name} role.").ConfigureAwait(false); await Task.Delay(3000); await msg.Delete(); try { - await e.Message.Delete(); + await e.Message.Delete().ConfigureAwait(false); } catch { } }); diff --git a/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs index d6e3acd7..e905d807 100644 --- a/NadekoBot/Modules/Administration/Commands/SelfCommands.cs +++ b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -29,13 +29,13 @@ namespace NadekoBot.Modules.Administration.Commands } if (!server.IsOwner) { - await server.Leave(); + await server.Leave().ConfigureAwait(false); } else { - await server.Delete(); + await server.Delete().ConfigureAwait(false); } - await NadekoBot.SendMessageToOwner("Left server " + server.Name); + await NadekoBot.SendMessageToOwner("Left server " + server.Name).ConfigureAwait(false); }); } } diff --git a/NadekoBot/Modules/Help/HelpModule.cs b/NadekoBot/Modules/Help/HelpModule.cs index f4fa618e..e1597d66 100644 --- a/NadekoBot/Modules/Help/HelpModule.cs +++ b/NadekoBot/Modules/Help/HelpModule.cs @@ -49,8 +49,8 @@ namespace NadekoBot.Modules.Help await e.Channel.SendMessage("That module does not exist.").ConfigureAwait(false); return; } - await e.Channel.SendMessage("`List of commands:` \n• " + string.Join("\n• ", cmdsArray.Select(c => c.Text))) - .ConfigureAwait(false); + var i = 0; + await e.Channel.SendMessage("`List Of Commands:`\n```xl\n" + string.Join("\n", cmdsArray.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"{el.Text,-22}")))) + "\n``` `You can type \"-h command name\" to see the help about that specific command.`").ConfigureAwait(false); }); }); } diff --git a/NadekoBot/Modules/Music/Classes/Song.cs b/NadekoBot/Modules/Music/Classes/Song.cs index 976867e0..520ab3d8 100644 --- a/NadekoBot/Modules/Music/Classes/Song.cs +++ b/NadekoBot/Modules/Music/Classes/Song.cs @@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Music.Classes $"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}`"; public SongInfo SongInfo { get; } - private PoopyBuffer songBuffer { get; } = new PoopyBuffer(4.MiB()); + private PoopyBuffer songBuffer { get; } = new PoopyBuffer(NadekoBot.Config.BufferSize); private bool prebufferingComplete { get; set; } = false; public MusicPlayer MusicPlayer { get; set; } diff --git a/NadekoBot/_Models/JSONModels/Configuration.cs b/NadekoBot/_Models/JSONModels/Configuration.cs index 7bd638a0..1b58871a 100644 --- a/NadekoBot/_Models/JSONModels/Configuration.cs +++ b/NadekoBot/_Models/JSONModels/Configuration.cs @@ -1,4 +1,5 @@ using Discord; +using NadekoBot.Extensions; using Newtonsoft.Json; using System.Collections.Generic; using System.IO; @@ -10,6 +11,7 @@ namespace NadekoBot.Classes.JSONModels public bool DontJoinServers { get; set; } = false; public bool ForwardMessages { get; set; } = true; public bool IsRotatingStatus { get; set; } = false; + public int BufferSize { get; set; } = 4.MiB(); [JsonIgnore] public List Quotes { get; set; } = new List(); diff --git a/NadekoBot/bin/Debug/data/config_example.json b/NadekoBot/bin/Debug/data/config_example.json index ffbe7121..10f0b6c5 100644 --- a/NadekoBot/bin/Debug/data/config_example.json +++ b/NadekoBot/bin/Debug/data/config_example.json @@ -2,6 +2,7 @@ "DontJoinServers": false, "ForwardMessages": true, "IsRotatingStatus": false, + "BufferSize": 4194304, "RemindMessageFormat": "❗⏰**I've been told to remind you to '%message%' now by %user%.**⏰❗", "CustomReactions": { "\\o\\": [ From 8944df8478e7cfb030df8d3b3947646958454dbb Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 17 Jun 2016 14:32:06 +0200 Subject: [PATCH 09/19] Better -modules and -commands --- NadekoBot/Modules/Help/HelpModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NadekoBot/Modules/Help/HelpModule.cs b/NadekoBot/Modules/Help/HelpModule.cs index e1597d66..fc19b28f 100644 --- a/NadekoBot/Modules/Help/HelpModule.cs +++ b/NadekoBot/Modules/Help/HelpModule.cs @@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Help .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))) + await e.Channel.SendMessage("`List of modules:` \n• " + string.Join("\n• ", NadekoBot.Client.GetService().Modules.Select(m => m.Name)) + $"\n`Type \"{Prefix}commands module_name\" to get a list of commands in that module.`") .ConfigureAwait(false); }); @@ -50,7 +50,7 @@ namespace NadekoBot.Modules.Help return; } var i = 0; - await e.Channel.SendMessage("`List Of Commands:`\n```xl\n" + string.Join("\n", cmdsArray.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"{el.Text,-22}")))) + "\n``` `You can type \"-h command name\" to see the help about that specific command.`").ConfigureAwait(false); + await e.Channel.SendMessage("`List Of Commands:`\n```xl\n" + string.Join("\n", cmdsArray.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"{el.Text,-22}")))) + $"\n``` `You can type \"{Prefix}h command_name\" to see the help about that specific command.`").ConfigureAwait(false); }); }); } From d2c455a9a605bbef599cd914ef634e9c0efd15f6 Mon Sep 17 00:00:00 2001 From: appelemac Date: Fri, 17 Jun 2016 22:10:51 +0200 Subject: [PATCH 10/19] Custom Random range --- .../CustomReactions/CustomReactions.cs | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/NadekoBot/Modules/CustomReactions/CustomReactions.cs index 39d59efd..4eee432a 100644 --- a/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -1,38 +1,42 @@ using Discord.Commands; using Discord.Modules; -using NadekoBot.Extensions; using NadekoBot.Modules.Permissions.Classes; using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; namespace NadekoBot.Modules.CustomReactions { - class CustomReactionsModule : DiscordModule + internal class CustomReactionsModule : DiscordModule { public override string Prefix { get; } = ""; - Random rng = new Random(); + private Random rng = new Random(); - private Dictionary> commandFuncs; + private Dictionary> commandFuncs; public CustomReactionsModule() { - commandFuncs = new Dictionary> + commandFuncs = new Dictionary> { - {"%rng%", (e) => rng.Next().ToString()}, - {"%mention%", (e) => NadekoBot.BotMention }, - {"%user%", e => e.User.Mention }, - {"%target%", e => e.GetArg("args")?.Trim() ?? "" }, + {new Regex(@"%rng:?(\d{0,9})-?(\d{0,9})%"), (e,m) => { + int start, end; + if (int.TryParse(m.Groups[1].Value, out start) && int.TryParse(m.Groups[2].Value, out end)) { + return rng.Next(start, end).ToString(); + } + else return rng.Next().ToString(); + } }, + {new Regex("%mention%"), (e,m) => NadekoBot.BotMention }, + {new Regex("%user%"), (e,m) => e.User.Mention }, + {new Regex("%target%"), (e,m) => e.GetArg("args")?.Trim() ?? "" }, }; } public override void Install(ModuleManager manager) { - manager.CreateCommands("", cgb => { - cgb.AddCheck(PermissionChecker.Instance); foreach (var command in NadekoBot.Config.CustomReactions) @@ -47,11 +51,17 @@ namespace NadekoBot.Modules.CustomReactions .Do(async e => { string str = command.Value[rng.Next(0, command.Value.Count())]; - commandFuncs.Keys.ForEach(k => str = str.Replace(k, commandFuncs[k](e))); + foreach (var key in commandFuncs.Keys) + { + foreach (Match m in key.Matches(str)) + { + str = str.Replace(m.Value, commandFuncs[key](e, m)); + } + } + await e.Channel.SendMessage(str).ConfigureAwait(false); }); } - }); } } From 1feddabce13b83ec41f9fc05da9fed8f1014a07e Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sat, 18 Jun 2016 00:02:03 +0200 Subject: [PATCH 11/19] Better help, better organization of aliases and commands names, a lot of commandnames changed. --- .../Administration/AdministrationModule.cs | 86 +++++++------------ .../Commands/CustomReactionsCommands.cs | 6 +- .../Administration/Commands/InfoCommands.cs | 12 +-- .../Commands/SelfAssignedRolesCommand.cs | 4 +- .../Commands/VoicePlusTextCommand.cs | 5 +- NadekoBot/Modules/Help/HelpModule.cs | 7 +- NadekoBot/Modules/Searches/SearchesModule.cs | 30 ++++++- 7 files changed, 80 insertions(+), 70 deletions(-) diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index 445f8bf1..e3e8bdf1 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -56,7 +56,7 @@ namespace NadekoBot.Modules.Administration Environment.Exit(0); }); - cgb.CreateCommand(Prefix + "sr").Alias(Prefix + "setrole") + cgb.CreateCommand(Prefix + "setrole").Alias(Prefix + "sr") .Description("Sets a role for a given user.\n**Usage**: .sr @User Guest") .Parameter("user_name", ParameterType.Required) .Parameter("role_name", ParameterType.Unparsed) @@ -99,7 +99,7 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "rr").Alias(Prefix + "removerole") + cgb.CreateCommand(Prefix + "removerole").Alias(Prefix + "rr") .Description("Removes a role from a given user.\n**Usage**: .rr @User Admin") .Parameter("user_name", ParameterType.Required) .Parameter("role_name", ParameterType.Unparsed) @@ -136,8 +136,8 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "renr") - .Alias(Prefix + "renamerole") + cgb.CreateCommand(Prefix + "renamerole") + .Alias(Prefix + "renr") .Description($"Renames a role. Role you are renaming must be lower than bot's highest role.\n**Usage**: `{Prefix}renr \"First role\" SecondRole`") .Parameter("r1", ParameterType.Required) .Parameter("r2", ParameterType.Required) @@ -170,7 +170,7 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "rar").Alias(Prefix + "removeallroles") + cgb.CreateCommand(Prefix + "removeallroles").Alias(Prefix + "rar") .Description("Removes all roles from a mentioned user.\n**Usage**: .rar @User") .Parameter("user_name", ParameterType.Unparsed) .AddCheck(SimpleCheckers.CanManageRoles) @@ -196,7 +196,7 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "r").Alias(Prefix + "role").Alias(Prefix + "cr") + cgb.CreateCommand(Prefix + "createrole").Alias(Prefix + "cr") .Description("Creates a role with a given name.**Usage**: `.r Awesome Role`") .Parameter("role_name", ParameterType.Unparsed) .AddCheck(SimpleCheckers.CanManageRoles) @@ -278,7 +278,7 @@ namespace NadekoBot.Modules.Administration await e.Channel.SendMessage("`List of roles:` \n• " + string.Join("\n• ", e.Server.Roles)).ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "b").Alias(Prefix + "ban") + cgb.CreateCommand(Prefix + "ban").Alias(Prefix + "b") .Parameter("user", ParameterType.Required) .Parameter("msg", ParameterType.Optional) .Description("Bans a user by id or name with an optional message.\n**Usage**: .b \"@some Guy\" Your behaviour is toxic.") @@ -313,7 +313,7 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "sb").Alias(Prefix + "softban") + cgb.CreateCommand(Prefix + "softban").Alias(Prefix + "sb") .Parameter("user", ParameterType.Required) .Parameter("msg", ParameterType.Optional) .Description("Bans and then unbans a user by id or name with an optional message.\n**Usage**: .sb \"@some Guy\" Your behaviour is toxic.") @@ -349,7 +349,7 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "k").Alias(Prefix + "kick") + cgb.CreateCommand(Prefix + "kick").Alias(Prefix + "k") .Parameter("user") .Parameter("msg", ParameterType.Unparsed) .Description("Kicks a mentioned user.") @@ -462,7 +462,7 @@ namespace NadekoBot.Modules.Administration }); cgb.CreateCommand(Prefix + "undeafen") - .Alias(Prefix + "undeaf") + .Alias(Prefix + "undef") .Description("Undeafens mentioned user or users") .Parameter("throwaway", ParameterType.Unparsed) .Do(async e => @@ -488,8 +488,9 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "rvch") - .Description("Removes a voice channel with a given name.") + cgb.CreateCommand(Prefix + "delvoichanl") + .Alias(Prefix + "dvch") + .Description("Deletes a voice channel with a given name.") .Parameter("channel_name", ParameterType.Required) .Do(async e => { @@ -510,7 +511,8 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "vch").Alias(Prefix + "cvch") + cgb.CreateCommand(Prefix + "creatvoichanl") + .Alias(Prefix + "cvch") .Description("Creates a new voice channel with a given name.") .Parameter("channel_name", ParameterType.Required) .Do(async e => @@ -529,8 +531,9 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "rch").Alias(Prefix + "rtch") - .Description("Removes a text channel with a given name.") + cgb.CreateCommand(Prefix + "deltxtchanl") + .Alias(Prefix + "dtch") + .Description("Deletes a text channel with a given name.") .Parameter("channel_name", ParameterType.Required) .Do(async e => { @@ -550,7 +553,8 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "ch").Alias(Prefix + "tch") + cgb.CreateCommand(Prefix + "creatxtchanl") + .Alias(Prefix + "ctch") .Description("Creates a new text channel with a given name.") .Parameter("channel_name", ParameterType.Required) .Do(async e => @@ -569,8 +573,8 @@ namespace NadekoBot.Modules.Administration } }); - cgb.CreateCommand(Prefix + "st").Alias(Prefix + "settopic") - .Alias(Prefix + "topic") + cgb.CreateCommand(Prefix + "settopic") + .Alias(Prefix + "st") .Description($"Sets a topic on the current channel.\n**Usage**: `{Prefix}st My new topic`") .AddCheck(SimpleCheckers.ManageChannels()) .Parameter("topic", ParameterType.Unparsed) @@ -581,8 +585,8 @@ namespace NadekoBot.Modules.Administration await e.Channel.SendMessage(":ok: **New channel topic set.**").ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "schn").Alias(Prefix + "setchannelname") - .Alias(Prefix + "topic") + cgb.CreateCommand(Prefix + "setchanlname") + .Alias(Prefix + "schn") .Description("Changed the name of the current channel.") .AddCheck(SimpleCheckers.ManageChannels()) .Parameter("name", ParameterType.Unparsed) @@ -595,7 +599,7 @@ namespace NadekoBot.Modules.Administration await e.Channel.SendMessage(":ok: **New channel name set.**").ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "uid").Alias(Prefix + "userid") + cgb.CreateCommand(Prefix + "userid").Alias(Prefix + "uid") .Description("Shows user ID.") .Parameter("user", ParameterType.Unparsed) .Do(async e => @@ -607,11 +611,11 @@ namespace NadekoBot.Modules.Administration await e.Channel.SendMessage($"Id of the user { usr.Name } is { usr.Id }").ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "cid").Alias(Prefix + "channelid") + cgb.CreateCommand(Prefix + "channelid").Alias(Prefix + "cid") .Description("Shows current channel ID.") .Do(async e => await e.Channel.SendMessage("This channel's ID is " + e.Channel.Id).ConfigureAwait(false)); - cgb.CreateCommand(Prefix + "sid").Alias(Prefix + "serverid") + cgb.CreateCommand(Prefix + "serverid").Alias(Prefix + "sid") .Description("Shows current server ID.") .Do(async e => await e.Channel.SendMessage("This server's ID is " + e.Server.Id).ConfigureAwait(false)); @@ -639,7 +643,7 @@ namespace NadekoBot.Modules.Administration }); cgb.CreateCommand(Prefix + "prune") - .Alias(".clr") + .Alias(Prefix + "clr") .Description( "`.prune` removes all nadeko's messages in the last 100 messages.`.prune X` removes last X messages from the channel (up to 100)`.prune @Someone` removes all Someone's messages in the last 100 messages.`.prune @Someone X` removes last X 'Someone's' messages in the channel.\n**Usage**: `.prune` or `.prune 5` or `.prune @Someone` or `.prune @Someone X`") .Parameter("user_or_num", ParameterType.Optional) @@ -709,7 +713,6 @@ namespace NadekoBot.Modules.Administration }); cgb.CreateCommand(Prefix + "die") - .Alias(Prefix + "graceful") .Description("Shuts the bot down and notifies users about the restart. **Bot Owner Only!**") .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => @@ -719,8 +722,8 @@ namespace NadekoBot.Modules.Administration Environment.Exit(0); }); - cgb.CreateCommand(Prefix + "newname") - .Alias(Prefix + "setname") + cgb.CreateCommand(Prefix + "setname") + .Alias(Prefix + "newnm") .Description("Give the bot a new name. **Bot Owner Only!**") .Parameter("new_name", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) @@ -839,8 +842,8 @@ namespace NadekoBot.Modules.Administration await e.Channel.SendMessage("Failed. Make sure you've specified server and [channel or user]").ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "menrole") - .Alias(Prefix + "mentionrole") + cgb.CreateCommand(Prefix + "mentionrole") + .Alias(Prefix + "menro") .Description("Mentions every person from the provided role or roles (separated by a ',') on this server. Requires you to have mention everyone permission.") .Parameter("roles", ParameterType.Unparsed) .Do(async e => @@ -924,8 +927,7 @@ namespace NadekoBot.Modules.Administration }).ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "adddon") - .Alias(Prefix + "donadd") + cgb.CreateCommand(Prefix + "donadd") .Description("Add a donator to the database.") .Parameter("donator") .Parameter("amount") @@ -951,28 +953,6 @@ namespace NadekoBot.Modules.Administration }).ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "videocall") - .Description("Creates a private video call link for you and other mentioned people. The link is sent to mentioned people via a private message.") - .Parameter("arg", ParameterType.Unparsed) - .Do(async e => - { - try - { - var allUsrs = e.Message.MentionedUsers.Union(new User[] { e.User }); - var allUsrsArray = allUsrs as User[] ?? allUsrs.ToArray(); - var str = allUsrsArray.Aggregate("http://appear.in/", (current, usr) => current + Uri.EscapeUriString(usr.Name[0].ToString())); - str += new Random().Next(); - foreach (var usr in allUsrsArray) - { - await usr.SendMessage(str).ConfigureAwait(false); - } - } - catch (Exception ex) - { - Console.WriteLine(ex); - } - }); - cgb.CreateCommand(Prefix + "announce") .Description($"Sends a message to all servers' general channel bot is connected to.**Bot Owner Only!**\n**Usage**: {Prefix}announce Useless spam") .Parameter("msg", ParameterType.Unparsed) diff --git a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs index 81f9ab40..3809df90 100644 --- a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs +++ b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs @@ -19,7 +19,7 @@ namespace NadekoBot.Modules.Administration.Commands { var Prefix = Module.Prefix; - cgb.CreateCommand(Prefix + "addcustomreaction") + cgb.CreateCommand(Prefix + "addcustreact") .Alias(Prefix + "acr") .Description($"Add a custom reaction. Guide here: **Bot Owner Only!** \n**Usage**: {Prefix}acr \"hello\" I love saying hello to %user%") .AddCheck(SimpleCheckers.OwnerOnly()) @@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Administration.Commands }); - cgb.CreateCommand(Prefix + "listcustomreactions") + cgb.CreateCommand(Prefix + "listcustreact") .Alias(Prefix + "lcr") .Description($"Lists all current custom reactions (paginated with 5 commands per page).\n**Usage**:{Prefix}lcr 1") .Parameter("num", ParameterType.Required) @@ -55,7 +55,7 @@ namespace NadekoBot.Modules.Administration.Commands await e.Channel.SendMessage(result).ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "deletecustomreaction") + cgb.CreateCommand(Prefix + "delcustreact") .Alias(Prefix + "dcr") .Description("Deletes a custom reaction with given name (and index)") .Parameter("name", ParameterType.Required) diff --git a/NadekoBot/Modules/Administration/Commands/InfoCommands.cs b/NadekoBot/Modules/Administration/Commands/InfoCommands.cs index 9d6770ea..6d661285 100644 --- a/NadekoBot/Modules/Administration/Commands/InfoCommands.cs +++ b/NadekoBot/Modules/Administration/Commands/InfoCommands.cs @@ -16,8 +16,8 @@ namespace NadekoBot.Modules.Administration.Commands internal override void Init(CommandGroupBuilder cgb) { - cgb.CreateCommand(Module.Prefix + "sinfo") - .Alias(Module.Prefix + "serverinfo") + cgb.CreateCommand(Module.Prefix + "serverinfo") + .Alias(Module.Prefix + "sinfo") .Description($"Shows info about the server the bot is on. If no channel is supplied, it defaults to current one.\n**Usage**:{Module.Prefix}sinfo Some Server") .Parameter("server", ParameterType.Optional) .Do(async e => @@ -47,8 +47,8 @@ namespace NadekoBot.Modules.Administration.Commands await e.Channel.SendMessage(sb.ToString()).ConfigureAwait(false); }); - cgb.CreateCommand(Module.Prefix + "cinfo") - .Alias(Module.Prefix + "channelinfo") + cgb.CreateCommand(Module.Prefix + "channelinfo") + .Alias(Module.Prefix + "cinfo") .Description($"Shows info about the channel. If no channel is supplied, it defaults to current one.\n**Usage**:{Module.Prefix}cinfo #some-channel") .Parameter("channel", ParameterType.Optional) .Do(async e => @@ -69,8 +69,8 @@ namespace NadekoBot.Modules.Administration.Commands await e.Channel.SendMessage(sb.ToString()).ConfigureAwait(false); }); - cgb.CreateCommand(Module.Prefix + "uinfo") - .Alias(Module.Prefix + "userinfo") + cgb.CreateCommand(Module.Prefix + "userinfo") + .Alias(Module.Prefix + "uinfo") .Description($"Shows info about the user. If no user is supplied, it defaults a user running the command.\n**Usage**:{Module.Prefix}uinfo @SomeUser") .Parameter("user", ParameterType.Optional) .Do(async e => diff --git a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index 6b87b55f..eaf59a3a 100644 --- a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -139,8 +139,8 @@ namespace NadekoBot.Modules.Administration.Commands catch { } }); - cgb.CreateCommand(Module.Prefix + "iamn") - .Alias(Module.Prefix + "iamnot") + cgb.CreateCommand(Module.Prefix + "iamnot") + .Alias(Module.Prefix + "iamn") .Description("Removes a role to you that you choose. " + "Role must be on a list of self-assignable roles." + "\n**Usage**: .iamn Gamer") diff --git a/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs b/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs index 44419682..e307c796 100644 --- a/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs @@ -87,6 +87,7 @@ namespace NadekoBot.Modules.Administration.Commands internal override void Init(CommandGroupBuilder cgb) { cgb.CreateCommand(Module.Prefix + "cleanv+t") + .Alias(Module.Prefix + "cv+t") .Description("Deletes all text channels ending in `-voice` for which voicechannels are not found. **Use at your own risk.**") .AddCheck(SimpleCheckers.CanManageRoles) .AddCheck(SimpleCheckers.ManageChannels()) @@ -116,8 +117,8 @@ namespace NadekoBot.Modules.Administration.Commands await e.Channel.SendMessage("`Done.`"); }); - cgb.CreateCommand(Module.Prefix + "v+t") - .Alias(Module.Prefix + "voice+text") + cgb.CreateCommand(Module.Prefix + "voice+text") + .Alias(Module.Prefix + "v+t") .Description("Creates a text channel for each voice channel only users in that voice channel can see." + "If you are server owner, keep in mind you will see them all the time regardless.") .AddCheck(SimpleCheckers.ManageChannels()) diff --git a/NadekoBot/Modules/Help/HelpModule.cs b/NadekoBot/Modules/Help/HelpModule.cs index fc19b28f..7612ef9b 100644 --- a/NadekoBot/Modules/Help/HelpModule.cs +++ b/NadekoBot/Modules/Help/HelpModule.cs @@ -50,7 +50,12 @@ namespace NadekoBot.Modules.Help return; } var i = 0; - await e.Channel.SendMessage("`List Of Commands:`\n```xl\n" + string.Join("\n", cmdsArray.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"{el.Text,-22}")))) + $"\n``` `You can type \"{Prefix}h command_name\" to see the help about that specific command.`").ConfigureAwait(false); + await e.Channel.SendMessage("`List Of Commands:`\n```xl\n" + + string.Join("\n", cmdsArray.GroupBy(item => (i++) / 3) + .Select(ig => string.Join("", ig.Select(el => $"{el.Text,-15}" + $"{"[" + el.Aliases.FirstOrDefault() + "]",-8}")))) + + $"\n```") + .ConfigureAwait(false); + await e.Channel.SendMessage($"`You can type \"{Prefix}h command_name\" to see the help about that specific command.`").ConfigureAwait(false); }); }); } diff --git a/NadekoBot/Modules/Searches/SearchesModule.cs b/NadekoBot/Modules/Searches/SearchesModule.cs index a614bd82..48e1c809 100644 --- a/NadekoBot/Modules/Searches/SearchesModule.cs +++ b/NadekoBot/Modules/Searches/SearchesModule.cs @@ -1,4 +1,5 @@ -using Discord.Commands; +using Discord; +using Discord.Commands; using Discord.Modules; using NadekoBot.Classes; using NadekoBot.Classes.JSONModels; @@ -27,7 +28,7 @@ namespace NadekoBot.Modules.Searches commands.Add(new StreamNotifications(this)); commands.Add(new ConverterCommand(this)); commands.Add(new RedditCommand(this)); - commands.Add(new WowJokeCommand(this)); + commands.Add(new WowJokeCommand(this)); commands.Add(new CalcCommand(this)); commands.Add(new WowJokeCommand(this)); rng = new Random(); @@ -472,7 +473,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 var red = Convert.ToInt32(arg1.Substring(0, 2), 16); var green = Convert.ToInt32(arg1.Substring(2, 2), 16); var blue = Convert.ToInt32(arg1.Substring(4, 2), 16); - var brush = new SolidBrush(Color.FromArgb(red, green, blue)); + var brush = new SolidBrush(System.Drawing.Color.FromArgb(red, green, blue)); using (Graphics g = Graphics.FromImage(img)) { @@ -482,6 +483,29 @@ $@"🌍 **Weather for** 【{obj["target"]}】 await e.Channel.SendFile("arg1.png", img.ToStream()); }); + + + cgb.CreateCommand(Prefix + "videocall") + .Description("Creates a private video call link for you and other mentioned people. The link is sent to mentioned people via a private message.") + .Parameter("arg", ParameterType.Unparsed) + .Do(async e => + { + try + { + var allUsrs = e.Message.MentionedUsers.Union(new User[] { e.User }); + var allUsrsArray = allUsrs as User[] ?? allUsrs.ToArray(); + var str = allUsrsArray.Aggregate("http://appear.in/", (current, usr) => current + Uri.EscapeUriString(usr.Name[0].ToString())); + str += new Random().Next(); + foreach (var usr in allUsrsArray) + { + await usr.SendMessage(str).ConfigureAwait(false); + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + }); }); } } From f41564cc007de2ee84299c0c3e49a49eed3fd613 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sat, 18 Jun 2016 04:11:55 +0200 Subject: [PATCH 12/19] music commandnames and aliases updated --- NadekoBot/Modules/Music/MusicModule.cs | 59 ++++++++++++++------------ 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index 220417ff..cec47ec6 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -38,8 +38,8 @@ namespace NadekoBot.Modules.Music commands.ForEach(cmd => cmd.Init(cgb)); - cgb.CreateCommand("n") - .Alias("next") + cgb.CreateCommand("next") + .Alias("n") .Alias("skip") .Description("Goes to the next song in the queue. You have to be in the same voice channel as the bot.\n**Usage**: `!m n`") .Do(e => @@ -50,8 +50,8 @@ namespace NadekoBot.Modules.Music musicPlayer.Next(); }); - cgb.CreateCommand("s") - .Alias("stop") + cgb.CreateCommand("stop") + .Alias("s") .Description("Stops the music and clears the playlist. Stays in the channel.\n**Usage**: `!m s`") .Do(async e => { @@ -64,8 +64,8 @@ namespace NadekoBot.Modules.Music }).ConfigureAwait(false); }); - cgb.CreateCommand("d") - .Alias("destroy") + cgb.CreateCommand("destroy") + .Alias("d") .Description("Completely stops the music and unbinds the bot from the channel. " + "(may cause weird behaviour)\n**Usage**: `!m d`") .Do(async e => @@ -79,8 +79,8 @@ namespace NadekoBot.Modules.Music }).ConfigureAwait(false); }); - cgb.CreateCommand("p") - .Alias("pause") + cgb.CreateCommand("pause") + .Alias("p") .Description("Pauses or Unpauses the song.\n**Usage**: `!m p`") .Do(async e => { @@ -95,7 +95,8 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage("🎵`Music Player unpaused.`").ConfigureAwait(false); }); - cgb.CreateCommand("q") + cgb.CreateCommand("queue") + .Alias("q") .Alias("yq") .Description("Queue a song using keywords or a link. Bot will join your voice channel." + "**You must be in a voice channel**.\n**Usage**: `!m q Dream Of Venice`") @@ -110,8 +111,8 @@ namespace NadekoBot.Modules.Music } }); - cgb.CreateCommand("lq") - .Alias("ls").Alias("lp") + cgb.CreateCommand("listqueue") + .Alias("lq") .Description("Lists up to 15 currently queued songs.\n**Usage**: `!m lq`") .Parameter("page", ParameterType.Optional) .Do(async e => @@ -148,8 +149,8 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); }); - cgb.CreateCommand("np") - .Alias("playing") + cgb.CreateCommand("nowplaying") + .Alias("np") .Description("Shows the song currently playing.\n**Usage**: `!m np`") .Do(async e => { @@ -163,7 +164,8 @@ namespace NadekoBot.Modules.Music $"{currentSong.PrettyCurrentTime()}").ConfigureAwait(false); }); - cgb.CreateCommand("vol") + cgb.CreateCommand("volume") + .Alias("vol") .Description("Sets the music volume 0-100%\n**Usage**: `!m vol 50`") .Parameter("val", ParameterType.Required) .Do(async e => @@ -184,8 +186,8 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage($"🎵 `Volume set to {volume}%`").ConfigureAwait(false); }); - cgb.CreateCommand("dv") - .Alias("defvol") + cgb.CreateCommand("defvol") + .Alias("dv") .Description("Sets the default music volume when music playback is started (0-100)." + " Does not persist through restarts.\n**Usage**: `!m dv 80`") .Parameter("val", ParameterType.Required) @@ -202,7 +204,7 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage($"🎵 `Default volume set to {volume}%`").ConfigureAwait(false); }); - cgb.CreateCommand("min").Alias("mute") + cgb.CreateCommand("mute").Alias("min") .Description("Sets the music volume to 0%\n**Usage**: `!m min`") .Do(e => { @@ -238,7 +240,8 @@ namespace NadekoBot.Modules.Music musicPlayer.SetVolume(50); }); - cgb.CreateCommand("sh") + cgb.CreateCommand("shuffle") + .Alias("sh") .Description("Shuffles the current playlist.\n**Usage**: `!m sh`") .Do(async e => { @@ -257,7 +260,8 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage("🎵 `Songs shuffled.`").ConfigureAwait(false); }); - cgb.CreateCommand("pl") + cgb.CreateCommand("playlist") + .Alias("pl") .Description("Queues up to 50 songs from a youtube playlist specified by a link, or keywords.\n**Usage**: `!m pl playlist link or name`") .Parameter("playlist", ParameterType.Unparsed) .Do(async e => @@ -298,7 +302,8 @@ namespace NadekoBot.Modules.Music await msg.Edit("🎵 `Playlist queue complete.`").ConfigureAwait(false); }); - cgb.CreateCommand("lopl") + cgb.CreateCommand("localplaylist") + .Alias("lopl") .Description("Queues all songs from a directory. **Bot Owner Only!**\n**Usage**: `!m lopl C:/music/classical`") .Parameter("directory", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) @@ -338,7 +343,8 @@ namespace NadekoBot.Modules.Music } }); - cgb.CreateCommand("lo") + cgb.CreateCommand("local") + .Alias("lo") .Description("Queues a local file by specifying a full path. **Bot Owner Only!**\n**Usage**: `!m lo C:/music/mysong.mp3`") .Parameter("path", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) @@ -350,7 +356,8 @@ namespace NadekoBot.Modules.Music await QueueSong(e.Channel, e.User.VoiceChannel, e.GetArg("path"), musicType: MusicType.Local).ConfigureAwait(false); }); - cgb.CreateCommand("mv") + cgb.CreateCommand("move") + .Alias("mv") .Description("Moves the bot to your voice channel. (works only if music is already playing)\n**Usage**: `!m mv`") .Do(e => { @@ -410,8 +417,8 @@ namespace NadekoBot.Modules.Music } }); - cgb.CreateCommand("rcs") - .Alias("repeatcurrentsong") + cgb.CreateCommand("repeatcursong") + .Alias("rcs") .Description("Toggles repeat of current song.\n**Usage**: `!m rcs`") .Do(async e => { @@ -428,8 +435,8 @@ namespace NadekoBot.Modules.Music .ConfigureAwait(false); }); - cgb.CreateCommand("rpl") - .Alias("repeatplaylist") + cgb.CreateCommand("repeatplaylist") + .Alias("rpl") .Description("Toggles repeat of all songs in the queue (every song that finishes is added to the end of the queue).\n**Usage**: `!m rpl`") .Do(async e => { From 46f0fcc1569e0611bef0f7f7734922655d1abe9a Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sat, 18 Jun 2016 04:24:21 +0200 Subject: [PATCH 13/19] music commandnames updated --- NadekoBot/Modules/Music/MusicModule.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index cec47ec6..98f4fafe 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -302,7 +302,7 @@ namespace NadekoBot.Modules.Music await msg.Edit("🎵 `Playlist queue complete.`").ConfigureAwait(false); }); - cgb.CreateCommand("localplaylist") + cgb.CreateCommand("localplaylst") .Alias("lopl") .Description("Queues all songs from a directory. **Bot Owner Only!**\n**Usage**: `!m lopl C:/music/classical`") .Parameter("directory", ParameterType.Unparsed) @@ -417,7 +417,7 @@ namespace NadekoBot.Modules.Music } }); - cgb.CreateCommand("repeatcursong") + cgb.CreateCommand("reptcursong") .Alias("rcs") .Description("Toggles repeat of current song.\n**Usage**: `!m rcs`") .Do(async e => @@ -435,7 +435,7 @@ namespace NadekoBot.Modules.Music .ConfigureAwait(false); }); - cgb.CreateCommand("repeatplaylist") + cgb.CreateCommand("rpeatplaylst") .Alias("rpl") .Description("Toggles repeat of all songs in the queue (every song that finishes is added to the end of the queue).\n**Usage**: `!m rpl`") .Do(async e => From d3d17815848a6e1867f35047afa03a3b7b7701d9 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sat, 18 Jun 2016 04:50:46 +0200 Subject: [PATCH 14/19] some normalization of commandname vs alias --- NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs | 8 ++++---- NadekoBot/Modules/Pokemon/PokemonModule.cs | 4 ++-- NadekoBot/Modules/Searches/SearchesModule.cs | 4 ++-- NadekoBot/Modules/Translator/TranslateCommand.cs | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs b/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs index 026d2eca..a96a7347 100644 --- a/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs +++ b/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs @@ -75,8 +75,8 @@ namespace NadekoBot.Modules.ClashOfClans //war with the index X started. }); - cgb.CreateCommand(Prefix + "sw") - .Alias(Prefix + "startwar") + cgb.CreateCommand(Prefix + "startwar") + .Alias(Prefix + "sw") .Description("Starts a war with a given number.") .Parameter("number", ParameterType.Required) .Do(async e => @@ -177,8 +177,8 @@ namespace NadekoBot.Modules.ClashOfClans } }); - cgb.CreateCommand(Prefix + "cf") - .Alias(Prefix + "claimfinish") + cgb.CreateCommand(Prefix + "claimfinish") + .Alias(Prefix + "cf") .Description($"Finish your claim if you destroyed a base. Optional second argument finishes for someone else.\n**Usage**: {Prefix}cf [war_number] [optional_other_name]") .Parameter("number", ParameterType.Required) .Parameter("other_name", ParameterType.Unparsed) diff --git a/NadekoBot/Modules/Pokemon/PokemonModule.cs b/NadekoBot/Modules/Pokemon/PokemonModule.cs index f24ea89f..7cc90720 100644 --- a/NadekoBot/Modules/Pokemon/PokemonModule.cs +++ b/NadekoBot/Modules/Pokemon/PokemonModule.cs @@ -194,8 +194,8 @@ namespace NadekoBot.Modules.Pokemon await e.Channel.SendMessage(response).ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "ml") - .Alias("movelist") + cgb.CreateCommand(Prefix + "movelist") + .Alias(Prefix + "ml") .Description("Lists the moves you are able to use") .Do(async e => { diff --git a/NadekoBot/Modules/Searches/SearchesModule.cs b/NadekoBot/Modules/Searches/SearchesModule.cs index 48e1c809..543f50a8 100644 --- a/NadekoBot/Modules/Searches/SearchesModule.cs +++ b/NadekoBot/Modules/Searches/SearchesModule.cs @@ -393,8 +393,8 @@ $@"🌍 **Weather for** 【{obj["target"]}】 await e.Channel.SendMessage("`" + JObject.Parse(response)["value"]["joke"].ToString() + "` 😆").ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "mi") - .Alias(Prefix + "magicitem") + cgb.CreateCommand(Prefix + "magicitem") + .Alias(Prefix + "mi") .Description("Shows a random magicitem from ") .Do(async e => { diff --git a/NadekoBot/Modules/Translator/TranslateCommand.cs b/NadekoBot/Modules/Translator/TranslateCommand.cs index 2ac7b43c..29ac4036 100644 --- a/NadekoBot/Modules/Translator/TranslateCommand.cs +++ b/NadekoBot/Modules/Translator/TranslateCommand.cs @@ -12,8 +12,8 @@ namespace NadekoBot.Modules.Translator internal override void Init(CommandGroupBuilder cgb) { - cgb.CreateCommand(Module.Prefix + "trans") - .Alias(Module.Prefix + "translate") + cgb.CreateCommand(Module.Prefix + "translate") + .Alias(Module.Prefix + "trans") .Description($"Translates from>to text. From the given language to the destiation language.\n**Usage**: {Module.Prefix}trans en>fr Hello") .Parameter("langs", ParameterType.Required) .Parameter("text", ParameterType.Unparsed) From 485ee3108aa924d62f92cccca882632606da872c Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sat, 18 Jun 2016 05:27:38 +0200 Subject: [PATCH 15/19] conversations and customreactions have old formating. Help command improvement done. --- NadekoBot/Modules/Help/HelpModule.cs | 18 +++++--- .../Commands/FilterInvitesCommand.cs | 8 ++-- .../Commands/FilterWordsCommand.cs | 20 ++++----- .../Modules/Permissions/PermissionsModule.cs | 45 ++++++++++--------- 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/NadekoBot/Modules/Help/HelpModule.cs b/NadekoBot/Modules/Help/HelpModule.cs index 7612ef9b..1b8ad4ec 100644 --- a/NadekoBot/Modules/Help/HelpModule.cs +++ b/NadekoBot/Modules/Help/HelpModule.cs @@ -41,8 +41,11 @@ namespace NadekoBot.Modules.Help .Parameter("module", ParameterType.Unparsed) .Do(async e => { + var module = e.GetArg("module")?.Trim().ToLower(); + if (string.IsNullOrWhiteSpace(module)) + return; var cmds = NadekoBot.Client.GetService().AllCommands - .Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower()); + .Where(c => c.Category.ToLower() == module); var cmdsArray = cmds as Command[] ?? cmds.ToArray(); if (!cmdsArray.Any()) { @@ -50,11 +53,14 @@ namespace NadekoBot.Modules.Help return; } var i = 0; - await e.Channel.SendMessage("`List Of Commands:`\n```xl\n" + - string.Join("\n", cmdsArray.GroupBy(item => (i++) / 3) - .Select(ig => string.Join("", ig.Select(el => $"{el.Text,-15}" + $"{"[" + el.Aliases.FirstOrDefault() + "]",-8}")))) - + $"\n```") - .ConfigureAwait(false); + if (module != "customreactions" && module != "conversations") + await e.Channel.SendMessage("`List Of Commands:`\n```xl\n" + + string.Join("\n", cmdsArray.GroupBy(item => (i++) / 3) + .Select(ig => string.Join("", ig.Select(el => $"{el.Text,-15}" + $"{"[" + el.Aliases.FirstOrDefault() + "]",-8}")))) + + $"\n```") + .ConfigureAwait(false); + else + await e.Channel.SendMessage("`List Of Commands:`\n• " + string.Join("\n• ", cmdsArray.Select(c => $"{c.Text}"))); await e.Channel.SendMessage($"`You can type \"{Prefix}h command_name\" to see the help about that specific command.`").ConfigureAwait(false); }); }); diff --git a/NadekoBot/Modules/Permissions/Commands/FilterInvitesCommand.cs b/NadekoBot/Modules/Permissions/Commands/FilterInvitesCommand.cs index 98e1a2f1..c9c9a945 100644 --- a/NadekoBot/Modules/Permissions/Commands/FilterInvitesCommand.cs +++ b/NadekoBot/Modules/Permissions/Commands/FilterInvitesCommand.cs @@ -51,8 +51,8 @@ namespace NadekoBot.Modules.Permissions.Commands internal override void Init(CommandGroupBuilder cgb) { - cgb.CreateCommand(Module.Prefix + "cfi") - .Alias(Module.Prefix + "channelfilterinvites") + cgb.CreateCommand(Module.Prefix + "chnlfilterinv") + .Alias(Module.Prefix + "cfi") .Description("Enables or disables automatic deleting of invites on the channel." + "If no channel supplied, it will default to current one. Use ALL to apply to all existing channels at once." + "\n**Usage**: ;cfi enable #general-chat") @@ -93,8 +93,8 @@ namespace NadekoBot.Modules.Permissions.Commands } }); - cgb.CreateCommand(Module.Prefix + "sfi") - .Alias(Module.Prefix + "serverfilterinvites") + cgb.CreateCommand(Module.Prefix + "srvrfilterinv") + .Alias(Module.Prefix + "sfi") .Description("Enables or disables automatic deleting of invites on the server.\n**Usage**: ;sfi disable") .Parameter("bool") .Do(async e => diff --git a/NadekoBot/Modules/Permissions/Commands/FilterWordsCommand.cs b/NadekoBot/Modules/Permissions/Commands/FilterWordsCommand.cs index 0ce09572..3d21c1a0 100644 --- a/NadekoBot/Modules/Permissions/Commands/FilterWordsCommand.cs +++ b/NadekoBot/Modules/Permissions/Commands/FilterWordsCommand.cs @@ -49,8 +49,8 @@ namespace NadekoBot.Modules.Permissions.Commands internal override void Init(CommandGroupBuilder cgb) { - cgb.CreateCommand(Module.Prefix + "cfw") - .Alias(Module.Prefix + "channelfilterwords") + cgb.CreateCommand(Module.Prefix + "chnlfilterwords") + .Alias(Module.Prefix + "cfw") .Description("Enables or disables automatic deleting of messages containing banned words on the channel." + "If no channel supplied, it will default to current one. Use ALL to apply to all existing channels at once." + "\n**Usage**: ;cfw enable #general-chat") @@ -86,8 +86,8 @@ namespace NadekoBot.Modules.Permissions.Commands } }); - cgb.CreateCommand(Module.Prefix + "afw") - .Alias(Module.Prefix + "addfilteredword") + cgb.CreateCommand(Module.Prefix + "addfilterword") + .Alias(Module.Prefix + "afw") .Description("Adds a new word to the list of filtered words" + "\n**Usage**: ;afw poop") .Parameter("word", ParameterType.Unparsed) @@ -108,8 +108,8 @@ namespace NadekoBot.Modules.Permissions.Commands } }); - cgb.CreateCommand(Module.Prefix + "rfw") - .Alias(Module.Prefix + "removefilteredword") + cgb.CreateCommand(Module.Prefix + "rmvfilterword") + .Alias(Module.Prefix + "rfw") .Description("Removes the word from the list of filtered words" + "\n**Usage**: ;rw poop") .Parameter("word", ParameterType.Unparsed) @@ -130,8 +130,8 @@ namespace NadekoBot.Modules.Permissions.Commands } }); - cgb.CreateCommand(Module.Prefix + "lfw") - .Alias(Module.Prefix + "listfilteredwords") + cgb.CreateCommand(Module.Prefix + "lstfilterwords") + .Alias(Module.Prefix + "lfw") .Description("Shows a list of filtered words" + "\n**Usage**: ;lfw") .Do(async e => @@ -150,8 +150,8 @@ namespace NadekoBot.Modules.Permissions.Commands } }); - cgb.CreateCommand(Module.Prefix + "sfw") - .Alias(Module.Prefix + "serverfilterwords") + cgb.CreateCommand(Module.Prefix + "srvrfilterwords") + .Alias(Module.Prefix + "sfw") .Description("Enables or disables automatic deleting of messages containing forbidden words on the server.\n**Usage**: ;sfw disable") .Parameter("bool") .Do(async e => diff --git a/NadekoBot/Modules/Permissions/PermissionsModule.cs b/NadekoBot/Modules/Permissions/PermissionsModule.cs index 81f88470..9b7012c1 100644 --- a/NadekoBot/Modules/Permissions/PermissionsModule.cs +++ b/NadekoBot/Modules/Permissions/PermissionsModule.cs @@ -58,8 +58,8 @@ namespace NadekoBot.Modules.Permissions await e.Channel.SendMessage($"Role `{role.Name}` is now required in order to change permissions.").ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "rpc") - .Alias(Prefix + "rolepermissionscopy") + cgb.CreateCommand(Prefix + "rolepermscopy") + .Alias(Prefix + "rpc") .Description($"Copies BOT PERMISSIONS (not discord permissions) from one role to another.\n**Usage**:`{Prefix}rpc Some Role ~ Some other role`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => @@ -86,8 +86,8 @@ namespace NadekoBot.Modules.Permissions await e.Channel.SendMessage($"💢{ex.Message}"); } }); - cgb.CreateCommand(Prefix + "cpc") - .Alias(Prefix + "channelpermissionscopy") + cgb.CreateCommand(Prefix + "chnlpermscopy") + .Alias(Prefix + "cpc") .Description($"Copies BOT PERMISSIONS (not discord permissions) from one channel to another.\n**Usage**:`{Prefix}cpc Some Channel ~ Some other channel`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => @@ -114,8 +114,8 @@ namespace NadekoBot.Modules.Permissions await e.Channel.SendMessage($"💢{ex.Message}"); } }); - cgb.CreateCommand(Prefix + "upc") - .Alias(Prefix + "userpermissionscopy") + cgb.CreateCommand(Prefix + "usrpermscopy") + .Alias(Prefix + "upc") .Description($"Copies BOT PERMISSIONS (not discord permissions) from one role to another.\n**Usage**:`{Prefix}upc @SomeUser ~ @SomeOtherUser`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => @@ -155,7 +155,7 @@ namespace NadekoBot.Modules.Permissions await e.Channel.SendMessage($"Verbosity set to {val}.").ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "serverperms") + cgb.CreateCommand(Prefix + "srvrperms") .Alias(Prefix + "sp") .Description("Shows banned permissions for this server.") .Do(async e => @@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Permissions await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "channelperms") + cgb.CreateCommand(Prefix + "chnlperms") .Alias(Prefix + "cp") .Description("Shows banned permissions for a certain channel. No argument means for this channel.\n**Usage**: ;cp #dev") .Parameter("channel", ParameterType.Unparsed) @@ -241,7 +241,8 @@ namespace NadekoBot.Modules.Permissions await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "sm").Alias(Prefix + "servermodule") + cgb.CreateCommand(Prefix + "srvrmdl") + .Alias(Prefix + "sm") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description("Sets a module's permission at the server level.\n**Usage**: ;sm [module_name] enable") @@ -265,7 +266,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "sc").Alias(Prefix + "servercommand") + cgb.CreateCommand(Prefix + "srvrcmd").Alias(Prefix + "sc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description("Sets a command's permission at the server level.\n**Usage**: ;sc [command_name] disable") @@ -289,7 +290,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "rm").Alias(Prefix + "rolemodule") + cgb.CreateCommand(Prefix + "rolemdl").Alias(Prefix + "rm") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) @@ -327,7 +328,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "rc").Alias(Prefix + "rolecommand") + cgb.CreateCommand(Prefix + "rolecmd").Alias(Prefix + "rc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) @@ -365,7 +366,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "cm").Alias(Prefix + "channelmodule") + cgb.CreateCommand(Prefix + "chnlmdl").Alias(Prefix + "cm") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) @@ -408,7 +409,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "cc").Alias(Prefix + "channelcommand") + cgb.CreateCommand(Prefix + "chnlcmd").Alias(Prefix + "cc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) @@ -446,7 +447,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "um").Alias(Prefix + "usermodule") + cgb.CreateCommand(Prefix + "usrmdl").Alias(Prefix + "um") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("user", ParameterType.Unparsed) @@ -472,7 +473,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "uc").Alias(Prefix + "usercommand") + cgb.CreateCommand(Prefix + "usrcmd").Alias(Prefix + "uc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("user", ParameterType.Unparsed) @@ -498,7 +499,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "asm").Alias(Prefix + "allservermodules") + cgb.CreateCommand(Prefix + "allsrvrmdls").Alias(Prefix + "asm") .Parameter("bool", ParameterType.Required) .Description("Sets permissions for all modules at the server level.\n**Usage**: ;asm [enable/disable]") .Do(async e => @@ -523,7 +524,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "asc").Alias(Prefix + "allservercommands") + cgb.CreateCommand(Prefix + "allsrvrcmds").Alias(Prefix + "asc") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description("Sets permissions for all commands from a certain module at the server level.\n**Usage**: ;asc [module_name] [enable/disable]") @@ -550,7 +551,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "acm").Alias(Prefix + "allchannelmodules") + cgb.CreateCommand(Prefix + "allchnlmdls").Alias(Prefix + "acm") .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description("Sets permissions for all modules at the channel level.\n**Usage**: ;acm [enable/disable] [channel_name]") @@ -578,7 +579,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "acc").Alias(Prefix + "allchannelcommands") + cgb.CreateCommand(Prefix + "allchnlcmds").Alias(Prefix + "acc") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) @@ -606,7 +607,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "arm").Alias(Prefix + "allrolemodules") + cgb.CreateCommand(Prefix + "allrolemdls").Alias(Prefix + "arm") .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description("Sets permissions for all modules at the role level.\n**Usage**: ;arm [enable/disable] [role_name]") @@ -633,7 +634,7 @@ namespace NadekoBot.Modules.Permissions } }); - cgb.CreateCommand(Prefix + "arc").Alias(Prefix + "allrolecommands") + cgb.CreateCommand(Prefix + "allrolecmds").Alias(Prefix + "arc") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) From 4ed29ea38e4c9e45e27c02b901a862aa0b7cd919 Mon Sep 17 00:00:00 2001 From: appelemac Date: Sat, 18 Jun 2016 13:26:31 +0200 Subject: [PATCH 16/19] made it a one-liner --- NadekoBot/Modules/CustomReactions/CustomReactions.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/NadekoBot/Modules/CustomReactions/CustomReactions.cs index 4eee432a..f4ebceac 100644 --- a/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -1,5 +1,6 @@ using Discord.Commands; using Discord.Modules; +using NadekoBot.Extensions; using NadekoBot.Modules.Permissions.Classes; using System; using System.Collections.Generic; @@ -30,6 +31,7 @@ namespace NadekoBot.Modules.CustomReactions {new Regex("%mention%"), (e,m) => NadekoBot.BotMention }, {new Regex("%user%"), (e,m) => e.User.Mention }, {new Regex("%target%"), (e,m) => e.GetArg("args")?.Trim() ?? "" }, + }; } @@ -51,13 +53,8 @@ namespace NadekoBot.Modules.CustomReactions .Do(async e => { string str = command.Value[rng.Next(0, command.Value.Count())]; - foreach (var key in commandFuncs.Keys) - { - foreach (Match m in key.Matches(str)) - { - str = str.Replace(m.Value, commandFuncs[key](e, m)); - } - } + commandFuncs.Keys.ForEach(key => str = key.Replace(str, m => commandFuncs[key](e, m))); + await e.Channel.SendMessage(str).ConfigureAwait(false); }); From c78f98bf19dd0d77490e9a90d94af21a478cd3c3 Mon Sep 17 00:00:00 2001 From: appelemac Date: Sat, 18 Jun 2016 13:40:22 +0200 Subject: [PATCH 17/19] pfft, nitpick --- NadekoBot/Modules/CustomReactions/CustomReactions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/NadekoBot/Modules/CustomReactions/CustomReactions.cs index f4ebceac..e735efc7 100644 --- a/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -21,7 +21,7 @@ namespace NadekoBot.Modules.CustomReactions { commandFuncs = new Dictionary> { - {new Regex(@"%rng:?(\d{0,9})-?(\d{0,9})%"), (e,m) => { + {new Regex(@"%rng(?:%|:(\d{0,9})-(\d{0,9})%)"), (e,m) => { int start, end; if (int.TryParse(m.Groups[1].Value, out start) && int.TryParse(m.Groups[2].Value, out end)) { return rng.Next(start, end).ToString(); From 32c14aecbcd49ded3af9574dfa2f458e2baed3af Mon Sep 17 00:00:00 2001 From: appelemac Date: Sat, 18 Jun 2016 13:52:32 +0200 Subject: [PATCH 18/19] Slight changes --- NadekoBot/Modules/CustomReactions/CustomReactions.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/NadekoBot/Modules/CustomReactions/CustomReactions.cs index e735efc7..a2e3973c 100644 --- a/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -21,12 +21,14 @@ namespace NadekoBot.Modules.CustomReactions { commandFuncs = new Dictionary> { - {new Regex(@"%rng(?:%|:(\d{0,9})-(\d{0,9})%)"), (e,m) => { + {new Regex(@"(?:%rng%|%rng:(\d{1,9})-(\d{1,9})%)"), (e,m) => { int start, end; - if (int.TryParse(m.Groups[1].Value, out start) && int.TryParse(m.Groups[2].Value, out end)) { + if (m.Groups[1].Success) + { + start = int.Parse(m.Groups[1].Value); + end = int.Parse(m.Groups[2].Value); return rng.Next(start, end).ToString(); - } - else return rng.Next().ToString(); + }else return rng.Next().ToString(); } }, {new Regex("%mention%"), (e,m) => NadekoBot.BotMention }, {new Regex("%user%"), (e,m) => e.User.Mention }, @@ -54,7 +56,7 @@ namespace NadekoBot.Modules.CustomReactions { string str = command.Value[rng.Next(0, command.Value.Count())]; commandFuncs.Keys.ForEach(key => str = key.Replace(str, m => commandFuncs[key](e, m))); - + await e.Channel.SendMessage(str).ConfigureAwait(false); }); From 12d3c2ad951f2652385aed469fd8be6a0f96870f Mon Sep 17 00:00:00 2001 From: appelemac Date: Sat, 18 Jun 2016 15:08:15 +0200 Subject: [PATCH 19/19] removed comments --- .../Conversations/Commands/RipCommand.cs | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/NadekoBot/Modules/Conversations/Commands/RipCommand.cs b/NadekoBot/Modules/Conversations/Commands/RipCommand.cs index a0075488..5557ade8 100644 --- a/NadekoBot/Modules/Conversations/Commands/RipCommand.cs +++ b/NadekoBot/Modules/Conversations/Commands/RipCommand.cs @@ -39,7 +39,8 @@ namespace NadekoBot.Modules.Conversations.Commands file = RipName(text, string.IsNullOrWhiteSpace(e.GetArg("year")) ? null : e.GetArg("year")); - } else + } + else { var avatar = await GetAvatar(usr.AvatarUrl); text = usr.Name; @@ -63,16 +64,13 @@ namespace NadekoBot.Modules.Conversations.Commands public Stream RipUser(string name, Image avatar, string year = null) { var bm = Resources.rip; - var offset = name.Length * 2; - var fontSize = 20; - if (name.Length > 10) - { - fontSize -= (name.Length - 10) / 2; - } - - //TODO use measure string + int width = 300; + var fontSize = width / name.Length -2; + if (fontSize > 20) fontSize = 20; var g = Graphics.FromImage(bm); - g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 220); + Font nameFont = new Font("Comic Sans MS", fontSize, FontStyle.Bold, GraphicsUnit.Pixel); + SizeF nameSize = g.MeasureString(name, nameFont); + g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, (bm.Width /2 - 8) - (nameSize.Width /2), 243 - nameSize.Height); g.DrawString((year ?? "?") + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 240); g.DrawImage(avatar, 80, 135); @@ -86,19 +84,14 @@ namespace NadekoBot.Modules.Conversations.Commands public Stream RipName(string name, string year = null) { var bm = Resources.rip; - + int width = 190; var offset = name.Length * 5; - - var fontSize = 20; - - if (name.Length > 10) - { - fontSize -= (name.Length - 10) / 2; - } - - //TODO use measure string + var fontSize = width / name.Length; + if (fontSize > 20) fontSize = 20; var g = Graphics.FromImage(bm); - g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 200); + Font nameFont = new Font("Comic Sans MS", fontSize, FontStyle.Bold, GraphicsUnit.Pixel); + SizeF nameSize = g.MeasureString(name, nameFont); + g.DrawString(name, nameFont, Brushes.Black, (bm.Width / 2) - (nameSize.Width / 2), 200); g.DrawString((year ?? "?") + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 235); g.Flush(); g.Dispose();