From 6c534f4233296d6e206c0ef148e37ef6c500cdd2 Mon Sep 17 00:00:00 2001 From: fkndean Date: Tue, 29 Nov 2016 08:47:06 -0500 Subject: [PATCH] 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()