.stats much prettier, .SendErrorAsync added for normalized error messages
This commit is contained in:
parent
1ff07446c3
commit
477a34a6ee
@ -1,5 +1,5 @@
|
||||
For more information and how to setup your own NadekoBot, go to: <http://github.com/Kwoth/NadekoBot/wiki>
|
||||
You can support the project on patreon: <https://patreon.com/nadekobot> or paypal: `nadekodiscordbot@gmail.com`
|
||||
You can support the project on patreon: <https://patreon.com/nadekobot> or paypal: <https://www.paypal.me/Kwoth>
|
||||
|
||||
##Table Of Contents
|
||||
- [Help](#help)
|
||||
- [Administration](#administration)
|
||||
|
@ -641,7 +641,8 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
var user = channel.Guild.GetCurrentUser();
|
||||
|
||||
var enumerable = (await umsg.Channel.GetMessagesAsync()).Where(x => x.Author.Id == user.Id);
|
||||
var enumerable = (await umsg.Channel.GetMessagesAsync()).AsEnumerable();
|
||||
enumerable = enumerable.Where(x => x.Author.Id == user.Id);
|
||||
await umsg.Channel.DeleteMessagesAsync(enumerable);
|
||||
}
|
||||
|
||||
|
@ -121,8 +121,7 @@ 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: <http://github.com/Kwoth/NadekoBot/wiki>
|
||||
You can support the project on patreon: <https://patreon.com/nadekobot> or paypal: `nadekodiscordbot@gmail.com`");
|
||||
helpstr.AppendLine("You can support the project on patreon: <https://patreon.com/nadekobot> or paypal: <https://www.paypal.me/Kwoth>\n");
|
||||
helpstr.AppendLine("##Table Of Contents");
|
||||
helpstr.AppendLine(string.Join("\n", NadekoBot.CommandService.Modules.Where(m => m.Name.ToLowerInvariant() != "help").OrderBy(m => m.Name).Prepend(NadekoBot.CommandService.Modules.FirstOrDefault(m=>m.Name.ToLowerInvariant()=="help")).Select(m => $"- [{m.Name}](#{m.Name.ToLowerInvariant()})")));
|
||||
helpstr.AppendLine();
|
||||
|
@ -10,6 +10,11 @@ using NadekoBot.Extensions;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Reflection;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Services.Impl;
|
||||
using Discord.API;
|
||||
using Embed = Discord.API.Embed;
|
||||
using EmbedAuthor = Discord.API.EmbedAuthor;
|
||||
using EmbedField = Discord.API.EmbedField;
|
||||
|
||||
namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
@ -37,7 +42,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
int i = 0;
|
||||
if (!arr.Any())
|
||||
await channel.SendMessageAsync(_l["🚧 `Nobody is playing that game.`"]).ConfigureAwait(false);
|
||||
await channel.SendErrorAsync("Nobody is playing that game.").ConfigureAwait(false);
|
||||
else
|
||||
await channel.SendMessageAsync("```css\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Concat(ig.Select(el => $"• {el,-35}")))) + "\n```").ConfigureAwait(false);
|
||||
}
|
||||
@ -158,7 +163,67 @@ namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
var channel = umsg.Channel;
|
||||
|
||||
await channel.SendMessageAsync(await NadekoBot.Stats.Print());
|
||||
var stats = NadekoBot.Stats;
|
||||
|
||||
await channel.EmbedAsync(
|
||||
new Embed()
|
||||
{
|
||||
Author = new EmbedAuthor()
|
||||
{
|
||||
Name = $"NadekoBot v{StatsService.BotVersion}",
|
||||
Url = "http://nadekobot.readthedocs.io/en/latest/",
|
||||
IconUrl = "https://cdn.discordapp.com/avatars/116275390695079945/b21045e778ef21c96d175400e779f0fb.jpg"
|
||||
},
|
||||
Fields = new[] {
|
||||
new EmbedField() {
|
||||
Name = "Author",
|
||||
Value = stats.Author,
|
||||
Inline = true
|
||||
},
|
||||
new EmbedField() {
|
||||
Name = "Library",
|
||||
Value = stats.Library,
|
||||
Inline = true
|
||||
},
|
||||
new EmbedField() {
|
||||
Name = "Bot ID",
|
||||
Value = NadekoBot.Client.GetCurrentUser().Id.ToString(),
|
||||
Inline = true
|
||||
},
|
||||
new EmbedField() {
|
||||
Name = "Commands Ran",
|
||||
Value = stats.CommandsRan.ToString(),
|
||||
Inline = true
|
||||
},
|
||||
new EmbedField() {
|
||||
Name = "Messages",
|
||||
Value = $"{stats.MessageCounter} [{stats.MessagesPerSecond:F2}/sec]",
|
||||
Inline = true
|
||||
},
|
||||
new EmbedField() {
|
||||
Name = "Memory",
|
||||
Value = $"{stats.Heap} MB",
|
||||
Inline = true
|
||||
},
|
||||
new EmbedField() {
|
||||
Name = "Owner ID(s)",
|
||||
Value = stats.OwnerIds,
|
||||
Inline = true
|
||||
},
|
||||
new EmbedField() {
|
||||
Name = "Uptime",
|
||||
Value = stats.GetUptimeString("\n"),
|
||||
Inline = true
|
||||
},
|
||||
new EmbedField() {
|
||||
Name = "Presence",
|
||||
Value = $"{NadekoBot.Client.GetGuilds().Count} servers\n{stats.TextChannels} Text Channels\n{stats.VoiceChannels} Voice Channels",
|
||||
Inline = true
|
||||
},
|
||||
|
||||
},
|
||||
Color = NadekoBot.OkColor
|
||||
});
|
||||
}
|
||||
|
||||
private Regex emojiFinder { get; } = new Regex(@"<:(?<name>.+?):(?<id>\d*)>", RegexOptions.Compiled);
|
||||
|
@ -12,26 +12,33 @@ namespace NadekoBot.Services.Impl
|
||||
{
|
||||
public class StatsService : IStatsService
|
||||
{
|
||||
private int messageCounter;
|
||||
private ShardedDiscordClient client;
|
||||
private ShardedDiscordClient client;
|
||||
private DateTime started;
|
||||
private int commandsRan = 0;
|
||||
|
||||
public const string BotVersion = "1.0-rc2";
|
||||
|
||||
public string Author => "Kwoth#2560";
|
||||
public string Library => "Discord.Net";
|
||||
public int MessageCounter { get; private set; } = 0;
|
||||
public int CommandsRan { get; private set; } = 0;
|
||||
public string Heap => Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString();
|
||||
public double MessagesPerSecond => MessageCounter / (double)GetUptime().TotalSeconds;
|
||||
public int TextChannels => client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is ITextChannel)).Count();
|
||||
public int VoiceChannels => client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is IVoiceChannel)).Count();
|
||||
public string OwnerIds => string.Join(", ", NadekoBot.Credentials.OwnerIds);
|
||||
|
||||
|
||||
|
||||
Timer carbonitexTimer { get; }
|
||||
|
||||
|
||||
public StatsService(ShardedDiscordClient client, CommandHandler cmdHandler)
|
||||
{
|
||||
|
||||
this.client = client;
|
||||
|
||||
Reset();
|
||||
this.client.MessageReceived += _ => Task.FromResult(messageCounter++);
|
||||
cmdHandler.CommandExecuted += (_, e) => commandsRan++;
|
||||
this.client.MessageReceived += _ => Task.FromResult(MessageCounter++);
|
||||
cmdHandler.CommandExecuted += (_, e) => CommandsRan++;
|
||||
|
||||
this.client.Disconnected += _ => Reset();
|
||||
|
||||
@ -61,20 +68,20 @@ namespace NadekoBot.Services.Impl
|
||||
public async Task<string> Print()
|
||||
{
|
||||
var curUser = await client.GetCurrentUserAsync();
|
||||
return $@"```css
|
||||
Author: [Kwoth#2560] | Library: [Discord.Net]
|
||||
return $@"
|
||||
Author: [{Author}] | Library: [{Library}]
|
||||
Bot Version: [{BotVersion}]
|
||||
Bot ID: {curUser.Id}
|
||||
Owner ID(s): {string.Join(", ", NadekoBot.Credentials.OwnerIds)}
|
||||
Owner ID(s): {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]```";
|
||||
Servers: {client.GetGuilds().Count} | TextChannels: {TextChannels} | VoiceChannels: {VoiceChannels}
|
||||
Commands Ran this session: {CommandsRan}
|
||||
Messages: {MessageCounter} [{MessagesPerSecond:F2}/sec] Heap: [{Heap} MB]";
|
||||
}
|
||||
|
||||
public Task Reset()
|
||||
{
|
||||
messageCounter = 0;
|
||||
MessageCounter = 0;
|
||||
started = DateTime.Now;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@ -82,10 +89,10 @@ Messages: {messageCounter} [{messageCounter / (double)GetUptime().TotalSeconds:F
|
||||
public TimeSpan GetUptime() =>
|
||||
DateTime.Now - started;
|
||||
|
||||
public string GetUptimeString()
|
||||
public string GetUptimeString(string separator = ", ")
|
||||
{
|
||||
var time = GetUptime();
|
||||
return time.Days + " days, " + time.Hours + " hours, and " + time.Minutes + " minutes.";
|
||||
return $"{time.Days} days{separator}{time.Hours} hours{separator}{time.Minutes} minutes";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,6 +159,9 @@ namespace NadekoBot.Extensions
|
||||
public static Task<IUserMessage> EmbedAsync(this IMessageChannel ch, Discord.API.Embed embed)
|
||||
=> ch.SendMessageAsync("", embed: embed);
|
||||
|
||||
public static Task<IUserMessage> SendErrorAsync(this IMessageChannel ch, string error, string title = null, string url = null)
|
||||
=> ch.SendMessageAsync("", embed: new Embed() { Description = error, Title = title, Url = url, Color = NadekoBot.ErrorColor });
|
||||
|
||||
public static Task<IUserMessage> SendTableAsync<T>(this IMessageChannel ch, string seed, IEnumerable<T> items, Func<T, string> howToPrint, int columns = 3)
|
||||
{
|
||||
var i = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user