diff --git a/Pootis-Bot/Modules/Fun/GiphySearch.cs b/Pootis-Bot/Modules/Fun/GiphySearch.cs index b6d3d363..f0e0bdf1 100644 --- a/Pootis-Bot/Modules/Fun/GiphySearch.cs +++ b/Pootis-Bot/Modules/Fun/GiphySearch.cs @@ -1,7 +1,9 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; +using Discord.Rest; using Pootis_Bot.Core; +using Pootis_Bot.Preconditions; using Pootis_Bot.Services.Fun; using Pootis_Bot.Structs; @@ -17,9 +19,10 @@ public class GiphySearch : ModuleBase [Command("giphy")] [Summary("Searches Giphy")] [Alias("gy")] + [Cooldown(5)] [RequireBotPermission(GuildPermission.EmbedLinks)] [RequireBotPermission(GuildPermission.AttachFiles)] - public async Task CmdGiphySearch([Remainder] string search = "") + public async Task Giphy([Remainder] string search = "") { if (string.IsNullOrWhiteSpace(Config.bot.Apis.ApiGiphyKey)) { @@ -33,12 +36,18 @@ public async Task CmdGiphySearch([Remainder] string search = "") return; } + EmbedBuilder embed = new EmbedBuilder(); + embed.WithTitle($"Giphy Search '{search}'"); + embed.WithDescription("Searching Giphy..."); + embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); + embed.WithCurrentTimestamp(); + embed.WithColor(FunCmdsConfig.giphyColor); + + RestUserMessage message = await Context.Channel.SendMessageAsync("", false, embed.Build()); + GiphySearchResult results = GiphyService.Search(search); if (!results.IsSuccessful) { - //This should never happen, since we check it at the start! - if (results.ErrorReason == ErrorReason.NoApiKey) - return; if (results.ErrorReason == ErrorReason.Error) { await Context.Channel.SendMessageAsync( @@ -47,15 +56,11 @@ await Context.Channel.SendMessageAsync( } } - EmbedBuilder embed = new EmbedBuilder(); - embed.WithTitle($"Giphy Search '{Global.Title(results.Data.GifTitle)}'"); embed.WithDescription($"**By**: {results.Data.GifAuthor}\n**URL**: {results.Data.GifLink}"); embed.WithImageUrl(results.Data.GifUrl); - embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); embed.WithCurrentTimestamp(); - embed.WithColor(FunCmdsConfig.giphyColor); - await Context.Channel.SendMessageAsync("", false, embed.Build()); + await message.ModifyAsync(x => { x.Embed = embed.Build(); }); } } } \ No newline at end of file diff --git a/Pootis-Bot/Modules/Fun/GoogleSearch.cs b/Pootis-Bot/Modules/Fun/GoogleSearch.cs index ddd31808..df0d180d 100644 --- a/Pootis-Bot/Modules/Fun/GoogleSearch.cs +++ b/Pootis-Bot/Modules/Fun/GoogleSearch.cs @@ -2,8 +2,11 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; +using Discord.Rest; +using Discord.WebSocket; using Google.Apis.Customsearch.v1.Data; using Pootis_Bot.Core; +using Pootis_Bot.Preconditions; using Pootis_Bot.Services.Google; namespace Pootis_Bot.Modules.Fun @@ -18,6 +21,7 @@ public class GoogleSearch : ModuleBase [Command("google")] [Summary("Searches Google")] [Alias("g")] + [Cooldown(5)] [RequireBotPermission(GuildPermission.EmbedLinks)] public async Task Google([Remainder] string search = "") { @@ -34,12 +38,13 @@ public async Task Google([Remainder] string search = "") return; } - await Context.Channel.SendMessageAsync("", false, GSearch(search)); + await GSearch(search, Context.Channel); } [Command("google")] [Summary("Searches Google")] [Alias("g")] + [Cooldown(5)] [RequireBotPermission(GuildPermission.EmbedLinks)] public async Task Google(int maxSearchResults = 10, [Remainder] string search = "") { @@ -63,11 +68,20 @@ await Context.Channel.SendMessageAsync( return; } - await Context.Channel.SendMessageAsync("", false, GSearch(search, maxSearchResults)); + await GSearch(search, Context.Channel, maxSearchResults); } - private Embed GSearch(string search, int maxResults = 10) + private async Task GSearch(string search, ISocketMessageChannel channel, int maxResults = 10) { + EmbedBuilder embed = new EmbedBuilder(); + embed.WithTitle($"Google Search '{search}'"); + embed.WithDescription("Searching Google..."); + embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); + embed.WithColor(FunCmdsConfig.googleColor); + embed.WithCurrentTimestamp(); + + RestUserMessage message = await channel.SendMessageAsync("", false, embed.Build()); + Search searchListResponse = GoogleService.Search(search, GetType().ToString()); StringBuilder description = new StringBuilder(); @@ -77,26 +91,22 @@ private Embed GSearch(string search, int maxResults = 10) { if (currentResult == maxResults) continue; - string message = $"**[{result.Title}]({result.Link})**\n{result.Snippet}\n\n"; + string link = $"**[{result.Title}]({result.Link})**\n{result.Snippet}\n\n"; if (description.Length >= 2048) continue; - if (description.Length + message.Length >= 2048) + if (description.Length + link.Length >= 2048) continue; - description.Append(message); + description.Append(link); currentResult += 1; } - EmbedBuilder embed = new EmbedBuilder(); - embed.WithTitle($"Google Search '{search}'"); embed.WithDescription(description.ToString()); - embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); - embed.WithColor(FunCmdsConfig.googleColor); embed.WithCurrentTimestamp(); - return embed.Build(); + await message.ModifyAsync(x => { x.Embed = embed.Build(); }); } } } \ No newline at end of file diff --git a/Pootis-Bot/Modules/Fun/WikipediaSearch.cs b/Pootis-Bot/Modules/Fun/WikipediaSearch.cs index 673c1158..4a244613 100644 --- a/Pootis-Bot/Modules/Fun/WikipediaSearch.cs +++ b/Pootis-Bot/Modules/Fun/WikipediaSearch.cs @@ -3,6 +3,9 @@ using CreepysinStudios.WikiDotNet; using Discord; using Discord.Commands; +using Discord.Rest; +using Discord.WebSocket; +using Pootis_Bot.Preconditions; namespace Pootis_Bot.Modules.Fun { @@ -13,13 +16,14 @@ public class WikipediaSearch : ModuleBase // Description - Wikipedia search // Contributors - Creepysin, - //This use a library called Wiki.Net + //This uses a library called Wiki.Net //It was developed by my good friend EternalClickbait and partially by me(Creepysin). //You can get it here: https://github.com/Creepysin-Studios/Wiki.Net [Command("wiki")] [Alias("wikipedia")] [Summary("Searches Wikipedia")] + [Cooldown(5)] public async Task Wikipedia([Remainder] string search = "") { if (string.IsNullOrWhiteSpace(search)) @@ -28,12 +32,13 @@ public async Task Wikipedia([Remainder] string search = "") return; } - await Context.Channel.SendMessageAsync("", false, WikiSearch(search)); + await WikiSearch(search, Context.Channel); } [Command("wiki")] [Alias("wikipedia")] [Summary("Searches Wikipedia")] + [Cooldown(5)] public async Task Wikipedia(int maxSearchResults = 15, [Remainder] string search = "") { if (string.IsNullOrWhiteSpace(search)) @@ -49,16 +54,21 @@ await Context.Channel.SendMessageAsync( return; } - await Context.Channel.SendMessageAsync("", false, WikiSearch(search, maxSearchResults)); + await WikiSearch(search, Context.Channel, maxSearchResults); } - private Embed WikiSearch(string search, int maxSearch = 10) + private async Task WikiSearch(string search, ISocketMessageChannel channel, int maxSearch = 10) { EmbedBuilder embed = new EmbedBuilder(); StringBuilder sb = new StringBuilder(); embed.WithTitle($"Wikipedia Search '{search}'"); embed.WithColor(FunCmdsConfig.wikipediaSearchColor); + embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); + embed.WithCurrentTimestamp(); + embed.WithDescription("Searching Wikipedia..."); + + RestUserMessage message = await channel.SendMessageAsync("", false, embed.Build()); WikiSearchResponse response = WikiSearcher.Search(search, new WikiSearchSettings { @@ -67,7 +77,7 @@ private Embed WikiSearch(string search, int maxSearch = 10) foreach (WikiSearchResult result in response.Query.SearchResults) { - string message = + string link = $"**[{result.Title}]({result.ConstantUrl})** (Words: {result.WordCount})\n{result.Preview}\n\n"; //There is a character limit of 2048, so lets make sure we don't hit that @@ -76,19 +86,18 @@ private Embed WikiSearch(string search, int maxSearch = 10) continue; } - if (sb.Length + message.Length >= 2048) + if (sb.Length + link.Length >= 2048) { continue; } - sb.Append(message); + sb.Append(link); } embed.WithDescription(sb.ToString()); - embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); embed.WithCurrentTimestamp(); - return embed.Build(); + await message.ModifyAsync(x => { x.Embed = embed.Build(); }); } } } diff --git a/Pootis-Bot/Modules/Fun/YoutubeSearch.cs b/Pootis-Bot/Modules/Fun/YoutubeSearch.cs index 6d7be503..cb60bcd3 100644 --- a/Pootis-Bot/Modules/Fun/YoutubeSearch.cs +++ b/Pootis-Bot/Modules/Fun/YoutubeSearch.cs @@ -2,8 +2,11 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; +using Discord.Rest; +using Discord.WebSocket; using Google.Apis.YouTube.v3.Data; using Pootis_Bot.Core; +using Pootis_Bot.Preconditions; using Pootis_Bot.Services.Audio; using Pootis_Bot.Services.Google; using SearchResult = Google.Apis.YouTube.v3.Data.SearchResult; @@ -20,6 +23,7 @@ public class YoutubeSearch : ModuleBase [Command("youtube")] [Summary("Searches Youtube")] [Alias("yt")] + [Cooldown(5)] [RequireBotPermission(GuildPermission.EmbedLinks)] public async Task Youtube([Remainder] string search = "") { @@ -35,12 +39,15 @@ public async Task Youtube([Remainder] string search = "") return; } - await Context.Channel.SendMessageAsync("", false, YtSearch(search)); + await YtSearch(search, Context.Channel); + + //await Context.Channel.SendMessageAsync("", false, YtSearch(search)); } [Command("youtube")] [Summary("Searches Youtube")] [Alias("yt")] + [Cooldown(5)] [RequireBotPermission(GuildPermission.EmbedLinks)] public async Task Youtube(int maxSearchResults = 6, [Remainder] string search = "") { @@ -63,11 +70,20 @@ await Context.Channel.SendMessageAsync( return; } - await Context.Channel.SendMessageAsync("", false, YtSearch(search, maxSearchResults)); + await YtSearch(search, Context.Channel, maxSearchResults); } - private Embed YtSearch(string search, int maxSearch = 6) + private async Task YtSearch(string search, ISocketMessageChannel channel, int maxSearch = 6) { + EmbedBuilder embed = new EmbedBuilder(); + embed.WithTitle($"YouTube Search '{search}'"); + embed.WithDescription("Searching YouTube..."); + embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); + embed.WithCurrentTimestamp(); + embed.WithColor(FunCmdsConfig.youtubeColor); + + RestUserMessage message = await channel.SendMessageAsync("", false, embed.Build()); + //Search Youtube SearchListResponse searchListResponse = YoutubeService.Search(search, GetType().ToString(), maxSearch); @@ -92,14 +108,10 @@ private Embed YtSearch(string search, int maxSearch = 6) } } - EmbedBuilder embed = new EmbedBuilder(); - embed.WithTitle($"YouTube Search '{search}'"); embed.WithDescription($"**Videos**\n{videos}\n\n**Channels**\n{channels}"); - embed.WithFooter($"Search by {Context.User}", Context.User.GetAvatarUrl()); embed.WithCurrentTimestamp(); - embed.WithColor(FunCmdsConfig.youtubeColor); - return embed.Build(); + await message.ModifyAsync(x => { x.Embed = embed.Build(); }); } } } \ No newline at end of file