User presence updates are now sent every 5 seconds. #468
This commit is contained in:
parent
31b2558523
commit
3aff5d0a12
@ -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)
|
||||||
@ -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}**."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 = "";
|
||||||
|
Loading…
Reference in New Issue
Block a user