User presence updates are now sent every 5 seconds. #468

This commit is contained in:
Kwoth 2016-07-31 20:06:09 +02:00
parent 31b2558523
commit 3aff5d0a12
2 changed files with 44 additions and 10 deletions

View File

@ -4,7 +4,10 @@ using NadekoBot.Classes;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Permissions.Classes; using NadekoBot.Modules.Permissions.Classes;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Administration.Commands namespace NadekoBot.Modules.Administration.Commands
{ {
@ -12,6 +15,8 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】"; private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
private ConcurrentBag<KeyValuePair<Channel, string>> voicePresenceUpdates = new ConcurrentBag<KeyValuePair<Channel, string>>();
public LogCommand(DiscordModule module) : base(module) public LogCommand(DiscordModule module) : base(module)
{ {
NadekoBot.Client.MessageReceived += MsgRecivd; NadekoBot.Client.MessageReceived += MsgRecivd;
@ -45,6 +50,36 @@ namespace NadekoBot.Modules.Administration.Commands
} }
catch { } catch { }
}; };
// start the userpresence queue
NadekoBot.OnReady += () => Task.Run(async () =>
{
while (true)
{
var toSend = new Dictionary<Channel, string>();
//take everything from the queue and merge the messages which are going to the same channel
KeyValuePair<Channel, string> item;
while (voicePresenceUpdates.TryTake(out item))
{
if (toSend.ContainsKey(item.Key))
{
toSend[item.Key] = toSend[item.Key] + Environment.NewLine + item.Value;
}
else
{
toSend.Add(item.Key, item.Value);
}
}
//send merged messages to each channel
foreach (var k in toSend)
{
try { await k.Key.SendMessage(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { }
}
await Task.Delay(5000);
}
});
} }
private async void ChannelUpdated(object sender, ChannelUpdatedEventArgs e) private async void ChannelUpdated(object sender, ChannelUpdatedEventArgs e)
@ -177,13 +212,13 @@ namespace NadekoBot.Modules.Administration.Commands
if (!string.IsNullOrWhiteSpace(e.Message.Text)) if (!string.IsNullOrWhiteSpace(e.Message.Text))
{ {
await ch.SendMessage( await ch.SendMessage(
$@"🕔`{prettyCurrentTime}` **New Message** `#{e.Channel.Name}` $@"🕔`{prettyCurrentTime}` **New Message** `#{e.Channel.Name}`
👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false); 👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false);
} }
else else
{ {
await ch.SendMessage( await ch.SendMessage(
$@"🕔`{prettyCurrentTime}` **File Uploaded** `#{e.Channel.Name}` $@"🕔`{prettyCurrentTime}` **File Uploaded** `#{e.Channel.Name}`
👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false); 👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false);
} }
@ -206,13 +241,13 @@ namespace NadekoBot.Modules.Administration.Commands
if (!string.IsNullOrWhiteSpace(e.Message.Text)) if (!string.IsNullOrWhiteSpace(e.Message.Text))
{ {
await ch.SendMessage( await ch.SendMessage(
$@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{e.Channel.Name}` $@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{e.Channel.Name}`
👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false); 👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false);
} }
else else
{ {
await ch.SendMessage( await ch.SendMessage(
$@"🕔`{prettyCurrentTime}` **File Deleted** `#{e.Channel.Name}` $@"🕔`{prettyCurrentTime}` **File Deleted** `#{e.Channel.Name}`
👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false); 👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false);
} }
} }
@ -232,7 +267,7 @@ namespace NadekoBot.Modules.Administration.Commands
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
return; return;
await ch.SendMessage( await ch.SendMessage(
$@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}` $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
👤`{e.User?.ToString() ?? ("NULL")}` 👤`{e.User?.ToString() ?? ("NULL")}`
`Old:` {e.Before.Text.Unmention()} `Old:` {e.Before.Text.Unmention()}
`New:` {e.After.Text.Unmention()}").ConfigureAwait(false); `New:` {e.After.Text.Unmention()}").ConfigureAwait(false);
@ -252,7 +287,7 @@ $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
{ {
if (e.Before.Status != e.After.Status) if (e.Before.Status != e.After.Status)
{ {
await ch.SendMessage($"`{prettyCurrentTime}`**{e.Before.Name}** is now **{e.After.Status}**.").ConfigureAwait(false); voicePresenceUpdates.Add(new KeyValuePair<Channel, string>(ch, $"`{prettyCurrentTime}`**{e.Before.Name}** is now **{e.After.Status}**."));
} }
} }
} }
@ -371,8 +406,8 @@ $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
Channel ch; Channel ch;
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
return; return;
SpecificConfigurations.Default.Of (e.Server.Id).LogServerChannel = null; SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel = null;
await e.Channel.SendMessage($"❗**NO LONGER LOGGING IN {ch.Mention} CHANNEL**❗").ConfigureAwait(false); await e.Channel.SendMessage($"❗**NO LONGER LOGGING IN {ch.Mention} CHANNEL**❗").ConfigureAwait(false);
}); });

View File

@ -52,8 +52,7 @@ $@"######For more information and how to setup your own NadekoBot, go to: <http:
######You can donate on patreon: <https://patreon.com/nadekobot> ######You can donate on patreon: <https://patreon.com/nadekobot>
######or paypal: `nadekodiscordbot@gmail.com` ######or paypal: `nadekodiscordbot@gmail.com`
#NadekoBot List Of Commands #NadekoBot List Of Commands ";
Version: `{NadekoStats.Instance.BotVersion}`";
string lastCategory = ""; string lastCategory = "";