From ee1a7931ee7eace150a05d3d3ddaf357aa406dec Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 28 Oct 2016 12:36:02 +0200 Subject: [PATCH 01/21] commandlist update --- docs/Commands List.md | 20 ++++++++++---------- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/Commands List.md b/docs/Commands List.md index 2ed4d12d..2088905f 100644 --- a/docs/Commands List.md +++ b/docs/Commands List.md @@ -1,17 +1,17 @@ -######For more information and how to setup your own NadekoBot, go to: -######You can support the project on patreon: or paypal: `nadekodiscordbot@gmail.com` +For more information and how to setup your own NadekoBot, go to: +You can support the project on patreon: or paypal: `nadekodiscordbot@gmail.com` ##Table Of Contents +- [Help](#help) +- [Music](#music) - [CustomReactions](#customreactions) - [ClashOfClans](#clashofclans) -- [Searches](#searches) -- [Utility](#utility) -- [Permissions](#permissions) -- [Help](#help) -- [Administration](#administration) -- [NSFW](#nsfw) -- [Games](#games) - [Gambling](#gambling) -- [Music](#music) +- [Administration](#administration) +- [Games](#games) +- [Searches](#searches) +- [Permissions](#permissions) +- [Utility](#utility) +- [NSFW](#nsfw) ### Administration diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index a25ed111..a11e1d60 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -125,8 +125,8 @@ namespace NadekoBot.Modules.Help public Task Hgit(IUserMessage umsg) { var helpstr = new StringBuilder(); - helpstr.AppendLine(@"######For more information and how to setup your own NadekoBot, go to: -######You can support the project on patreon: or paypal: `nadekodiscordbot@gmail.com`"); + helpstr.AppendLine(@"For more information and how to setup your own NadekoBot, go to: +You can support the project on patreon: or paypal: `nadekodiscordbot@gmail.com`"); helpstr.AppendLine("##Table Of Contents"); helpstr.AppendLine(string.Join("\n", NadekoBot.CommandService.Modules.Select(m => $"- [{m.Name}](#{m.Name.ToLowerInvariant()})"))); helpstr.AppendLine(); From e8f6054c5a950a66fb3e24a9a768fde80e5505dd Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 28 Oct 2016 12:44:40 +0200 Subject: [PATCH 02/21] Fixes to v+t and blacklisting --- .../Modules/Administration/Commands/VoicePlusTextCommands.cs | 5 +++-- .../Modules/Permissions/Commands/BlacklistCommands.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index cd9b4bc2..1e4ca219 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -114,7 +114,7 @@ namespace NadekoBot.Modules.Administration var channel = (ITextChannel)msg.Channel; var guild = channel.Guild; - var botUser = guild.GetCurrentUser(); + var botUser = await guild.GetCurrentUserAsync().ConfigureAwait(false); if (!botUser.GuildPermissions.ManageRoles || !botUser.GuildPermissions.ManageChannels) { await channel.SendMessageAsync(":anger: `I require atleast manage roles and manage channels permissions to enable this feature (preffered Administration permission).`"); @@ -166,7 +166,8 @@ namespace NadekoBot.Modules.Administration { var channel = (ITextChannel)msg.Channel; var guild = channel.Guild; - if (!guild.GetCurrentUser().GuildPermissions.Administrator) + var botUser = await guild.GetCurrentUserAsync().ConfigureAwait(false); + if (!botUser.GuildPermissions.Administrator) { await channel.SendMessageAsync("`I need Administrator permission to do that.`").ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Permissions/Commands/BlacklistCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/BlacklistCommands.cs index e538e2a6..bbffabcf 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/BlacklistCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/BlacklistCommands.cs @@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Permissions } await uow.CompleteAsync().ConfigureAwait(false); } - if (action == AddRemove.Rem) + if (action == AddRemove.Add) { TriviaGame tg; switch (type) From bc4d37c0fa9073fdc7156530e01c7737592cb9c1 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 28 Oct 2016 13:14:16 +0200 Subject: [PATCH 03/21] Added >typelist and >typedel commands --- .../Games/Commands/SpeedTypingCommands.cs | 41 ++++++++++++++ .../Resources/CommandStrings.Designer.cs | 54 +++++++++++++++++++ src/NadekoBot/Resources/CommandStrings.resx | 18 +++++++ 3 files changed, 113 insertions(+) diff --git a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs index 466bc23a..801b4bab 100644 --- a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs @@ -218,6 +218,47 @@ namespace NadekoBot.Modules.Games await channel.SendMessageAsync("Added new article for typing game.").ConfigureAwait(false); } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task Typelist(IUserMessage imsg, int page = 1) + { + var channel = (ITextChannel)imsg.Channel; + + if (page < 1) + return; + + var articles = TypingArticles.Skip((page - 1) * 15).Take(15); + + if (!articles.Any()) + { + await channel.SendMessageAsync($"{imsg.Author.Mention} `No articles found on that page.`").ConfigureAwait(false); + return; + } + var i = (page - 1) * 15; + await channel.SendMessageAsync(String.Join("\n", articles.Select(a => $"`#{++i}` - {a.Text.TrimTo(50)}"))) + .ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [OwnerOnly] + public async Task Typedel(IUserMessage imsg, int index) + { + var channel = (ITextChannel)imsg.Channel; + + index -= 1; + if (index < 0 || index >= TypingArticles.Count) + return; + + var removed = TypingArticles[index]; + TypingArticles.RemoveAt(index); + + File.WriteAllText(typingArticlesPath, JsonConvert.SerializeObject(TypingArticles)); + + await channel.SendMessageAsync($"`Removed typing article:` #{index + 1} - {removed.Text.TrimTo(50)}") + .ConfigureAwait(false); + } } } } \ No newline at end of file diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index ef639f4c..542b2cb8 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -6701,6 +6701,60 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to typedel. + /// + public static string typedel_cmd { + get { + return ResourceManager.GetString("typedel_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Deletes a typing article given the ID.. + /// + public static string typedel_desc { + get { + return ResourceManager.GetString("typedel_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}typedel 3`. + /// + public static string typedel_usage { + get { + return ResourceManager.GetString("typedel_usage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to typelist. + /// + public static string typelist_cmd { + get { + return ResourceManager.GetString("typelist_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lists added typing articles with their IDs. 15 per page.. + /// + public static string typelist_desc { + get { + return ResourceManager.GetString("typelist_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}typelist` or `{0}typelist 3`. + /// + public static string typelist_usage { + get { + return ResourceManager.GetString("typelist_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to typestart. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 23fdb67f..10c72d72 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2574,4 +2574,22 @@ Lists all quotes on the server ordered alphabetically. 15 Per page. + + typedel + + + Deletes a typing article given the ID. + + + `{0}typedel 3` + + + typelist + + + Lists added typing articles with their IDs. 15 per page. + + + `{0}typelist` or `{0}typelist 3` + \ No newline at end of file From 2f82ae28216637a18d0495ae4be6ca355ffa6cb7 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 28 Oct 2016 13:31:21 +0200 Subject: [PATCH 04/21] .listservers command added --- src/NadekoBot/Modules/Utility/Utility.cs | 23 ++++++++++++++++ .../Resources/CommandStrings.Designer.cs | 27 +++++++++++++++++++ src/NadekoBot/Resources/CommandStrings.resx | 9 +++++++ 3 files changed, 59 insertions(+) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 8634c721..6933be88 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -177,6 +177,29 @@ namespace NadekoBot.Modules.Utility await msg.Channel.SendMessageAsync(result).ConfigureAwait(false); } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [OwnerOnly] + public async Task ListServers(IUserMessage imsg, int page = 1) + { + var channel = (ITextChannel)imsg.Channel; + + page -= 1; + + if (page < 0) + return; + + var guilds = NadekoBot.Client.GetGuilds().OrderBy(g => g.Name).Skip((page - 1) * 15).Take(15); + + if (!guilds.Any()) + { + await channel.SendMessageAsync("`No servers found on that page.`").ConfigureAwait(false); + return; + } + + await channel.SendMessageAsync(String.Join("\n", guilds.Select(g => $"`Name:` {g.Name} `Id:` {g.Id} `Members:` {g.GetUsers().Count} `OwnerId:`{g.OwnerId}"))).ConfigureAwait(false); + } + //[NadekoCommand, Usage, Description, Aliases] //[RequireContext(ContextType.Guild)] //public async Task TextToImage(IUserMessage msg, [Remainder] string arg) diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 542b2cb8..abb53dd0 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -3434,6 +3434,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to listservers. + /// + public static string listservers_cmd { + get { + return ResourceManager.GetString("listservers_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lists servers the bot is on with some basic info. 15 per page.. + /// + public static string listservers_desc { + get { + return ResourceManager.GetString("listservers_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}listservers 3`. + /// + public static string listservers_usage { + get { + return ResourceManager.GetString("listservers_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to liststreams ls. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 10c72d72..99877fdd 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2592,4 +2592,13 @@ `{0}typelist` or `{0}typelist 3` + + listservers + + + Lists servers the bot is on with some basic info. 15 per page. + + + `{0}listservers 3` + \ No newline at end of file From 7606a20c7f303cd428813c468c4d119c395a1296 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 28 Oct 2016 13:50:55 +0200 Subject: [PATCH 05/21] Fixed repeat message format --- .../Modules/Administration/Commands/MessageRepeater.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index 713fb7a2..44459e8f 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -159,7 +159,7 @@ namespace NadekoBot.Modules.Administration return old; }); - await channel.SendMessageAsync($"Repeating \"{rep.Repeater.Message}\" every {rep.Repeater.Interval} minutes").ConfigureAwait(false); + await channel.SendMessageAsync($"Repeating \"{rep.Repeater.Message}\" every {rep.Repeater.Interval.Days} days, {rep.Repeater.Interval.Hours} hours and {rep.Repeater.Interval.Minutes} minutes.").ConfigureAwait(false); } } } From c111f4c864b6780386b2bd6abe6c7f6510f8eba2 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 28 Oct 2016 14:08:02 +0200 Subject: [PATCH 06/21] !!n can now skip multiple songs, with consequences --- src/NadekoBot/Modules/Music/Music.cs | 11 ++++++++++- src/NadekoBot/Resources/CommandStrings.Designer.cs | 4 ++-- src/NadekoBot/Resources/CommandStrings.resx | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 70af561d..be775ab0 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -38,14 +38,23 @@ namespace NadekoBot.Modules.Music [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public Task Next(IUserMessage umsg) + public Task Next(IUserMessage umsg, int skipCount = 1) { var channel = (ITextChannel)umsg.Channel; + if (skipCount < 1) + return Task.CompletedTask; + MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return Task.CompletedTask; if (musicPlayer.PlaybackVoiceChannel == ((IGuildUser)umsg.Author).VoiceChannel) + { + while (--skipCount > 0) + { + musicPlayer.RemoveSongAt(0); + } musicPlayer.Next(); + } return Task.CompletedTask; } diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index abb53dd0..a0eec5a2 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -4119,7 +4119,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Goes to the next song in the queue. You have to be in the same voice channel as the bot.. + /// Looks up a localized string similar to Goes to the next song in the queue. You have to be in the same voice channel as the bot. You can skip multiple songs, but in that case songs will not be requeued if {0}rcs or {0}rpl is enabled.. /// public static string next_desc { get { @@ -4128,7 +4128,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `{0}n`. + /// Looks up a localized string similar to `{0}n` or `{0}n 5`. /// public static string next_usage { get { diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 99877fdd..3ef9cbb9 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -1426,10 +1426,10 @@ next n - Goes to the next song in the queue. You have to be in the same voice channel as the bot. + Goes to the next song in the queue. You have to be in the same voice channel as the bot. You can skip multiple songs, but in that case songs will not be requeued if {0}rcs or {0}rpl is enabled. - `{0}n` + `{0}n` or `{0}n 5` stop s From 371d21e785b0ba2127a1ebea445db40c8bf6f886 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 1 Nov 2016 19:14:56 +0100 Subject: [PATCH 07/21] Fixed blacklist not working properly for guild owners --- src/NadekoBot/Services/CommandHandler.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index a70eabe4..1e7f2d15 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -110,16 +110,17 @@ namespace NadekoBot.Services _log.Warn("I do not have permission to filter words in channel with id " + usrMsg.Channel.Id, ex); } } - - BlacklistItem blacklistedItem; - if ((blacklistedItem = Permissions.BlacklistCommands.BlacklistedItems.FirstOrDefault(bi => - (bi.Type == BlacklistItem.BlacklistType.Server && bi.ItemId == guild?.Id) || - (bi.Type == BlacklistItem.BlacklistType.Channel && bi.ItemId == msg.Channel.Id) || - (bi.Type == BlacklistItem.BlacklistType.User && bi.ItemId == usrMsg.Author.Id))) != null) - { - return; - } } + + BlacklistItem blacklistedItem; + if ((blacklistedItem = Permissions.BlacklistCommands.BlacklistedItems.FirstOrDefault(bi => + (bi.Type == BlacklistItem.BlacklistType.Server && bi.ItemId == guild?.Id) || + (bi.Type == BlacklistItem.BlacklistType.Channel && bi.ItemId == msg.Channel.Id) || + (bi.Type == BlacklistItem.BlacklistType.User && bi.ItemId == usrMsg.Author.Id))) != null) + { + return; + } + var throwaway = Task.Run(async () => { var sw = new Stopwatch(); From 83e0ccd226969d9a58b741a6cc6b94ba66bfaf6a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 3 Nov 2016 13:04:15 +0100 Subject: [PATCH 08/21] lolcommands have banrate percentage now --- src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs index 2108878f..3f0f61ab 100644 --- a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs @@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Searches { if (i % 2 == 0 && i != 0) sb.AppendLine(); - sb.Append($"`{i + 1}.` **{dataList[i]["name"]}** "); + sb.Append($"`{i + 1}.` **{dataList[i]["name"]}** {dataList[i]["general"]["banRate"]}% "); //sb.AppendLine($" ({dataList[i]["general"]["banRate"]}%)"); } From 1fe0c63f52a3d6d38ae8d1ebdaeafcbe63b3a43b Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 3 Nov 2016 13:05:04 +0100 Subject: [PATCH 09/21] Changed error message for ~lolban --- src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs index 3f0f61ab..c18eecdc 100644 --- a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs @@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Searches } catch (Exception) { - await channel.SendMessageAsync($":anger: Fail: Champion.gg didsabled ban data until next patch. Sorry for the inconvenience.").ConfigureAwait(false); + await channel.SendMessageAsync($":anger: `Something went wrong.`").ConfigureAwait(false); } } } From 17e6fc909b52c9742754dff1d9d16eddfb2e99cd Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 5 Nov 2016 18:03:23 +0100 Subject: [PATCH 10/21] Fixed [@]everyone and [@]here mentions in LogServer commnds --- src/NadekoBot/Modules/Administration/Commands/LogCommand.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 40ac1a5d..23aa8e7c 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -384,7 +384,7 @@ namespace NadekoBot.Modules.Administration πŸ‘€`{msg.Author.Username}`: {msg.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}"; if (msg.Attachments.Any()) str += $"{Environment.NewLine}`Attachements`: {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}"; - await logChannel.SendMessageAsync(str).ConfigureAwait(false); + await logChannel.SendMessageAsync(str.SanitizeMentions()).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } }); @@ -421,8 +421,8 @@ namespace NadekoBot.Modules.Administration { try { await logChannel.SendMessageAsync($@"πŸ•”`{prettyCurrentTime}` **Message** πŸ“ `#{channel.Name}` πŸ‘€`{before.Author.Username}` - `Old:` {before.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)} - `New:` {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } + `Old:` {before.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()} + `New:` {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } }); return Task.CompletedTask; From 5c20c88253b22cb21c05c5a509013657676effd6 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 5 Nov 2016 18:57:34 +0100 Subject: [PATCH 11/21] ~atf added --- src/NadekoBot/Modules/NSFW/NSFW.cs | 34 +++++++++++++++++++++ src/NadekoBot/Resources/CommandStrings.resx | 9 ++++++ 2 files changed, 43 insertions(+) diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index 93834390..bd3dac2f 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -41,6 +41,20 @@ namespace NadekoBot.Modules.NSFW await channel.SendMessageAsync(String.Join("\n\n", links)).ConfigureAwait(false); } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task ATFbooru(IUserMessage umsg, [Remainder] string tag = null) + { + var channel = (ITextChannel)umsg.Channel; + + tag = tag?.Trim() ?? ""; + var link = await GetATFbooruImageLink(tag).ConfigureAwait(false); + if (string.IsNullOrWhiteSpace(link)) + await channel.SendMessageAsync("Search yielded no results ;("); + else + await channel.SendMessageAsync(link).ConfigureAwait(false); + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Danbooru(IUserMessage umsg, [Remainder] string tag = null) @@ -255,5 +269,25 @@ namespace NadekoBot.Modules.NSFW return "Error, do you have too many tags?"; } } + + public static async Task GetATFbooruImageLink(string tag) + { + var rng = new NadekoRandom(); + + var link = $"https://atfbooru.ninja/posts?" + + $"limit=100"; + if (!string.IsNullOrWhiteSpace(tag)) + link += $"&tags={tag.Replace(" ", "+")}"; + using (var http = new HttpClient()) + { + var webpage = await http.GetStringAsync(link).ConfigureAwait(false); + var matches = Regex.Matches(webpage, "data-file-url=\"(?.*?)\""); + + if (matches.Count == 0) + return null; + return $"https://atfbooru.ninja" + + $"{matches[rng.Next(0, matches.Count)].Groups["id"].Value}"; + } + } } } diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 3ef9cbb9..a9d42d0d 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2115,6 +2115,15 @@ `{0}danbooru yuri+kissing` + + atfbooru atf + + + Shows a random hentai image from atfbooru with a given tag. Tag is optional but preferred. + + + `{0}atfbooru yuri+kissing` + gelbooru From a7fefead64fb6403c1d84dcfa277d0b2ce4e7cc2 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 5 Nov 2016 20:03:50 +0100 Subject: [PATCH 12/21] Custom reactions will no longer trigger if user/server is blacklisted or if there is a filtered word or invite in it. If custom reaction is triggered, no commands will be attempted to be triggered after it (if your CR has the same name as some command, only your CR will be ran) --- .../CustomReactions/CustomReactions.cs | 75 +++++++++---------- src/NadekoBot/Services/CommandHandler.cs | 12 +++ 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index d13b143a..2882eb11 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -19,6 +19,7 @@ namespace NadekoBot.Modules.CustomReactions { public static ConcurrentHashSet GlobalReactions { get; } = new ConcurrentHashSet(); public static ConcurrentDictionary> GuildReactions { get; } = new ConcurrentDictionary>(); + static CustomReactions() { using (var uow = DbHandler.UnitOfWork()) @@ -30,49 +31,43 @@ namespace NadekoBot.Modules.CustomReactions } public CustomReactions(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client) { - client.MessageReceived += (imsg) => + } + + public static async Task TryExecuteCustomReaction(IUserMessage umsg) + { + var channel = umsg.Channel as ITextChannel; + if (channel == null) + return false; + + var content = umsg.Content.Trim().ToLowerInvariant(); + ConcurrentHashSet reactions; + GuildReactions.TryGetValue(channel.Guild.Id, out reactions); + if (reactions != null && reactions.Any()) { - var umsg = imsg as IUserMessage; - if (umsg == null || imsg.Author.IsBot) - return Task.CompletedTask; - - var channel = umsg.Channel as ITextChannel; - if (channel == null) - return Task.CompletedTask; - - var t = Task.Run(async () => + var reaction = reactions.Where(cr => { + var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%"); + var trigger = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant(); + return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger); + }).Shuffle().FirstOrDefault(); + if (reaction != null) { - var content = umsg.Content.Trim().ToLowerInvariant(); - ConcurrentHashSet reactions; - GuildReactions.TryGetValue(channel.Guild.Id, out reactions); - if (reactions != null && reactions.Any()) - { - var reaction = reactions.Where(cr => { - var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%"); - var trigger = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant(); - return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger); - }).Shuffle().FirstOrDefault(); - if (reaction != null) - { - try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } - return; - } - } - var greaction = GlobalReactions.Where(cr => - { - var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%"); - var trigger = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant(); - return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger); - }).Shuffle().FirstOrDefault(); + try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } + return true; + } + } + var greaction = GlobalReactions.Where(cr => + { + var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%"); + var trigger = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant(); + return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger); + }).Shuffle().FirstOrDefault(); - if (greaction != null) - { - try { await channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } - return; - } - }); - return Task.CompletedTask; - }; + if (greaction != null) + { + try { await channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } + return true; + } + return false; } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 1e7f2d15..52d4ba4f 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -18,6 +18,7 @@ using static NadekoBot.Modules.Permissions.Permissions; using System.Collections.Concurrent; using NadekoBot.Modules.Help; using static NadekoBot.Modules.Administration.Administration; +using NadekoBot.Modules.CustomReactions; namespace NadekoBot.Services { @@ -121,6 +122,17 @@ namespace NadekoBot.Services return; } + try + { + // maybe this message is a custom reaction + var crExecuted = await CustomReactions.TryExecuteCustomReaction(usrMsg).ConfigureAwait(false); + + //if it was, don't execute the command + if (crExecuted) + return; + } + catch { } + var throwaway = Task.Run(async () => { var sw = new Stopwatch(); From 1408367cc2a986bc0d8b9e51ad6a1903fd27d003 Mon Sep 17 00:00:00 2001 From: ZirconiumHacker Date: Sat, 5 Nov 2016 18:20:31 -0400 Subject: [PATCH 13/21] Updated widget due to discord api changes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7bb0d57e..f1bef229 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![img](https://ci.appveyor.com/api/projects/status/gmu6b3ltc80hr3k9?svg=true) -[![Discord](https://discordapp.com/api/servers/117523346618318850/widget.png)](https://discord.gg/0ehQwTK2RBjAxzEY) +[![Discord](https://discordapp.com/api/guilds/117523346618318850/widget.png)](https://discord.gg/0ehQwTK2RBjAxzEY) [![Documentation Status](https://readthedocs.org/projects/nadekobot/badge/?version=latest)](http://nadekobot.readthedocs.io/en/1.0/?badge=latest) # NadekoBot From 8dfa7ee1c1f4d89007fbd4cdc5c1f5c4232483ac Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 6 Nov 2016 00:59:21 +0100 Subject: [PATCH 14/21] ~hentai changed, ~hentaibomb added (buffed ~hentai) --- src/NadekoBot/Modules/NSFW/NSFW.cs | 58 ++++++++++++++++--- .../Resources/CommandStrings.Designer.cs | 58 ++++++++++++++++++- src/NadekoBot/Resources/CommandStrings.resx | 17 ++++-- .../Services/Impl/GoogleApiService.cs | 4 ++ 4 files changed, 122 insertions(+), 15 deletions(-) diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index bd3dac2f..2ae6a96e 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -30,11 +30,51 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; - var links = await Task.WhenAll(GetGelbooruImageLink("rating%3Aexplicit+" + tag), GetDanbooruImageLink("rating%3Aexplicit+" + tag)).ConfigureAwait(false); + tag = "rating%3Aexplicit+" + tag; + + var rng = new NadekoRandom(); + Task provider = Task.FromResult(""); + switch (rng.Next(0,4)) + { + case 0: + provider = GetDanbooruImageLink(tag); + break; + case 1: + provider = GetGelbooruImageLink(tag); + break; + case 2: + provider = GetATFbooruImageLink(tag); + break; + case 3: + provider = GetKonachanImageLink(tag); + break; + default: + break; + } + var link = await provider.ConfigureAwait(false); + if (string.IsNullOrWhiteSpace(link)) + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); + else + await channel.SendMessageAsync(link).ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task HentaiBomb(IUserMessage umsg, [Remainder] string tag = null) + { + var channel = (ITextChannel)umsg.Channel; + + tag = tag?.Trim() ?? ""; + tag = "rating%3Aexplicit+" + tag; + + var links = await Task.WhenAll(GetGelbooruImageLink(tag), + GetDanbooruImageLink(tag), + GetKonachanImageLink(tag), + GetATFbooruImageLink(tag)).ConfigureAwait(false); if (links.All(l => l == null)) { - await channel.SendMessageAsync("`No results.`"); + await channel.SendMessageAsync("`No results.`").ConfigureAwait(false); return; } @@ -50,7 +90,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetATFbooruImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -64,7 +104,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetDanbooruImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -78,7 +118,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetKonachanImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -92,7 +132,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetGelbooruImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -106,7 +146,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetRule34ImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -120,7 +160,7 @@ namespace NadekoBot.Modules.NSFW tag = tag?.Trim() ?? ""; var link = await GetE621ImageLink(tag).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(link)) - await channel.SendMessageAsync("Search yielded no results ;("); + await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false); else await channel.SendMessageAsync(link).ConfigureAwait(false); } @@ -190,7 +230,7 @@ namespace NadekoBot.Modules.NSFW if (matches.Count == 0) return null; - return await NadekoBot.Google.ShortenUrl(matches[rng.Next(0, matches.Count)].Groups["ll"].Value).ConfigureAwait(false); + return matches[rng.Next(0, matches.Count)].Groups["ll"].Value; } } diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index a0eec5a2..b34b06f9 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -464,6 +464,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to atfbooru atf. + /// + public static string atfbooru_cmd { + get { + return ResourceManager.GetString("atfbooru_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows a random hentai image from atfbooru with a given tag. Tag is optional but preferred.. + /// + public static string atfbooru_desc { + get { + return ResourceManager.GetString("atfbooru_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}atfbooru yuri+kissing`. + /// + public static string atfbooru_usage { + get { + return ResourceManager.GetString("atfbooru_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to autoassignrole aar. /// @@ -2823,7 +2850,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Shows a 2 random images (from gelbooru and danbooru) with a given tag. Tag is optional but preferred. Only 1 tag allowed.. + /// Looks up a localized string similar to Shows a hentai image from a random website (gelbooru or danbooru or konachan or atfbooru) with a given tag. Tag is optional but preferred. Only 1 tag allowed.. /// public static string hentai_desc { get { @@ -2840,6 +2867,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to hentaibomb. + /// + public static string hentaibomb_cmd { + get { + return ResourceManager.GetString("hentaibomb_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows a total 4 images (from gelbooru, danbooru, konachan and atfbooru). Tag is optional but preferred.. + /// + public static string hentaibomb_desc { + get { + return ResourceManager.GetString("hentaibomb_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}hentaibomb yuri`. + /// + public static string hentaibomb_usage { + get { + return ResourceManager.GetString("hentaibomb_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to hgit. /// @@ -3147,7 +3201,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Shows a random hentai image from konachan with a given tag. Tag is optional but preferred. (multiple tags are appended with +). + /// Looks up a localized string similar to Shows a random hentai image from konachan with a given tag. Tag is optional but preferred.. /// public static string konachan_desc { get { diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index a9d42d0d..e414ffe5 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2101,7 +2101,7 @@ hentai - Shows a 2 random images (from gelbooru and danbooru) with a given tag. Tag is optional but preferred. Only 1 tag allowed. + Shows a hentai image from a random website (gelbooru or danbooru or konachan or atfbooru) with a given tag. Tag is optional but preferred. Only 1 tag allowed. `{0}hentai yuri` @@ -2115,7 +2115,7 @@ `{0}danbooru yuri+kissing` - + atfbooru atf @@ -2123,7 +2123,7 @@ `{0}atfbooru yuri+kissing` - + gelbooru @@ -2461,7 +2461,7 @@ konachan - Shows a random hentai image from konachan with a given tag. Tag is optional but preferred. (multiple tags are appended with +) + Shows a random hentai image from konachan with a given tag. Tag is optional but preferred. `{0}konachan yuri` @@ -2610,4 +2610,13 @@ `{0}listservers 3` + + hentaibomb + + + Shows a total 4 images (from gelbooru, danbooru, konachan and atfbooru). Tag is optional but preferred. + + + `{0}hentaibomb yuri` + \ No newline at end of file diff --git a/src/NadekoBot/Services/Impl/GoogleApiService.cs b/src/NadekoBot/Services/Impl/GoogleApiService.cs index 5d578dc1..860a379c 100644 --- a/src/NadekoBot/Services/Impl/GoogleApiService.cs +++ b/src/NadekoBot/Services/Impl/GoogleApiService.cs @@ -91,6 +91,10 @@ namespace NadekoBot.Services.Impl { if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); + + if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.GoogleApiKey)) + return url; + try { var response = await sh.Url.Insert(new Url { LongUrl = url }).ExecuteAsync(); From bffb9912647bbaaf8fd11ade41293df563b6b76a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 6 Nov 2016 01:02:38 +0100 Subject: [PATCH 15/21] .sb now requires kick+manage messages instead of ban --- src/NadekoBot/Modules/Administration/Administration.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 46176fcf..d7f72186 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -311,7 +311,8 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.BanMembers)] + [RequirePermission(GuildPermission.KickMembers)] + [RequirePermission(GuildPermission.ManageMessages)] public async Task Softban(IUserMessage umsg, IGuildUser user, [Remainder] string msg = null) { var channel = (ITextChannel)umsg.Channel; From 2248298bc9252b85b45b4d0c8ea70cbd2aa85cc2 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 6 Nov 2016 20:46:17 +0100 Subject: [PATCH 16/21] Names of the people who dm the bot now properly show up when .fwmsgs is enabled --- .../Modules/Administration/Commands/DMForwardCommands.cs | 2 +- src/NadekoBot/Modules/Utility/Utility.cs | 2 -- src/NadekoBot/project.json | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs b/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs index 9a872341..c755d34d 100644 --- a/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs @@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Administration { var firstOwnerChannel = ownerChannels.First(); if (firstOwnerChannel.Recipient.Id != msg.Author.Id) - try { await firstOwnerChannel.SendMessageAsync(msg.Content).ConfigureAwait(false); } catch { } + try { await firstOwnerChannel.SendMessageAsync(toSend).ConfigureAwait(false); } catch { } } } } diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 6933be88..fb4a95a9 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -169,8 +169,6 @@ namespace NadekoBot.Modules.Utility { var matches = emojiFinder.Matches(emojis); - - var result = string.Join("\n", matches.Cast() .Select(m => $"`Name:` {m.Groups["name"]} `Link:` http://discordapp.com/api/emojis/{m.Groups["id"]}.png")); diff --git a/src/NadekoBot/project.json b/src/NadekoBot/project.json index 5d021051..9ed621ff 100644 --- a/src/NadekoBot/project.json +++ b/src/NadekoBot/project.json @@ -7,7 +7,7 @@ "emitEntryPoint": true, "allowUnsafe": true, "compile": { - "exclude": [ "data" ] + "exclude": [ "data", "credentials.json", "credentials_example.json" ] }, "copyToOutput": { "include": [ "data" ], From 3611817e220d04b5492879e6f87f4003f169d5a1 Mon Sep 17 00:00:00 2001 From: fkndean Date: Sun, 6 Nov 2016 16:04:24 -0500 Subject: [PATCH 17/21] Add Minecraft Commands --- src/NadekoBot/Modules/Searches/Searches.cs | 89 ++++++++++++++++++- .../Resources/CommandStrings.Designer.cs | 54 +++++++++++ src/NadekoBot/Resources/CommandStrings.resx | 18 ++++ 3 files changed, 159 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 9a370f80..5d700d6c 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Linq; +using System.Text; using System.Net.Http; using NadekoBot.Services; using System.Threading.Tasks; @@ -225,7 +226,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 throw new KeyNotFoundException("Cannot find a card by that name"); foreach (var item in items.Where(item => item.HasValues && item["img"] != null).Take(4)) { - using (var sr =await http.GetStreamAsync(item["img"].ToString())) + using (var sr = await http.GetStreamAsync(item["img"].ToString())) { var imgStream = new MemoryStream(); await sr.CopyToAsync(imgStream); @@ -271,7 +272,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 try { var items = JObject.Parse(res); - var sb = new System.Text.StringBuilder(); + var sb = new StringBuilder(); sb.AppendLine($"`Term:` {items["list"][0]["word"].ToString()}"); sb.AppendLine($"`Definition:` {items["list"][0]["definition"].ToString()}"); sb.Append($"`Link:` <{await _google.ShortenUrl(items["list"][0]["permalink"].ToString()).ConfigureAwait(false)}>"); @@ -464,6 +465,90 @@ $@"🌍 **Weather for** 【{obj["target"]}】 } } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task MCPing(IUserMessage umsg, [Remainder] string query = null) + { + var channel = (ITextChannel)umsg.Channel; + var arg = query; + if (string.IsNullOrWhiteSpace(arg)) + { + await channel.SendMessageAsync("πŸ’’ Please enter a `ip:port`.").ConfigureAwait(false); + return; + } + await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false); + using (var http = new HttpClient()) + { + http.DefaultRequestHeaders.Clear(); + string ip = arg.Split(':')[0]; + string port = arg.Split(':')[1]; + var res = await http.GetStringAsync($"https://api.minetools.eu/ping/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false); + try + { + var items = JObject.Parse(res); + var sb = new StringBuilder(); + int ping = (int)Math.Ceiling(Double.Parse(items["latency"].ToString())); + sb.AppendLine($"`Server:` {arg}"); + sb.AppendLine($"`Version:` {items["version"]["name"].ToString()} / Protocol {items["version"]["protocol"].ToString()}"); + sb.AppendLine($"`Description:` {items["description"].ToString()}"); + sb.AppendLine($"`Online Players:` {items["players"]["online"].ToString()}/{items["players"]["max"].ToString()}"); + sb.Append($"`Latency:` {ping}"); + await channel.SendMessageAsync(sb.ToString()); + } + catch + { + await channel.SendMessageAsync($"πŸ’’ Failed finding `{arg}`.").ConfigureAwait(false); + } + } + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task MCQ(IUserMessage umsg, [Remainder] string query = null) + { + var channel = (ITextChannel)umsg.Channel; + var arg = query; + if (string.IsNullOrWhiteSpace(arg)) + { + await channel.SendMessageAsync("πŸ’’ Please enter a `ip:port`.").ConfigureAwait(false); + return; + } + await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false); + using (var http = new HttpClient()) + { + http.DefaultRequestHeaders.Clear(); + try + { + string ip = arg.Split(':')[0]; + string port = arg.Split(':')[1]; + var res = await http.GetStringAsync($"https://api.minetools.eu/query/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false); + var items = JObject.Parse(res); + var sb = new StringBuilder(); + sb.AppendLine($"`Server:` {arg.ToString()} γ€˜Status: {items["status"]}γ€™"); + sb.AppendLine($"`Player List:`"); + for (int i = 0; i < items["Playerlist"].Count(); i++) + { + if (i == 5) + { + break; + } + else + { + sb.AppendLine($"γ€”{i + 1}. {items["Playerlist"][i]}〕"); + } + } + sb.AppendLine($"`Online Players:` {items["Players"]} / {items["MaxPlayers"]}"); + sb.AppendLine($"`Plugins:` {items["Plugins"]}"); + sb.Append($"`Version:` {items["Version"]}"); + await channel.SendMessageAsync(sb.ToString()); + } + catch + { + await channel.SendMessageAsync($"πŸ’’ Failed finding server `{arg}`.").ConfigureAwait(false); + } + } + } + public static async Task ValidateQuery(ITextChannel ch, string query) { if (!string.IsNullOrEmpty(query.Trim())) return true; diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index b34b06f9..70df73b6 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -3937,6 +3937,60 @@ namespace NadekoBot.Resources { return ResourceManager.GetString("memegen_desc", resourceCulture); } } + + /// + /// Looks up a localized string similar to minecraftping mcping. + /// + public static string mcping_cmd { + get { + return ResourceManager.GetString("mcping_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Pings a minecraft server.. + /// + public static string mcping_desc { + get { + return ResourceManager.GetString("mcping_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}mcping 127.0.0.1:1337`. + /// + public static string mcping_usage { + get { + return ResourceManager.GetString("mcping_usage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to minecraftquery mcq. + /// + public static string mcq_cmd { + get { + return ResourceManager.GetString("mcq_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Finds information about a minecraft server.. + /// + public static string mcq_desc { + get { + return ResourceManager.GetString("mcq_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}mcq server:ip`. + /// + public static string mcq_usage { + get { + return ResourceManager.GetString("mcq_usage", resourceCulture); + } + } /// /// Looks up a localized string similar to `{0}memegen biw "gets iced coffee" "in the winter"`. diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index e414ffe5..54b18ef6 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2619,4 +2619,22 @@ `{0}hentaibomb yuri` + + minecraftping mcping + + + Pings a minecraft server. + + + `{0}mcping 127.0.0.1:25565` + + + minecraftquery mcq + + + Finds information about a minecraft server. + + + `{0}mcq server:ip` + \ No newline at end of file From ac06c9b48b8bc795ff4a4da50b1115b7feca05e5 Mon Sep 17 00:00:00 2001 From: fkndean Date: Sun, 6 Nov 2016 17:29:32 -0500 Subject: [PATCH 18/21] MCQ minor consistency fix --- src/NadekoBot/Modules/Searches/Searches.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 5d700d6c..4ee6f93b 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -524,18 +524,12 @@ $@"🌍 **Weather for** 【{obj["target"]}】 var res = await http.GetStringAsync($"https://api.minetools.eu/query/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false); var items = JObject.Parse(res); var sb = new StringBuilder(); + int i = 0; sb.AppendLine($"`Server:` {arg.ToString()} γ€˜Status: {items["status"]}γ€™"); - sb.AppendLine($"`Player List:`"); - for (int i = 0; i < items["Playerlist"].Count(); i++) + sb.AppendLine($"`Player List (First 5):`"); + foreach (var item in items["Playerlist"].Take(5)) { - if (i == 5) - { - break; - } - else - { - sb.AppendLine($"γ€”{i + 1}. {items["Playerlist"][i]}〕"); - } + sb.AppendLine($"γ€”:rosette: {item}〕"); } sb.AppendLine($"`Online Players:` {items["Players"]} / {items["MaxPlayers"]}"); sb.AppendLine($"`Plugins:` {items["Plugins"]}"); From 56eb10cf8175a9328460f5a64a8c481955c46f6a Mon Sep 17 00:00:00 2001 From: fkndean Date: Sun, 6 Nov 2016 17:30:47 -0500 Subject: [PATCH 19/21] bah :camel: --- src/NadekoBot/Modules/Searches/Searches.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 4ee6f93b..f4e0ef2c 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -524,7 +524,6 @@ $@"🌍 **Weather for** 【{obj["target"]}】 var res = await http.GetStringAsync($"https://api.minetools.eu/query/{Uri.EscapeUriString(ip)}/{Uri.EscapeUriString(port)}").ConfigureAwait(false); var items = JObject.Parse(res); var sb = new StringBuilder(); - int i = 0; sb.AppendLine($"`Server:` {arg.ToString()} γ€˜Status: {items["status"]}γ€™"); sb.AppendLine($"`Player List (First 5):`"); foreach (var item in items["Playerlist"].Take(5)) From c06b1ae33ca1a8516103c11a390c714f68b20401 Mon Sep 17 00:00:00 2001 From: fkndean Date: Sun, 6 Nov 2016 17:58:04 -0500 Subject: [PATCH 20/21] Wikia Search --- src/NadekoBot/Modules/Searches/Searches.cs | 35 +++++++++++++++++++ .../Resources/CommandStrings.Designer.cs | 27 ++++++++++++++ src/NadekoBot/Resources/CommandStrings.resx | 9 +++++ 3 files changed, 71 insertions(+) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index f4e0ef2c..aee7f422 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -464,6 +464,41 @@ $@"🌍 **Weather for** 【{obj["target"]}】 return matches[rng.Next(0, matches.Count)].Groups["url"].Value; } } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task Wikia(IUserMessage umsg, string targ, [Remainder] string query = null) + { + var channel = (ITextChannel)umsg.Channel; + var arg = query; + if (string.IsNullOrWhiteSpace(arg)) + { + await channel.SendMessageAsync("πŸ’’ Please enter `target query`.").ConfigureAwait(false); + return; + } + await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false); + using (var http = new HttpClient()) + { + http.DefaultRequestHeaders.Clear(); + string target = targ; + string search = arg; + try + { + var res = await http.GetStringAsync($"http://www.{Uri.EscapeUriString(target)}.wikia.com/api/v1/Search/List?query={Uri.EscapeUriString(search)}&limit=25&minArticleQuality=10&batch=1&namespaces=0%2C14").ConfigureAwait(false); + var items = JObject.Parse(res); + var sb = new StringBuilder(); + sb.AppendLine($"`Found:` {items["items"][0]["title"].ToString()}"); + sb.AppendLine($"`Total Found:` {items["total"].ToString()}"); + sb.AppendLine($"`Batch:` {items["currentBatch"].ToString()}/{items["batches"].ToString()}"); + sb.Append($"`URL:` <{await _google.ShortenUrl(items["items"][0]["url"].ToString()).ConfigureAwait(false)}> / `Quality`: {items["items"][0]["quality"].ToString()}"); + await channel.SendMessageAsync(sb.ToString()); + } + catch + { + await channel.SendMessageAsync($"πŸ’’ Failed finding `{arg}`.").ConfigureAwait(false); + } + } + } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 70df73b6..15c84b56 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -7510,6 +7510,33 @@ namespace NadekoBot.Resources { return ResourceManager.GetString("wiki_usage", resourceCulture); } } + + /// + /// Looks up a localized string similar to wikia. + /// + public static string wikia_cmd { + get { + return ResourceManager.GetString("wikia_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Gives you back a wikia link. + /// + public static string wikia_desc { + get { + return ResourceManager.GetString("wikia_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}wikia target query`. + /// + public static string wikia_usage { + get { + return ResourceManager.GetString("wikia_usage", resourceCulture); + } + } /// /// Looks up a localized string similar to wowjoke. diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 54b18ef6..98faafae 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2637,4 +2637,13 @@ `{0}mcq server:ip` + + wikia + + + Gives you back a wikia link + + + `{0}wikia target query` + \ No newline at end of file From f9fb9d2f7631344c4ee2b0c0206806750c1d7435 Mon Sep 17 00:00:00 2001 From: fkndean Date: Mon, 7 Nov 2016 07:29:36 -0500 Subject: [PATCH 21/21] also check targ for null or whitespace --- src/NadekoBot/Modules/Searches/Searches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index aee7f422..76edb462 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -471,7 +471,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 { var channel = (ITextChannel)umsg.Channel; var arg = query; - if (string.IsNullOrWhiteSpace(arg)) + if (string.IsNullOrWhiteSpace(targ) || string.IsNullOrWhiteSpace(arg)) { await channel.SendMessageAsync("πŸ’’ Please enter `target query`.").ConfigureAwait(false); return;