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.Modules.Permissions.Classes;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Commands
|
||||
{
|
||||
@ -12,6 +15,8 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
{
|
||||
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)
|
||||
{
|
||||
NadekoBot.Client.MessageReceived += MsgRecivd;
|
||||
@ -45,6 +50,36 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
}
|
||||
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)
|
||||
@ -177,13 +212,13 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
if (!string.IsNullOrWhiteSpace(e.Message.Text))
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -206,13 +241,13 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
if (!string.IsNullOrWhiteSpace(e.Message.Text))
|
||||
{
|
||||
await ch.SendMessage(
|
||||
$@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{e.Channel.Name}`
|
||||
$@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{e.Channel.Name}`
|
||||
👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -232,7 +267,7 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
return;
|
||||
await ch.SendMessage(
|
||||
$@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
|
||||
$@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
|
||||
👤`{e.User?.ToString() ?? ("NULL")}`
|
||||
`Old:` {e.Before.Text.Unmention()}
|
||||
`New:` {e.After.Text.Unmention()}").ConfigureAwait(false);
|
||||
@ -252,7 +287,7 @@ $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
|
||||
{
|
||||
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}**."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -372,7 +407,7 @@ $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
|
||||
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
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);
|
||||
});
|
||||
|
||||
|
@ -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>
|
||||
######or paypal: `nadekodiscordbot@gmail.com`
|
||||
|
||||
#NadekoBot List Of Commands
|
||||
Version: `{NadekoStats.Instance.BotVersion}`";
|
||||
#NadekoBot List Of Commands ";
|
||||
|
||||
|
||||
string lastCategory = "";
|
||||
|
Loading…
Reference in New Issue
Block a user