Many random things

This commit is contained in:
Kwoth 2017-01-07 00:46:07 +01:00
parent c39d65dffd
commit f052bcf5a0
4 changed files with 26 additions and 4 deletions

View File

@ -269,8 +269,10 @@ namespace NadekoBot.Modules.Utility
.AddField(efb => efb.WithName(Format.Bold("Memory")).WithValue($"{stats.Heap} MB").WithIsInline(true)) .AddField(efb => efb.WithName(Format.Bold("Memory")).WithValue($"{stats.Heap} MB").WithIsInline(true))
.AddField(efb => efb.WithName(Format.Bold("Owner ID(s)")).WithValue(stats.OwnerIds).WithIsInline(true)) .AddField(efb => efb.WithName(Format.Bold("Owner ID(s)")).WithValue(stats.OwnerIds).WithIsInline(true))
.AddField(efb => efb.WithName(Format.Bold("Uptime")).WithValue(stats.GetUptimeString("\n")).WithIsInline(true)) .AddField(efb => efb.WithName(Format.Bold("Uptime")).WithValue(stats.GetUptimeString("\n")).WithIsInline(true))
.AddField(efb => efb.WithName(Format.Bold("Presence")).WithValue($"{NadekoBot.Client.GetGuilds().Count} Servers\n{stats.TextChannels} Text Channels\n{stats.VoiceChannels} Voice Channels").WithIsInline(true)) .AddField(efb => efb.WithName(Format.Bold("Presence")).WithValue($"{NadekoBot.Client.GetGuildsCount()} Servers\n{stats.TextChannels} Text Channels\n{stats.VoiceChannels} Voice Channels").WithIsInline(true))
#if !GLOBAL_NADEKO
.WithFooter(efb => efb.WithText($"Playing {Music.Music.MusicPlayers.Where(mp => mp.Value.CurrentSong != null).Count()} songs, {Music.Music.MusicPlayers.Sum(mp => mp.Value.Playlist.Count)} queued.")) .WithFooter(efb => efb.WithText($"Playing {Music.Music.MusicPlayers.Where(mp => mp.Value.CurrentSong != null).Count()} songs, {Music.Music.MusicPlayers.Sum(mp => mp.Value.Playlist.Count)} queued."))
#endif
); );
} }

View File

@ -17,6 +17,7 @@ using static NadekoBot.Modules.Administration.Administration;
using NadekoBot.Modules.CustomReactions; using NadekoBot.Modules.CustomReactions;
using NadekoBot.Modules.Games; using NadekoBot.Modules.Games;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Threading;
namespace NadekoBot.Services namespace NadekoBot.Services
{ {
@ -39,11 +40,19 @@ namespace NadekoBot.Services
//userid/msg count //userid/msg count
public ConcurrentDictionary<ulong, uint> UserMessagesSent { get; } = new ConcurrentDictionary<ulong, uint>(); public ConcurrentDictionary<ulong, uint> UserMessagesSent { get; } = new ConcurrentDictionary<ulong, uint>();
public ConcurrentHashSet<ulong> UsersOnShortCooldown { get; } = new ConcurrentHashSet<ulong>();
private Timer clearUsersOnShortCooldown { get; }
public CommandHandler(ShardedDiscordClient client, CommandService commandService) public CommandHandler(ShardedDiscordClient client, CommandService commandService)
{ {
_client = client; _client = client;
_commandService = commandService; _commandService = commandService;
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
clearUsersOnShortCooldown = new Timer((_) =>
{
UsersOnShortCooldown.Clear();
}, null, 1500, 1500);
} }
public async Task StartHandling() public async Task StartHandling()
{ {
@ -70,8 +79,11 @@ namespace NadekoBot.Services
if (usrMsg == null) if (usrMsg == null)
return; return;
//if (!usrMsg.IsAuthor()) if (!usrMsg.IsAuthor())
// UserMessagesSent.AddOrUpdate(usrMsg.Author.Id, 1, (key, old) => ++old); UserMessagesSent.AddOrUpdate(usrMsg.Author.Id, 1, (key, old) => ++old);
if (!UsersOnShortCooldown.Add(usrMsg.Author.Id))
return;
if (msg.Author.IsBot || !NadekoBot.Ready) //no bots if (msg.Author.IsBot || !NadekoBot.Ready) //no bots
return; return;

View File

@ -20,7 +20,12 @@ namespace NadekoBot.Services.Impl
public string Library => "Discord.Net"; public string Library => "Discord.Net";
public int MessageCounter { get; private set; } = 0; public int MessageCounter { get; private set; } = 0;
public int CommandsRan { 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 string Heap =>
#if !GLOBAL_NADEKO
Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString();
#else
"a lot :)";
#endif
public double MessagesPerSecond => MessageCounter / (double)GetUptime().TotalSeconds; public double MessagesPerSecond => MessageCounter / (double)GetUptime().TotalSeconds;
public int TextChannels => client.GetGuilds().SelectMany(g => g.Channels.Where(c => c is ITextChannel)).Count(); public int TextChannels => client.GetGuilds().SelectMany(g => g.Channels.Where(c => c is ITextChannel)).Count();
public int VoiceChannels => client.GetGuilds().SelectMany(g => g.Channels.Where(c => c is IVoiceChannel)).Count(); public int VoiceChannels => client.GetGuilds().SelectMany(g => g.Channels.Where(c => c is IVoiceChannel)).Count();

View File

@ -96,6 +96,9 @@ namespace NadekoBot
public IReadOnlyCollection<SocketGuild> GetGuilds() => public IReadOnlyCollection<SocketGuild> GetGuilds() =>
Clients.SelectMany(c => c.Guilds).ToList(); Clients.SelectMany(c => c.Guilds).ToList();
public int GetGuildsCount() =>
Clients.Sum(c => c.Guilds.Count);
public SocketGuild GetGuild(ulong id) => public SocketGuild GetGuild(ulong id) =>
Clients.Select(c => c.GetGuild(id)).FirstOrDefault(g => g != null); Clients.Select(c => c.GetGuild(id)).FirstOrDefault(g => g != null);