Added a lot of logging to find the delays
This commit is contained in:
parent
c91716a143
commit
f552e03e24
@ -4,6 +4,7 @@ using NadekoBot.Attributes;
|
|||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Services;
|
using NadekoBot.Services;
|
||||||
using NadekoBot.Services.Database.Models;
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using NLog;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -16,24 +17,28 @@ namespace NadekoBot.Modules.Administration
|
|||||||
public class ServerGreetCommands
|
public class ServerGreetCommands
|
||||||
{
|
{
|
||||||
public static long Greeted = 0;
|
public static long Greeted = 0;
|
||||||
|
private Logger _log;
|
||||||
|
|
||||||
public ServerGreetCommands()
|
public ServerGreetCommands()
|
||||||
{
|
{
|
||||||
NadekoBot.Client.UserJoined += UserJoined;
|
NadekoBot.Client.UserJoined += UserJoined;
|
||||||
NadekoBot.Client.UserLeft += UserLeft;
|
NadekoBot.Client.UserLeft += UserLeft;
|
||||||
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UserLeft(IGuildUser user)
|
private async Task UserLeft(IGuildUser user)
|
||||||
{
|
{
|
||||||
|
_log.Info("Left: User Left");
|
||||||
GuildConfig conf;
|
GuildConfig conf;
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
conf = uow.GuildConfigs.For(user.Guild.Id);
|
conf = uow.GuildConfigs.For(user.Guild.Id);
|
||||||
}
|
}
|
||||||
|
_log.Info("Left: Got unit of work");
|
||||||
|
|
||||||
if (!conf.SendChannelByeMessage) return;
|
if (!conf.SendChannelByeMessage) return;
|
||||||
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.ByeMessageChannelId);
|
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.ByeMessageChannelId);
|
||||||
|
_log.Info("Left: Found channel");
|
||||||
if (channel == null) //maybe warn the server owner that the channel is missing
|
if (channel == null) //maybe warn the server owner that the channel is missing
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -41,37 +46,45 @@ namespace NadekoBot.Modules.Administration
|
|||||||
if (string.IsNullOrWhiteSpace(msg))
|
if (string.IsNullOrWhiteSpace(msg))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
_log.Info("Left: Sending");
|
||||||
var toDelete = await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
var toDelete = await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
||||||
if (conf.AutoDeleteByeMessages)
|
if (conf.AutoDeleteByeMessages)
|
||||||
{
|
{
|
||||||
|
_log.Info("Left: Sent, waiting for delete");
|
||||||
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
|
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
|
||||||
|
_log.Info("Left: Deleted");
|
||||||
await toDelete.DeleteAsync().ConfigureAwait(false);
|
await toDelete.DeleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UserJoined(IGuildUser user)
|
private async Task UserJoined(IGuildUser user)
|
||||||
{
|
{
|
||||||
|
_log.Info("Joined: User joined");
|
||||||
GuildConfig conf;
|
GuildConfig conf;
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
conf = uow.GuildConfigs.For(user.Guild.Id);
|
conf = uow.GuildConfigs.For(user.Guild.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_log.Info("Joined: Got unit of work");
|
||||||
if (conf.SendChannelGreetMessage)
|
if (conf.SendChannelGreetMessage)
|
||||||
{
|
{
|
||||||
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId);
|
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId);
|
||||||
|
_log.Info("Joined: Found required channel");
|
||||||
if (channel != null) //maybe warn the server owner that the channel is missing
|
if (channel != null) //maybe warn the server owner that the channel is missing
|
||||||
{
|
{
|
||||||
|
|
||||||
var msg = conf.ChannelGreetMessageText.Replace("%user%", "**" + user.Username + "**");
|
var msg = conf.ChannelGreetMessageText.Replace("%user%", "**" + user.Username + "**");
|
||||||
if (!string.IsNullOrWhiteSpace(msg))
|
if (!string.IsNullOrWhiteSpace(msg))
|
||||||
{
|
{
|
||||||
|
_log.Info("Joined: Sending message");
|
||||||
var toDelete = await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
var toDelete = await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
||||||
|
_log.Info("Joined: Message sent");
|
||||||
if (conf.AutoDeleteGreetMessages)
|
if (conf.AutoDeleteGreetMessages)
|
||||||
{
|
{
|
||||||
|
_log.Info("Joined: Waiting to delete");
|
||||||
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
|
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
|
||||||
await toDelete.DeleteAsync().ConfigureAwait(false);
|
await toDelete.DeleteAsync().ConfigureAwait(false);
|
||||||
|
_log.Info("Joined: Deleted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public string ChannelGreetMessageText { get; set; } = "Welcome to the %server% server, %user%!";
|
public string ChannelGreetMessageText { get; set; } = "Welcome to the %server% server, %user%!";
|
||||||
|
|
||||||
public bool SendChannelByeMessage { get; set; }
|
public bool SendChannelByeMessage { get; set; }
|
||||||
public string ChannelByeMessageText { get; set; } = "Welcome to the %server% server, %user%!";
|
public string ChannelByeMessageText { get; set; } = "%user% has left!";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user