diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index eb7c7404..5e875219 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -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("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("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.")) +#endif ); } diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index f196e20e..e22249e9 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -17,6 +17,7 @@ using static NadekoBot.Modules.Administration.Administration; using NadekoBot.Modules.CustomReactions; using NadekoBot.Modules.Games; using System.Collections.Concurrent; +using System.Threading; namespace NadekoBot.Services { @@ -39,11 +40,19 @@ namespace NadekoBot.Services //userid/msg count public ConcurrentDictionary UserMessagesSent { get; } = new ConcurrentDictionary(); + public ConcurrentHashSet UsersOnShortCooldown { get; } = new ConcurrentHashSet(); + private Timer clearUsersOnShortCooldown { get; } + public CommandHandler(ShardedDiscordClient client, CommandService commandService) { _client = client; _commandService = commandService; _log = LogManager.GetCurrentClassLogger(); + + clearUsersOnShortCooldown = new Timer((_) => + { + UsersOnShortCooldown.Clear(); + }, null, 1500, 1500); } public async Task StartHandling() { @@ -70,8 +79,11 @@ namespace NadekoBot.Services if (usrMsg == null) return; - //if (!usrMsg.IsAuthor()) - // UserMessagesSent.AddOrUpdate(usrMsg.Author.Id, 1, (key, old) => ++old); + if (!usrMsg.IsAuthor()) + UserMessagesSent.AddOrUpdate(usrMsg.Author.Id, 1, (key, old) => ++old); + + if (!UsersOnShortCooldown.Add(usrMsg.Author.Id)) + return; if (msg.Author.IsBot || !NadekoBot.Ready) //no bots return; diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index c767ecec..3331edeb 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -20,7 +20,12 @@ namespace NadekoBot.Services.Impl 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 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 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(); diff --git a/src/NadekoBot/ShardedDiscordClient.cs b/src/NadekoBot/ShardedDiscordClient.cs index 580f0e8d..29630eaf 100644 --- a/src/NadekoBot/ShardedDiscordClient.cs +++ b/src/NadekoBot/ShardedDiscordClient.cs @@ -96,6 +96,9 @@ namespace NadekoBot public IReadOnlyCollection GetGuilds() => Clients.SelectMany(c => c.Guilds).ToList(); + public int GetGuildsCount() => + Clients.Sum(c => c.Guilds.Count); + public SocketGuild GetGuild(ulong id) => Clients.Select(c => c.GetGuild(id)).FirstOrDefault(g => g != null);