From 6c534f4233296d6e206c0ef148e37ef6c500cdd2 Mon Sep 17 00:00:00 2001 From: fkndean Date: Tue, 29 Nov 2016 08:47:06 -0500 Subject: [PATCH 1/4] Initial commit for rich embed change for message output. Started on `.stats` command. --- src/NadekoBot/Modules/Utility/Utility.cs | 26 +++++++++++- src/NadekoBot/Services/Impl/StatsService.cs | 46 +++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 3e191577..988fdcb3 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -157,8 +157,32 @@ namespace NadekoBot.Modules.Utility public async Task Stats(IUserMessage umsg) { var channel = umsg.Channel; + var desc = await NadekoBot.Stats.Print(); + var servers = await NadekoBot.Stats.PrintServers(); + var version = await NadekoBot.Stats.PrintVersion(); + var uptime = await NadekoBot.Stats.PrintUptime(); + var statistics = await NadekoBot.Stats.PrintStatistics(); + var botid = await NadekoBot.Stats.PrintBotID(); + var owners = await NadekoBot.Stats.PrintOwners(); + DateTimeOffset date = date.ToLocalTime(); - await channel.SendMessageAsync(await NadekoBot.Stats.Print()); + var embed = new EmbedBuilder() + .WithAuthor(eau => eau.WithName("Author: [Kwoth#2560] | Library: [Discord.NET]") + .WithIconUrl("http://i.imgur.com/y0n6Lu4.jpg")) + .WithUrl("https://github.com/kwoth/nadekobot") + .WithTitle("Bot Information") + .WithDescription(servers) + .AddField(fb => fb.WithIndex(1).WithName("**Bot Version**").WithValue(version).WithIsInline(true)) + .AddField(fb => fb.WithIndex(1).WithName("**Bot ID**").WithValue(botid).WithIsInline(true)) + .AddField(fb => fb.WithIndex(1).WithName("**Uptime**").WithValue(uptime).WithIsInline(true)) + .AddField(fb => fb.WithIndex(1).WithName("**Statistics**").WithValue(statistics).WithIsInline(true)) + .WithColor(0xee42f4) + .AddField(fb => fb.WithIndex(1).WithName("**Owners**").WithValue(owners).WithIsInline(false)) + .WithThumbnail(tn => tn.Url = "https://avatars.githubusercontent.com/u/2537696?v=3") + .WithImage(tn => tn.Url = "https://lh3.googleusercontent.com/-TDLUR4j7q20/V8u0E7CDUyI/AAAAAAAAAbQ/1pmQ256Cbdg324gU_ecvqdPMsmIBST-gwCJoC/w895-h504/rol%2B1-A.png") + .WithFooter(fb => fb.WithIconUrl("https://media0.giphy.com/media/JIu5iDNbCeLsI/200_s.gif").WithText("Nadeko")) + .WithTimestamp(DateTime.Now); + await channel.SendMessageAsync("-", embed: embed); } private Regex emojiFinder { get; } = new Regex(@"<:(?.+?):(?\d*)>", RegexOptions.Compiled); diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 1c1cb367..245e717f 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -61,15 +61,55 @@ namespace NadekoBot.Services.Impl public async Task Print() { var curUser = await client.GetCurrentUserAsync(); - return $@"```css + return $@" Author: [Kwoth#2560] | Library: [Discord.Net] Bot Version: [{BotVersion}] Bot ID: {curUser.Id} Owner ID(s): {string.Join(", ", NadekoBot.Credentials.OwnerIds)} Uptime: {GetUptimeString()} Servers: {client.GetGuilds().Count} | TextChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is ITextChannel)).Count()} | VoiceChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is IVoiceChannel)).Count()} -Commands Ran this session: {commandsRan} -Messages: {messageCounter} [{messageCounter / (double)GetUptime().TotalSeconds:F2}/sec] Heap: [{Heap} MB]```"; +`Commands Ran this session: {commandsRan}` +`Messages: {messageCounter} ({messageCounter / (double)GetUptime().TotalSeconds:F2}/sec)` `Heap: {Heap} MB`"; + } + + public async Task PrintVersion() + { + var curUser = await client.GetCurrentUserAsync(); + return $@"{BotVersion}"; + } + + public async Task PrintOwners() + { + var curUser = await client.GetCurrentUserAsync(); + return $@"ID(s): {string.Join(", ", NadekoBot.Credentials.OwnerIds)}"; + } + + public async Task PrintUptime() + { + var curUser = await client.GetCurrentUserAsync(); + return $@"{GetUptimeString()}"; + } + + public async Task PrintBotID() + { + var curUser = await client.GetCurrentUserAsync(); + return $@"{curUser.Id}"; + } + + public async Task PrintServers() + { + var curUser = await client.GetCurrentUserAsync(); + return $@"Servers: {client.GetGuilds().Count} | TextChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is ITextChannel)).Count()} | VoiceChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is IVoiceChannel)).Count()}"; + } + + public async Task PrintStatistics() + { + var curUser = await client.GetCurrentUserAsync(); + return $@"Commands Ran this session: {commandsRan} + +Messages: {messageCounter} ({messageCounter / (double)GetUptime().TotalSeconds:F2}/sec) + +Heap: {Heap} MB"; } public Task Reset() From da21308345bfd0bfd4f56e72d91441166c27ac4c Mon Sep 17 00:00:00 2001 From: fkndean Date: Tue, 29 Nov 2016 09:01:06 -0500 Subject: [PATCH 2/4] Fix to match Kwoth's d.net changes. --- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 988fdcb3..49f54e4b 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -182,7 +182,7 @@ namespace NadekoBot.Modules.Utility .WithImage(tn => tn.Url = "https://lh3.googleusercontent.com/-TDLUR4j7q20/V8u0E7CDUyI/AAAAAAAAAbQ/1pmQ256Cbdg324gU_ecvqdPMsmIBST-gwCJoC/w895-h504/rol%2B1-A.png") .WithFooter(fb => fb.WithIconUrl("https://media0.giphy.com/media/JIu5iDNbCeLsI/200_s.gif").WithText("Nadeko")) .WithTimestamp(DateTime.Now); - await channel.SendMessageAsync("-", embed: embed); + await channel.SendMessageAsync("-", embed: embed.Build()); } private Regex emojiFinder { get; } = new Regex(@"<:(?.+?):(?\d*)>", RegexOptions.Compiled); From c015b519014b683a58b39ce503335ebb22da7ec5 Mon Sep 17 00:00:00 2001 From: fkndean Date: Fri, 2 Dec 2016 20:25:42 -0500 Subject: [PATCH 3/4] add mashape yoda --- src/NadekoBot/Modules/Searches/Searches.cs | 45 +++++++++++++++++++ .../Resources/CommandStrings.Designer.cs | 27 +++++++++++ src/NadekoBot/Resources/CommandStrings.resx | 9 ++++ 3 files changed, 81 insertions(+) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 3154e9aa..ed45e0eb 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -313,6 +313,51 @@ namespace NadekoBot.Modules.Searches } } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task Yodify(IUserMessage umsg, [Remainder] string query = null) + { + var channel = (ITextChannel)umsg.Channel; + + if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey)) + { + await channel.SendMessageAsync("💢 `Bot owner didn't specify MashapeApiKey. You can't use this functionality.`").ConfigureAwait(false); + return; + } + + var arg = query; + if (string.IsNullOrWhiteSpace(arg)) + { + await channel.SendMessageAsync("💢 `Please enter a sentence.`").ConfigureAwait(false); + return; + } + await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false); + using (var http = new HttpClient()) + { + http.DefaultRequestHeaders.Clear(); + http.DefaultRequestHeaders.Add("X-Mashape-Key", NadekoBot.Credentials.MashapeKey); + http.DefaultRequestHeaders.Add("Accept", "text/plain"); + var res = await http.GetStringAsync($"https://yoda.p.mashape.com/yoda?sentence={Uri.EscapeUriString(arg)}").ConfigureAwait(false); + try + { + var embed = new EmbedBuilder() + .WithTitle("Young Padawan") + .WithUrl("http://www.yodaspeak.co.uk/") + .WithAuthor(au => au.WithName("Yoda").WithIconUrl("http://www.yodaspeak.co.uk/yoda-small1.gif")) + .WithDescription("Seek advice, you must!") + .WithThumbnail(th => th.WithUrl("http://i.imgur.com/62Uh4u6.jpg")) + .AddField(fb => fb.WithName($"🌍 **{umsg.Author.Username}**").WithValue($"{res.ToString()}").WithIsInline(false)) + .WithColor(NadekoBot.OkColor) + .WithTimestamp(DateTime.Now); + await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); + } + catch + { + await channel.SendMessageAsync("💢 Failed to yodify your sentence.").ConfigureAwait(false); + } + } + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task UrbanDict(IUserMessage umsg, [Remainder] string query = null) diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index d64bce83..31a2b274 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -7781,6 +7781,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to yodify yoda. + /// + public static string yodify_cmd { + get { + return ResourceManager.GetString("yodify_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Translates your normal sentences into Yoda styled sentences!. + /// + public static string yodify_desc { + get { + return ResourceManager.GetString("yodify_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0}yodify I was once an adventurer like you` or `{0}yoda my feelings hurt`. + /// + public static string yodify_usage { + get { + return ResourceManager.GetString("yodify_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to yomama ym. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index e2df60fe..ab531b38 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2709,4 +2709,13 @@ `{0}magicthegathering about face` or `{0}mtg about face` + + yodify yoda + + + Translates your normal sentences into Yoda styled sentences! + + + {0}yodify I was once an adventurer like you` or `{0}yoda my feelings hurt` + \ No newline at end of file From 0464c1d7244e7a7bef9ffa0842bb0e379a6fa906 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 3 Dec 2016 14:54:25 -0500 Subject: [PATCH 4/4] Update Searches.cs remove timestamp --- src/NadekoBot/Modules/Searches/Searches.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index ed45e0eb..9dca0558 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -347,8 +347,7 @@ namespace NadekoBot.Modules.Searches .WithDescription("Seek advice, you must!") .WithThumbnail(th => th.WithUrl("http://i.imgur.com/62Uh4u6.jpg")) .AddField(fb => fb.WithName($"🌍 **{umsg.Author.Username}**").WithValue($"{res.ToString()}").WithIsInline(false)) - .WithColor(NadekoBot.OkColor) - .WithTimestamp(DateTime.Now); + .WithColor(NadekoBot.OkColor); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); } catch