Huge amounts of changes, hopefully nothing broken

This commit is contained in:
Kwoth 2016-12-28 06:31:39 +01:00
parent 84703f4bf0
commit 3a68a8b4f6
23 changed files with 1038 additions and 1058 deletions

View File

@ -85,11 +85,11 @@ namespace NadekoBot.Modules.Administration
{ {
var msg = imsg as IUserMessage; var msg = imsg as IUserMessage;
if (msg == null || msg.Author.IsBot) if (msg == null || msg.Author.IsBot)
return Task.CompletedTask; return;
var channel = msg.Channel as ITextChannel; var channel = msg.Channel as ITextChannel;
if (channel == null) if (channel == null)
return Task.CompletedTask; return;
var t = Task.Run(async () => var t = Task.Run(async () =>
{ {
@ -113,20 +113,18 @@ namespace NadekoBot.Modules.Administration
} }
catch { } catch { }
}); });
return Task.CompletedTask; return;
}; };
NadekoBot.Client.UserJoined += (usr) => NadekoBot.Client.UserJoined += async (usr) =>
{
try
{ {
if (usr.IsBot) if (usr.IsBot)
return Task.CompletedTask; return;
AntiRaidSetting settings; AntiRaidSetting settings;
if (!antiRaidGuilds.TryGetValue(usr.Guild.Id, out settings)) if (!antiRaidGuilds.TryGetValue(usr.Guild.Id, out settings))
return Task.CompletedTask; return;
var t = Task.Run(async () =>
{
if (!settings.RaidUsers.Add(usr)) if (!settings.RaidUsers.Add(usr))
return; return;
@ -143,9 +141,9 @@ namespace NadekoBot.Modules.Administration
settings.RaidUsers.TryRemove(usr); settings.RaidUsers.TryRemove(usr);
--settings.UsersCount; --settings.UsersCount;
});
return Task.CompletedTask; }
catch { }
}; };
} }

View File

@ -26,9 +26,7 @@ namespace NadekoBot.Modules.Administration
AutoAssignedRoles = new ConcurrentDictionary<ulong, ulong>(NadekoBot.AllGuildConfigs.Where(x => x.AutoAssignRoleId != 0) AutoAssignedRoles = new ConcurrentDictionary<ulong, ulong>(NadekoBot.AllGuildConfigs.Where(x => x.AutoAssignRoleId != 0)
.ToDictionary(k => k.GuildId, v => v.AutoAssignRoleId)); .ToDictionary(k => k.GuildId, v => v.AutoAssignRoleId));
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
NadekoBot.Client.UserJoined += (user) => NadekoBot.Client.UserJoined += async (user) =>
{
var t = Task.Run(async () =>
{ {
try try
{ {
@ -44,8 +42,6 @@ namespace NadekoBot.Modules.Administration
await user.AddRolesAsync(role).ConfigureAwait(false); await user.AddRolesAsync(role).ConfigureAwait(false);
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
}; };
} }

View File

@ -19,21 +19,18 @@ namespace NadekoBot.Modules.Administration
static CrossServerTextChannel() static CrossServerTextChannel()
{ {
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
NadekoBot.Client.MessageReceived += (imsg) => NadekoBot.Client.MessageReceived += async (imsg) =>
{
try
{ {
if (imsg.Author.IsBot) if (imsg.Author.IsBot)
return Task.CompletedTask; return;
var msg = imsg as IUserMessage; var msg = imsg as IUserMessage;
if (msg == null) if (msg == null)
return Task.CompletedTask; return;
var channel = imsg.Channel as ITextChannel; var channel = imsg.Channel as ITextChannel;
if (channel == null) if (channel == null)
return Task.CompletedTask; return;
Task.Run(async () =>
{
if (msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return; if (msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return;
foreach (var subscriber in Subscribers) foreach (var subscriber in Subscribers)
{ {
@ -45,8 +42,10 @@ namespace NadekoBot.Modules.Administration
try { await chan.SendMessageAsync(GetText(channel.Guild, channel, (IGuildUser)msg.Author, msg)).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } try { await chan.SendMessageAsync(GetText(channel.Guild, channel, (IGuildUser)msg.Author, msg)).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
} }
} }
}); }
return Task.CompletedTask; catch (Exception ex) {
_log.Warn(ex);
}
}; };
} }

View File

@ -86,26 +86,28 @@ namespace NadekoBot.Modules.Administration
MuteCommands.UserUnmuted += MuteCommands_UserUnmuted; MuteCommands.UserUnmuted += MuteCommands_UserUnmuted;
} }
private Task _client_UserVoiceStateUpdated_TTS(IUser iusr, IVoiceState before, IVoiceState after) private async void _client_UserVoiceStateUpdated_TTS(IUser iusr, IVoiceState before, IVoiceState after)
{
try
{ {
var usr = iusr as IGuildUser; var usr = iusr as IGuildUser;
if (usr == null) if (usr == null)
return Task.CompletedTask; return;
var beforeVch = before.VoiceChannel; var beforeVch = before.VoiceChannel;
var afterVch = after.VoiceChannel; var afterVch = after.VoiceChannel;
if (beforeVch == afterVch) if (beforeVch == afterVch)
return Task.CompletedTask; return;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| (logSetting.LogVoicePresenceTTSId == null)) || (logSetting.LogVoicePresenceTTSId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null) if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null)
return Task.CompletedTask; return;
string str = null; string str = null;
if (beforeVch?.Guild == afterVch?.Guild) if (beforeVch?.Guild == afterVch?.Guild)
@ -120,33 +122,24 @@ namespace NadekoBot.Modules.Administration
{ {
str = $"{usr.Username} has left {beforeVch.Name}"; str = $"{usr.Username} has left {beforeVch.Name}";
} }
Task.Run(async () =>
{
try
{
var toDelete = await logChannel.SendMessageAsync(str, true).ConfigureAwait(false); var toDelete = await logChannel.SendMessageAsync(str, true).ConfigureAwait(false);
toDelete.DeleteAfter(5); toDelete.DeleteAfter(5);
} }
catch { } catch { }
});
return Task.CompletedTask;
} }
private Task MuteCommands_UserMuted(IGuildUser usr, MuteCommands.MuteType muteType) private async void MuteCommands_UserMuted(IGuildUser usr, MuteCommands.MuteType muteType)
{
try
{ {
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| (logSetting.UserMutedId == null)) || (logSetting.UserMutedId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
return Task.CompletedTask; return;
var task = Task.Run(async () =>
{
string mutes = ""; string mutes = "";
switch (muteType) switch (muteType)
{ {
@ -160,25 +153,24 @@ namespace NadekoBot.Modules.Administration
mutes = "text and voice chat"; mutes = "text and voice chat";
break; break;
} }
try { await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🔇 **| User muted from the {mutes}. |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🔇 **| User muted from the {mutes}. |** 🆔 `{usr.Id}`").ConfigureAwait(false);
}); }
catch (Exception ex) { _log.Warn(ex); }
return Task.CompletedTask;
} }
private Task MuteCommands_UserUnmuted(IGuildUser usr, MuteCommands.MuteType muteType) private async void MuteCommands_UserUnmuted(IGuildUser usr, MuteCommands.MuteType muteType)
{
try
{ {
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| (logSetting.UserMutedId == null)) || (logSetting.UserMutedId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
return Task.CompletedTask; return;
var task = Task.Run(async () =>
{
string mutes = ""; string mutes = "";
switch (muteType) switch (muteType)
{ {
@ -192,13 +184,14 @@ namespace NadekoBot.Modules.Administration
mutes = "text and voice chat"; mutes = "text and voice chat";
break; break;
} }
try { await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🔊 **| User unmuted from the {mutes}. |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🔊 **| User unmuted from the {mutes}. |** 🆔 `{usr.Id}`").ConfigureAwait(false);
}); }
catch (Exception ex) { _log.Warn(ex); }
return Task.CompletedTask;
} }
public static async Task TriggeredAntiProtection(IGuildUser[] users, PunishmentAction action, ProtectionType protection) public static async Task TriggeredAntiProtection(IGuildUser[] users, PunishmentAction action, ProtectionType protection)
{
try
{ {
if (users.Length == 0) if (users.Length == 0)
return; return;
@ -231,22 +224,21 @@ namespace NadekoBot.Modules.Administration
//await logChannel.SendMessageAsync(String.Join("\n",users.Select(user=>$"{Format.Bold(user.ToString())} was **{punishment}** due to `{protection}` protection on **{user.Guild.Name}** server."))) //await logChannel.SendMessageAsync(String.Join("\n",users.Select(user=>$"{Format.Bold(user.ToString())} was **{punishment}** due to `{protection}` protection on **{user.Guild.Name}** server.")))
.ConfigureAwait(false); .ConfigureAwait(false);
} }
catch (Exception ex) { _log.Warn(ex); }
}
private Task _client_UserUpdated(IGuildUser before, IGuildUser after) private async void _client_UserUpdated(IGuildUser before, IGuildUser after)
{
try
{ {
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting)
|| (logSetting.UserUpdatedId == null)) || (logSetting.UserUpdatedId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null) if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null)
return Task.CompletedTask; return;
var task = Task.Run(async () =>
{
try
{
string str = $"🕔`{prettyCurrentTime}`"; string str = $"🕔`{prettyCurrentTime}`";
if (before.Username != after.Username) if (before.Username != after.Username)
//str += $"**Name Changed**`{before.Username}#{before.Discriminator}`\n\t\t`New:`{after.ToString()}`"; //str += $"**Name Changed**`{before.Username}#{before.Discriminator}`\n\t\t`New:`{after.ToString()}`";
@ -276,33 +268,27 @@ namespace NadekoBot.Modules.Administration
return; return;
try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
} }
catch { } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter) private async void _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
{
try
{ {
var before = cbefore as IGuildChannel; var before = cbefore as IGuildChannel;
if (before == null) if (before == null)
return Task.CompletedTask; return;
var after = (IGuildChannel)cafter; var after = (IGuildChannel)cafter;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting)
|| (logSetting.ChannelUpdatedId == null) || (logSetting.ChannelUpdatedId == null)
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == after.Id)) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == after.Id))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null) if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null)
return Task.CompletedTask; return;
var task = Task.Run(async () =>
{
try
{
if (before.Name != after.Name) if (before.Name != after.Name)
//await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{after.Name}` ({after.Id}) //await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{after.Name}` ({after.Id})
await logChannel.SendMessageAsync($@"🕓`{prettyCurrentTime}` **| Channel Name Changed |** #⃣ `{after.Name} ({after.Id})` await logChannel.SendMessageAsync($@"🕓`{prettyCurrentTime}` **| Channel Name Changed |** #⃣ `{after.Name} ({after.Id})`
@ -314,79 +300,76 @@ namespace NadekoBot.Modules.Administration
`Old:` {((ITextChannel)before).Topic} `Old:` {((ITextChannel)before).Topic}
**`New:`** {((ITextChannel)after).Topic}").ConfigureAwait(false); **`New:`** {((ITextChannel)after).Topic}").ConfigureAwait(false);
} }
catch { } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private Task _client_ChannelDestroyed(IChannel ich) private async void _client_ChannelDestroyed(IChannel ich)
{
try
{ {
var ch = ich as IGuildChannel; var ch = ich as IGuildChannel;
if (ch == null) if (ch == null)
return Task.CompletedTask; return;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting)
|| (logSetting.ChannelDestroyedId == null) || (logSetting.ChannelDestroyedId == null)
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == ch.Id)) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == ch.Id))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null) if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null)
return Task.CompletedTask; return;
var task = Task.Run(async () => await logChannel.SendMessageAsync($"🕕`{prettyCurrentTime}`🗑 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Deleted #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false);
{ }
try { await logChannel.SendMessageAsync($"🕕`{prettyCurrentTime}`🗑 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Deleted #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private Task _client_ChannelCreated(IChannel ich) private async void _client_ChannelCreated(IChannel ich)
{
try
{ {
var ch = ich as IGuildChannel; var ch = ich as IGuildChannel;
if (ch == null) if (ch == null)
return Task.CompletedTask; return;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting)
|| (logSetting.ChannelCreatedId == null)) || (logSetting.ChannelCreatedId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null) if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null)
return Task.CompletedTask; return;
var task = Task.Run(async () => await logChannel.SendMessageAsync($"🕓`{prettyCurrentTime}`🆕 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Created: #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false);
{ }
try { await logChannel.SendMessageAsync($"🕓`{prettyCurrentTime}`🆕 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Created: #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private Task _client_UserVoiceStateUpdated(IUser iusr, IVoiceState before, IVoiceState after) private async void _client_UserVoiceStateUpdated(IUser iusr, IVoiceState before, IVoiceState after) => await Task.Run(() =>
{
try
{ {
var usr = iusr as IGuildUser; var usr = iusr as IGuildUser;
if (usr == null) if (usr == null)
return Task.CompletedTask; return;
var beforeVch = before.VoiceChannel; var beforeVch = before.VoiceChannel;
var afterVch = after.VoiceChannel; var afterVch = after.VoiceChannel;
if (beforeVch == afterVch) if (beforeVch == afterVch)
return Task.CompletedTask; return;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| (logSetting.LogVoicePresenceId == null)) || (logSetting.LogVoicePresenceId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null) if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null)
return Task.CompletedTask; return;
string str = null; string str = null;
if (beforeVch?.Guild == afterVch?.Guild) if (beforeVch?.Guild == afterVch?.Guild)
@ -403,21 +386,26 @@ namespace NadekoBot.Modules.Administration
} }
if (str != null) if (str != null)
UserPresenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; }); UserPresenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; });
return Task.CompletedTask;
} }
catch (Exception ex)
{
_log.Warn(ex);
}
});
private Task _client_UserPresenceUpdated(IGuildUser usr, IPresence before, IPresence after) private async void _client_UserPresenceUpdated(IGuildUser usr, IPresence before, IPresence after) => await Task.Run(() =>
{
try
{ {
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| (logSetting.LogUserPresenceId == null) || (logSetting.LogUserPresenceId == null)
|| before.Status == after.Status) || before.Status == after.Status)
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserPresence)) == null) if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserPresence)) == null)
return Task.CompletedTask; return;
string str; string str;
if (before.Status != after.Status) if (before.Status != after.Status)
str = $"🔵`{prettyCurrentTime}`👤__**{usr.Username}**__ is now **{after.Status}**."; str = $"🔵`{prettyCurrentTime}`👤__**{usr.Username}**__ is now **{after.Status}**.";
@ -425,110 +413,102 @@ namespace NadekoBot.Modules.Administration
str = $"👾`{prettyCurrentTime}`👤__**{usr.Username}**__ is now playing **{after.Game}**."; str = $"👾`{prettyCurrentTime}`👤__**{usr.Username}**__ is now playing **{after.Game}**.";
UserPresenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; }); UserPresenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; });
return Task.CompletedTask;
} }
catch { }
});
private Task _client_UserLeft(IGuildUser usr) private async void _client_UserLeft(IGuildUser usr)
{
try
{ {
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| (logSetting.UserLeftId == null)) || (logSetting.UserLeftId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)) == null) if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)) == null)
return Task.CompletedTask; return;
await logChannel.SendMessageAsync($"❗️🕛`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__❌ **| USER LEFT |** 🆔 `{usr.Id}`").ConfigureAwait(false);
var task = Task.Run(async () => }
{ catch { }
try { await logChannel.SendMessageAsync($"❗️🕛`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__❌ **| USER LEFT |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private Task _client_UserJoined(IGuildUser usr) private async void _client_UserJoined(IGuildUser usr)
{
try
{ {
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| (logSetting.UserJoinedId == null)) || (logSetting.UserJoinedId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null) if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null)
return Task.CompletedTask; return;
var task = Task.Run(async () => await logChannel.SendMessageAsync($"❕🕓`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__✅ **| USER JOINED |** 🆔 `{usr.Id}`").ConfigureAwait(false);
{ }
try { await logChannel.SendMessageAsync($"❕🕓`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__✅ **| USER JOINED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private Task _client_UserUnbanned(IUser usr, IGuild guild) private async void _client_UserUnbanned(IUser usr, IGuild guild)
{
try
{ {
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|| (logSetting.UserUnbannedId == null)) || (logSetting.UserUnbannedId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null) if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null)
return Task.CompletedTask; return;
var task = Task.Run(async () => await logChannel.SendMessageAsync($"❕🕘`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__♻ **| USER UN-BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false);
{ }
try { await logChannel.SendMessageAsync($"❕🕘`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__♻ **| USER UN-BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private Task _client_UserBanned(IUser usr, IGuild guild) private async void _client_UserBanned(IUser usr, IGuild guild)
{
try
{ {
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|| (logSetting.UserBannedId == null)) || (logSetting.UserBannedId == null))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null) if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null)
return Task.CompletedTask; return;
await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🚫 **| USER BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false);
var task = Task.Run(async () => }
{ catch (Exception ex) { _log.Warn(ex); }
try { await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🚫 **| USER BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private Task _client_MessageDeleted(ulong arg1, Optional<IMessage> imsg) private async void _client_MessageDeleted(ulong arg1, Optional<IMessage> imsg)
{
try
{ {
var msg = (imsg.IsSpecified ? imsg.Value : null) as IUserMessage; var msg = (imsg.IsSpecified ? imsg.Value : null) as IUserMessage;
if (msg == null || msg.IsAuthor()) if (msg == null || msg.IsAuthor())
return Task.CompletedTask; return;
var channel = msg.Channel as ITextChannel; var channel = msg.Channel as ITextChannel;
if (channel == null) if (channel == null)
return Task.CompletedTask; return;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|| (logSetting.MessageDeletedId == null) || (logSetting.MessageDeletedId == null)
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageDeleted)) == null || logChannel.Id == msg.Id) if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageDeleted)) == null || logChannel.Id == msg.Id)
return Task.CompletedTask; return;
var task = Task.Run(async () =>
{
try
{
var str = $@"🕔`{prettyCurrentTime}`👤__**{msg.Author.Username}#{msg.Author.Discriminator}**__ **| Deleted Message |** 🆔 `{msg.Author.Id}` #⃣ `{channel.Name}` var str = $@"🕔`{prettyCurrentTime}`👤__**{msg.Author.Username}#{msg.Author.Discriminator}**__ **| Deleted Message |** 🆔 `{msg.Author.Id}` #⃣ `{channel.Name}`
🗑 {msg.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}"; 🗑 {msg.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}";
if (msg.Attachments.Any()) if (msg.Attachments.Any())
@ -536,48 +516,41 @@ namespace NadekoBot.Modules.Administration
await logChannel.SendMessageAsync(str.SanitizeMentions()).ConfigureAwait(false); await logChannel.SendMessageAsync(str.SanitizeMentions()).ConfigureAwait(false);
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private Task _client_MessageUpdated(Optional<IMessage> optmsg, IMessage imsg2) private async void _client_MessageUpdated(Optional<IMessage> optmsg, IMessage imsg2)
{
try
{ {
var after = imsg2 as IUserMessage; var after = imsg2 as IUserMessage;
if (after == null || after.IsAuthor()) if (after == null || after.IsAuthor())
return Task.CompletedTask; return;
var before = (optmsg.IsSpecified ? optmsg.Value : null) as IUserMessage; var before = (optmsg.IsSpecified ? optmsg.Value : null) as IUserMessage;
if (before == null) if (before == null)
return Task.CompletedTask; return;
var channel = after.Channel as ITextChannel; var channel = after.Channel as ITextChannel;
if (channel == null) if (channel == null)
return Task.CompletedTask; return;
if (before.Content == after.Content) if (before.Content == after.Content)
return Task.CompletedTask; return;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|| (logSetting.MessageUpdatedId == null) || (logSetting.MessageUpdatedId == null)
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
return Task.CompletedTask; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated)) == null || logChannel.Id == after.Channel.Id) if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated)) == null || logChannel.Id == after.Channel.Id)
return Task.CompletedTask; return;
await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}`👤__**{before.Author.Username}#{before.Author.Discriminator}**__ **| 📝 Edited Message |** 🆔 `{before.Author.Id}` #⃣ `{channel.Name}`
var task = Task.Run(async () =>
{
//try { await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}` **Message** 📝 `#{channel.Name}`
//👤`{before.Author.Username}`
try { await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}`👤__**{before.Author.Username}#{before.Author.Discriminator}**__ **| 📝 Edited Message |** 🆔 `{before.Author.Id}` #⃣ `{channel.Name}`
`Old:` {before.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()} `Old:` {before.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}
**`New:`** {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } **`New:`** {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}").ConfigureAwait(false);
}); }
catch (Exception ex) { _log.Warn(ex); }
return Task.CompletedTask;
} }
public enum LogType public enum LogType

View File

@ -24,8 +24,8 @@ namespace NadekoBot.Modules.Administration
private static ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>> MutedUsers { get; } = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>(); private static ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>> MutedUsers { get; } = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>();
public static event Func<IGuildUser, MuteType, Task> UserMuted = delegate { return Task.CompletedTask; }; public static event Action<IGuildUser, MuteType> UserMuted = delegate { };
public static event Func<IGuildUser, MuteType, Task> UserUnmuted = delegate { return Task.CompletedTask; }; public static event Action<IGuildUser, MuteType> UserUnmuted = delegate { };
public enum MuteType { public enum MuteType {
@ -51,7 +51,9 @@ namespace NadekoBot.Modules.Administration
NadekoBot.Client.UserJoined += Client_UserJoined; NadekoBot.Client.UserJoined += Client_UserJoined;
} }
private static async Task Client_UserJoined(IGuildUser usr) private static async void Client_UserJoined(IGuildUser usr)
{
try
{ {
ConcurrentHashSet<ulong> muted; ConcurrentHashSet<ulong> muted;
MutedUsers.TryGetValue(usr.Guild.Id, out muted); MutedUsers.TryGetValue(usr.Guild.Id, out muted);
@ -60,6 +62,11 @@ namespace NadekoBot.Modules.Administration
return; return;
else else
await Mute(usr).ConfigureAwait(false); await Mute(usr).ConfigureAwait(false);
}
catch (Exception ex)
{
_log.Warn(ex);
}
} }
@ -80,7 +87,7 @@ namespace NadekoBot.Modules.Administration
await uow.CompleteAsync().ConfigureAwait(false); await uow.CompleteAsync().ConfigureAwait(false);
} }
await UserMuted(usr, MuteType.All).ConfigureAwait(false); UserMuted(usr, MuteType.All);
} }
public static async Task Unmute(IGuildUser usr) public static async Task Unmute(IGuildUser usr)
@ -99,7 +106,7 @@ namespace NadekoBot.Modules.Administration
muted.TryRemove(usr.Id); muted.TryRemove(usr.Id);
await uow.CompleteAsync().ConfigureAwait(false); await uow.CompleteAsync().ConfigureAwait(false);
} }
await UserUnmuted(usr, MuteType.All).ConfigureAwait(false); UserUnmuted(usr, MuteType.All);
} }
public static async Task<IRole> GetMuteRole(IGuild guild) public static async Task<IRole> GetMuteRole(IGuild guild)
@ -211,7 +218,7 @@ namespace NadekoBot.Modules.Administration
try try
{ {
await user.AddRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false); await user.AddRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false);
await UserMuted(user, MuteType.Chat).ConfigureAwait(false); UserMuted(user, MuteType.Chat);
await channel.SendConfirmAsync($"✏️🚫 **{user}** has been **muted** from chatting.").ConfigureAwait(false); await channel.SendConfirmAsync($"✏️🚫 **{user}** has been **muted** from chatting.").ConfigureAwait(false);
} }
catch catch
@ -230,7 +237,7 @@ namespace NadekoBot.Modules.Administration
try try
{ {
await user.RemoveRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false); await user.RemoveRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false);
await UserUnmuted(user, MuteType.Chat).ConfigureAwait(false); UserUnmuted(user, MuteType.Chat);
await channel.SendConfirmAsync($"✏️✅ **{user}** has been **unmuted** from chatting.").ConfigureAwait(false); await channel.SendConfirmAsync($"✏️✅ **{user}** has been **unmuted** from chatting.").ConfigureAwait(false);
} }
catch catch
@ -249,7 +256,7 @@ namespace NadekoBot.Modules.Administration
try try
{ {
await user.ModifyAsync(usr => usr.Mute = true).ConfigureAwait(false); await user.ModifyAsync(usr => usr.Mute = true).ConfigureAwait(false);
await UserMuted(user, MuteType.Voice).ConfigureAwait(false); UserMuted(user, MuteType.Voice);
await channel.SendConfirmAsync($"🎙🚫 **{user}** has been **voice muted**.").ConfigureAwait(false); await channel.SendConfirmAsync($"🎙🚫 **{user}** has been **voice muted**.").ConfigureAwait(false);
} }
catch catch
@ -267,7 +274,7 @@ namespace NadekoBot.Modules.Administration
try try
{ {
await user.ModifyAsync(usr => usr.Mute = false).ConfigureAwait(false); await user.ModifyAsync(usr => usr.Mute = false).ConfigureAwait(false);
await UserUnmuted(user, MuteType.Voice).ConfigureAwait(false); UserUnmuted(user, MuteType.Voice);
await channel.SendConfirmAsync($"🎙✅ **{user}** has been **voice unmuted**.").ConfigureAwait(false); await channel.SendConfirmAsync($"🎙✅ **{user}** has been **voice unmuted**.").ConfigureAwait(false);
} }
catch catch

View File

@ -79,7 +79,7 @@ namespace NadekoBot.Modules.Administration
if (limiter.CheckUserRatelimit(usrMsg.Author.Id)) if (limiter.CheckUserRatelimit(usrMsg.Author.Id))
try { await usrMsg.DeleteAsync(); } catch (Exception ex) { _log.Warn(ex); } try { await usrMsg.DeleteAsync(); } catch (Exception ex) { _log.Warn(ex); }
}); });
return Task.CompletedTask; return;
}; };
} }

View File

@ -25,10 +25,8 @@ namespace NadekoBot.Modules.Administration
NadekoBot.Client.UserLeft += UserLeft; NadekoBot.Client.UserLeft += UserLeft;
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
} }
//todo optimize ASAP
private static Task UserLeft(IGuildUser user) private static async void UserLeft(IGuildUser user)
{
var leftTask = Task.Run(async () =>
{ {
try try
{ {
@ -58,13 +56,9 @@ namespace NadekoBot.Modules.Administration
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
} }
catch { } catch { }
});
return Task.CompletedTask;
} }
private static Task UserJoined(IGuildUser user) private static async void UserJoined(IGuildUser user)
{
var joinedTask = Task.Run(async () =>
{ {
try try
{ {
@ -110,8 +104,6 @@ namespace NadekoBot.Modules.Administration
} }
} }
catch { } catch { }
});
return Task.CompletedTask;
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -29,15 +29,14 @@ namespace NadekoBot.Modules.Administration
NadekoBot.Client.UserVoiceStateUpdated += UserUpdatedEventHandler; NadekoBot.Client.UserVoiceStateUpdated += UserUpdatedEventHandler;
} }
private static Task UserUpdatedEventHandler(IUser iuser, IVoiceState before, IVoiceState after) private static async void UserUpdatedEventHandler(IUser iuser, IVoiceState before, IVoiceState after)
{ {
var user = (iuser as IGuildUser); var user = (iuser as IGuildUser);
var guild = user?.Guild; var guild = user?.Guild;
if (guild == null) if (guild == null)
return Task.CompletedTask; return;
var task = Task.Run(async () =>
{
try try
{ {
var botUserPerms = guild.GetCurrentUser().GuildPermissions; var botUserPerms = guild.GetCurrentUser().GuildPermissions;
@ -97,8 +96,6 @@ namespace NadekoBot.Modules.Administration
{ {
Console.WriteLine(ex); Console.WriteLine(ex);
} }
});
return Task.CompletedTask;
} }
private static string GetChannelName(string voiceName) => private static string GetChannelName(string voiceName) =>

View File

@ -209,15 +209,15 @@ namespace NadekoBot.Modules.Gambling
} }
private Task Client_MessageReceived(IMessage imsg) private void Client_MessageReceived(IMessage imsg)
{ {
var msg = imsg as IUserMessage; var msg = imsg as IUserMessage;
if (msg == null) if (msg == null)
return Task.CompletedTask; return;
if (msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel) if (msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel)
return Task.CompletedTask; return;
messagesSinceGameStarted++; messagesSinceGameStarted++;
return Task.CompletedTask; return;
} }
private async Task CheckForFullGameAsync(CancellationToken cancelToken) private async Task CheckForFullGameAsync(CancellationToken cancelToken)
@ -277,10 +277,7 @@ namespace NadekoBot.Modules.Gambling
this.AmountBet = amount; this.AmountBet = amount;
} }
public override int GetHashCode() public override int GetHashCode() => User.GetHashCode();
{
return User.GetHashCode();
}
public override bool Equals(object obj) public override bool Equals(object obj)
{ {

View File

@ -163,9 +163,7 @@ namespace NadekoBot.Modules.Games
await End().ConfigureAwait(false); await End().ConfigureAwait(false);
} }
private Task PotentialAcro(IMessage arg) private async void PotentialAcro(IMessage arg)
{
var t = Task.Run(async () =>
{ {
try try
{ {
@ -256,8 +254,6 @@ namespace NadekoBot.Modules.Games
} }
} }
catch { } catch { }
});
return Task.CompletedTask;
} }
public async Task End() public async Task End()

View File

@ -124,17 +124,15 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
await GameChannel.EmbedAsync(embed.WithOkColor().Build()).ConfigureAwait(false); await GameChannel.EmbedAsync(embed.WithOkColor().Build()).ConfigureAwait(false);
} }
private Task PotentialGuess(IMessage msg) private async void PotentialGuess(IMessage msg)
{ {
if (msg.Channel != GameChannel) if (msg.Channel != GameChannel)
return Task.CompletedTask; // message's channel has to be the same as game's return; // message's channel has to be the same as game's
if (msg.Content.Length != 1) // message must be 1 char long if (msg.Content.Length != 1) // message must be 1 char long
{ {
if (++MessagesSinceLastPost > 10) if (++MessagesSinceLastPost > 10)
{ {
MessagesSinceLastPost = 0; MessagesSinceLastPost = 0;
Task.Run(async () =>
{
try try
{ {
await GameChannel.SendConfirmAsync("Hangman Game", await GameChannel.SendConfirmAsync("Hangman Game",
@ -142,18 +140,13 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
footer: string.Join(" ", Guesses)).ConfigureAwait(false); footer: string.Join(" ", Guesses)).ConfigureAwait(false);
} }
catch { } catch { }
});
} }
return Task.CompletedTask;
} }
if (!(char.IsLetter(msg.Content[0]) || char.IsDigit(msg.Content[0])))// and a letter or a digit if (!(char.IsLetter(msg.Content[0]) || char.IsDigit(msg.Content[0])))// and a letter or a digit
return Task.CompletedTask; return;
var guess = char.ToUpperInvariant(msg.Content[0]); var guess = char.ToUpperInvariant(msg.Content[0]);
Task.Run(async () =>
{
try try
{ {
if (Guesses.Contains(guess)) if (Guesses.Contains(guess))
@ -180,8 +173,12 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
return; return;
} }
MessagesSinceLastPost = 0; MessagesSinceLastPost = 0;
try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!\n" + ScrambledWord + "\n" + GetHangman(), try
footer: string.Join(" ", Guesses)).ConfigureAwait(false); } catch { } {
await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!\n" + ScrambledWord + "\n" + GetHangman(),
footer: string.Join(" ", Guesses)).ConfigureAwait(false);
}
catch { }
} }
else else
@ -197,15 +194,9 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
} }
catch { } catch { }
});
return Task.CompletedTask;
} }
public string GetHangman() public string GetHangman() => $@"\_\_\_\_\_\_\_\_\_
{
return
$@"\_\_\_\_\_\_\_\_\_
| | | |
| | | |
{(Errors > 0 ? "😲" : " ")} | {(Errors > 0 ? "😲" : " ")} |
@ -214,4 +205,3 @@ $@"\_\_\_\_\_\_\_\_\_
/-\"; /-\";
} }
} }
}

View File

@ -57,21 +57,19 @@ namespace NadekoBot.Modules.Games
} }
} }
private static Task PotentialFlowerGeneration(IMessage imsg) private static async void PotentialFlowerGeneration(IMessage imsg)
{ {
var msg = imsg as IUserMessage; var msg = imsg as IUserMessage;
if (msg == null || msg.IsAuthor() || msg.Author.IsBot) if (msg == null || msg.IsAuthor() || msg.Author.IsBot)
return Task.CompletedTask; return;
var channel = imsg.Channel as ITextChannel; var channel = imsg.Channel as ITextChannel;
if (channel == null) if (channel == null)
return Task.CompletedTask; return;
if (!generationChannels.Contains(channel.Id)) if (!generationChannels.Contains(channel.Id))
return Task.CompletedTask; return;
var t = Task.Run(async () =>
{
var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue); var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue);
var rng = new NadekoRandom(); var rng = new NadekoRandom();
@ -94,9 +92,8 @@ namespace NadekoBot.Modules.Games
catch { } catch { }
} }
});
return Task.CompletedTask;
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Pick(IUserMessage imsg) public async Task Pick(IUserMessage imsg)

View File

@ -124,22 +124,19 @@ namespace NadekoBot.Modules.Games
} }
} }
private Task Vote(IMessage imsg) private async void Vote(IMessage imsg)
{ {
// has to be a user message // has to be a user message
var msg = imsg as IUserMessage; var msg = imsg as IUserMessage;
if (msg == null || msg.Author.IsBot) if (msg == null || msg.Author.IsBot)
return Task.CompletedTask; return;
// has to be an integer // has to be an integer
int vote; int vote;
if (!int.TryParse(imsg.Content, out vote)) if (!int.TryParse(imsg.Content, out vote))
return Task.CompletedTask; return;
if (vote < 1 || vote > answers.Length) if (vote < 1 || vote > answers.Length)
return Task.CompletedTask; return;
var t = Task.Run(async () =>
{
try try
{ {
IMessageChannel ch; IMessageChannel ch;
@ -177,8 +174,6 @@ namespace NadekoBot.Modules.Games
} }
} }
catch { } catch { }
});
return Task.CompletedTask;
} }
} }
} }

View File

@ -105,15 +105,13 @@ namespace NadekoBot.Modules.Games
NadekoBot.Client.MessageReceived += AnswerReceived; NadekoBot.Client.MessageReceived += AnswerReceived;
} }
private Task AnswerReceived(IMessage imsg) private async void AnswerReceived(IMessage imsg)
{ {
if (imsg.Author.IsBot) if (imsg.Author.IsBot)
return Task.CompletedTask; return;
var msg = imsg as IUserMessage; var msg = imsg as IUserMessage;
if (msg == null) if (msg == null)
return Task.CompletedTask; return;
var t = Task.Run(async () =>
{
try try
{ {
if (this.Channel == null || this.Channel.Id != this.Channel.Id) return; if (this.Channel == null || this.Channel.Id != this.Channel.Id) return;
@ -138,9 +136,7 @@ namespace NadekoBot.Modules.Games
} }
} }
} }
catch { } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
private bool Judge(int errors, int textLength) => errors <= textLength / 25; private bool Judge(int errors, int textLength) => errors <= textLength / 25;

View File

@ -142,15 +142,14 @@ namespace NadekoBot.Modules.Games.Trivia
try { await channel.SendConfirmAsync("Trivia Game", "Stopping after this question.").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } try { await channel.SendConfirmAsync("Trivia Game", "Stopping after this question.").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
} }
private Task PotentialGuess(IMessage imsg) private async void PotentialGuess(IMessage imsg)
{ {
if (imsg.Author.IsBot) if (imsg.Author.IsBot)
return Task.CompletedTask; return;
var umsg = imsg as IUserMessage; var umsg = imsg as IUserMessage;
if (umsg == null) if (umsg == null)
return Task.CompletedTask; return;
var t = Task.Run(async () =>
{
try try
{ {
var textChannel = umsg.Channel as ITextChannel; var textChannel = umsg.Channel as ITextChannel;
@ -174,7 +173,8 @@ namespace NadekoBot.Modules.Games.Trivia
triviaCancelSource.Cancel(); triviaCancelSource.Cancel();
if (Users[guildUser] == WinRequirement) { if (Users[guildUser] == WinRequirement)
{
ShouldStopGame = true; ShouldStopGame = true;
await channel.SendConfirmAsync("Trivia Game", $"{guildUser.Mention} guessed it and WON the game! The answer was: **{CurrentQuestion.Answer}**").ConfigureAwait(false); await channel.SendConfirmAsync("Trivia Game", $"{guildUser.Mention} guessed it and WON the game! The answer was: **{CurrentQuestion.Answer}**").ConfigureAwait(false);
return; return;
@ -183,8 +183,6 @@ namespace NadekoBot.Modules.Games.Trivia
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
} }
public string GetLeaderboard() public string GetLeaderboard()

View File

@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Music.Classes
public bool Autoplay { get; set; } = false; public bool Autoplay { get; set; } = false;
public uint MaxQueueSize { get; set; } = 0; public uint MaxQueueSize { get; set; } = 0;
private ConcurrentQueue<Action> actionQueue { get; set; } = new ConcurrentQueue<Action>(); private ConcurrentQueue<Action> actionQueue { get; } = new ConcurrentQueue<Action>();
public string PrettyVolume => $"🔉 {(int)(Volume * 100)}%"; public string PrettyVolume => $"🔉 {(int)(Volume * 100)}%";

View File

@ -36,17 +36,15 @@ namespace NadekoBot.Modules.Music
Directory.CreateDirectory(MusicDataPath); Directory.CreateDirectory(MusicDataPath);
} }
private Task Client_UserVoiceStateUpdated(IUser iusr, IVoiceState oldState, IVoiceState newState) private void Client_UserVoiceStateUpdated(IUser iusr, IVoiceState oldState, IVoiceState newState)
{ {
var usr = iusr as IGuildUser; var usr = iusr as IGuildUser;
if (usr == null || if (usr == null ||
oldState.VoiceChannel == newState.VoiceChannel) oldState.VoiceChannel == newState.VoiceChannel)
return Task.CompletedTask; return;
MusicPlayer player; MusicPlayer player;
if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player)) if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player))
return Task.CompletedTask; return;
if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause
player.Paused && player.Paused &&
player.PlaybackVoiceChannel.GetUsers().Count == 2) || // keep in mind bot is in the channel (+1) player.PlaybackVoiceChannel.GetUsers().Count == 2) || // keep in mind bot is in the channel (+1)
@ -56,7 +54,7 @@ namespace NadekoBot.Modules.Music
{ {
player.TogglePause(); player.TogglePause();
} }
return Task.CompletedTask; return;
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -28,18 +28,15 @@ namespace NadekoBot.Modules.Searches
TranslatedChannels = new ConcurrentDictionary<ulong, bool>(); TranslatedChannels = new ConcurrentDictionary<ulong, bool>();
UserLanguages = new ConcurrentDictionary<UserChannelPair, string>(); UserLanguages = new ConcurrentDictionary<UserChannelPair, string>();
NadekoBot.Client.MessageReceived += (msg) => NadekoBot.Client.MessageReceived += async (msg) =>
{ {
var umsg = msg as IUserMessage; var umsg = msg as IUserMessage;
if (umsg == null) if (umsg == null)
return Task.CompletedTask; return;
bool autoDelete; bool autoDelete;
if (!TranslatedChannels.TryGetValue(umsg.Channel.Id, out autoDelete)) if (!TranslatedChannels.TryGetValue(umsg.Channel.Id, out autoDelete))
return Task.CompletedTask; return;
var t = Task.Run(async () =>
{
var key = new UserChannelPair() var key = new UserChannelPair()
{ {
UserId = umsg.Author.Id, UserId = umsg.Author.Id,
@ -59,9 +56,6 @@ namespace NadekoBot.Modules.Searches
await umsg.Channel.SendConfirmAsync($"{umsg.Author.Mention} `:` " + text.Replace("<@ ", "<@").Replace("<@! ", "<@!")).ConfigureAwait(false); await umsg.Channel.SendConfirmAsync($"{umsg.Author.Mention} `:` " + text.Replace("<@ ", "<@").Replace("<@! ", "<@!")).ConfigureAwait(false);
} }
catch { } catch { }
});
return Task.CompletedTask;
}; };
} }

View File

@ -95,5 +95,31 @@ namespace NadekoBot.Modules.Utility
.WithOkColor(); .WithOkColor();
await msg.Channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await msg.Channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly]
public async Task Activity(IUserMessage imsg, int page = 1)
{
const int activityPerPage = 15;
page -= 1;
if (page < 0)
return;
int startCount = page * activityPerPage;
StringBuilder str = new StringBuilder();
foreach (var kvp in NadekoBot.CommandHandler.UserMessagesSent.OrderByDescending(kvp => kvp.Value).Skip(page*activityPerPage).Take(activityPerPage))
{
str.AppendLine($"`{++startCount}.` **{kvp.Key}** [{kvp.Value/NadekoBot.Stats.GetUptime().TotalSeconds:F2}/s] - {kvp.Value} total");
}
await imsg.Channel.EmbedAsync(new EmbedBuilder().WithTitle($"Activity Page #{page}")
.WithOkColor()
.WithFooter(efb => efb.WithText($"{NadekoBot.CommandHandler.UserMessagesSent.Count} users total."))
.WithDescription(str.ToString())
.Build());
}
} }
} }

View File

@ -113,6 +113,33 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to activity.
/// </summary>
public static string activity_cmd {
get {
return ResourceManager.GetString("activity_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Checks for spammers..
/// </summary>
public static string activity_desc {
get {
return ResourceManager.GetString("activity_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}activity`.
/// </summary>
public static string activity_usage {
get {
return ResourceManager.GetString("activity_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to addcustreact acr. /// Looks up a localized string similar to addcustreact acr.
/// </summary> /// </summary>

View File

@ -2835,4 +2835,13 @@
<data name="setmaxplaytime_usage" xml:space="preserve"> <data name="setmaxplaytime_usage" xml:space="preserve">
<value>`{0}smp 0` or `{0}smp 270`</value> <value>`{0}smp 0` or `{0}smp 270`</value>
</data> </data>
<data name="activity_cmd" xml:space="preserve">
<value>activity</value>
</data>
<data name="activity_desc" xml:space="preserve">
<value>Checks for spammers.</value>
</data>
<data name="activity_usage" xml:space="preserve">
<value>`{0}activity`</value>
</data>
</root> </root>

View File

@ -16,20 +16,15 @@ using NadekoBot.Modules.Help;
using static NadekoBot.Modules.Administration.Administration; using static NadekoBot.Modules.Administration.Administration;
using NadekoBot.Modules.CustomReactions; using NadekoBot.Modules.CustomReactions;
using NadekoBot.Modules.Games; using NadekoBot.Modules.Games;
using System.Collections.Concurrent;
namespace NadekoBot.Services namespace NadekoBot.Services
{ {
public class IGuildUserComparer : IEqualityComparer<IGuildUser> public class IGuildUserComparer : IEqualityComparer<IGuildUser>
{ {
public bool Equals(IGuildUser x, IGuildUser y) public bool Equals(IGuildUser x, IGuildUser y) => x.Id == y.Id;
{
return x.Id == y.Id;
}
public int GetHashCode(IGuildUser obj) public int GetHashCode(IGuildUser obj) => obj.Id.GetHashCode();
{
return obj.Id.GetHashCode();
}
} }
public class CommandHandler public class CommandHandler
{ {
@ -41,6 +36,9 @@ namespace NadekoBot.Services
public event Func<IUserMessage, Command, Task> CommandExecuted = delegate { return Task.CompletedTask; }; public event Func<IUserMessage, Command, Task> CommandExecuted = delegate { return Task.CompletedTask; };
//userid/msg count
public ConcurrentDictionary<ulong, uint> UserMessagesSent { get; } = new ConcurrentDictionary<ulong, uint>();
public CommandHandler(ShardedDiscordClient client, CommandService commandService) public CommandHandler(ShardedDiscordClient client, CommandService commandService)
{ {
_client = client; _client = client;
@ -64,17 +62,17 @@ namespace NadekoBot.Services
_client.MessageReceived += MessageReceivedHandler; _client.MessageReceived += MessageReceivedHandler;
} }
private Task MessageReceivedHandler(IMessage msg) private async void MessageReceivedHandler(IMessage msg)
{ {
var usrMsg = msg as IUserMessage; var usrMsg = msg as IUserMessage;
if (usrMsg == null) if (usrMsg == null)
return Task.CompletedTask; return;
if (!usrMsg.IsAuthor())
UserMessagesSent.AddOrUpdate(usrMsg.Author.Id, 1, (key, old) => ++old);
if (usrMsg.Author.IsBot || !NadekoBot.Ready) //no bots if (usrMsg.Author.IsBot || !NadekoBot.Ready) //no bots
return Task.CompletedTask; return;
var throwaway = Task.Run(async () =>
{
var sw = new Stopwatch(); var sw = new Stopwatch();
sw.Start(); sw.Start();
@ -208,9 +206,6 @@ namespace NadekoBot.Services
if (ex.InnerException != null) if (ex.InnerException != null)
_log.Warn(ex.InnerException, "Inner Exception of the error in CommandHandler"); _log.Warn(ex.InnerException, "Inner Exception of the error in CommandHandler");
} }
});
return Task.CompletedTask;
} }
public async Task<Tuple<Command, PermissionCache, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) { public async Task<Tuple<Command, PermissionCache, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {

View File

@ -13,20 +13,20 @@ namespace NadekoBot
private DiscordSocketConfig discordSocketConfig; private DiscordSocketConfig discordSocketConfig;
private Logger _log { get; } private Logger _log { get; }
public event Func<IGuildUser, Task> UserJoined = delegate { return Task.CompletedTask; }; public event Action<IGuildUser> UserJoined = delegate { };
public event Func<IMessage, Task> MessageReceived = delegate { return Task.CompletedTask; }; public event Action<IMessage> MessageReceived = delegate { };
public event Func<IGuildUser, Task> UserLeft = delegate { return Task.CompletedTask; }; public event Action<IGuildUser> UserLeft = delegate { };
public event Func<IGuildUser, IGuildUser, Task> UserUpdated = delegate { return Task.CompletedTask; }; public event Action<IGuildUser, IGuildUser> UserUpdated = delegate { };
public event Func<Optional<IMessage>, IMessage, Task> MessageUpdated = delegate { return Task.CompletedTask; }; public event Action<Optional<IMessage>, IMessage> MessageUpdated = delegate { };
public event Func<ulong, Optional<IMessage>, Task> MessageDeleted = delegate { return Task.CompletedTask; }; public event Action<ulong, Optional<IMessage>> MessageDeleted = delegate { };
public event Func<IUser, IGuild, Task> UserBanned = delegate { return Task.CompletedTask; }; public event Action<IUser, IGuild> UserBanned = delegate { };
public event Func<IUser, IGuild, Task> UserUnbanned = delegate { return Task.CompletedTask; }; public event Action<IUser, IGuild> UserUnbanned = delegate { };
public event Func<IGuildUser, IPresence, IPresence, Task> UserPresenceUpdated = delegate { return Task.CompletedTask; }; public event Action<IGuildUser, IPresence, IPresence> UserPresenceUpdated = delegate { };
public event Func<IUser, IVoiceState, IVoiceState, Task> UserVoiceStateUpdated = delegate { return Task.CompletedTask; }; public event Action<IUser, IVoiceState, IVoiceState> UserVoiceStateUpdated = delegate { };
public event Func<IChannel, Task> ChannelCreated = delegate { return Task.CompletedTask; }; public event Action<IChannel> ChannelCreated = delegate { };
public event Func<IChannel, Task> ChannelDestroyed = delegate { return Task.CompletedTask; }; public event Action<IChannel> ChannelDestroyed = delegate { };
public event Func<IChannel, IChannel, Task> ChannelUpdated = delegate { return Task.CompletedTask; }; public event Action<IChannel, IChannel> ChannelUpdated = delegate { };
public event Func<Exception, Task> Disconnected = delegate { return Task.CompletedTask; }; public event Action<Exception> Disconnected = delegate { };
private IReadOnlyList<DiscordSocketClient> Clients { get; } private IReadOnlyList<DiscordSocketClient> Clients { get; }
@ -41,19 +41,19 @@ namespace NadekoBot
discordSocketConfig.ShardId = i; discordSocketConfig.ShardId = i;
var client = new DiscordSocketClient(discordSocketConfig); var client = new DiscordSocketClient(discordSocketConfig);
clientList.Add(client); clientList.Add(client);
client.UserJoined += async arg1 => await UserJoined(arg1); client.UserJoined += arg1 => { UserJoined(arg1); return Task.CompletedTask; };
client.MessageReceived += async arg1 => await MessageReceived(arg1); client.MessageReceived += arg1 => { MessageReceived(arg1); return Task.CompletedTask; };
client.UserLeft += async arg1 => await UserLeft(arg1); client.UserLeft += arg1 => { UserLeft(arg1); return Task.CompletedTask; };
client.UserUpdated += async (arg1, gu2) => await UserUpdated(arg1, gu2); client.UserUpdated += (arg1, gu2) => { UserUpdated(arg1, gu2); return Task.CompletedTask; };
client.MessageUpdated += async (arg1, m2) => await MessageUpdated(arg1, m2); client.MessageUpdated += (arg1, m2) => { MessageUpdated(arg1, m2); return Task.CompletedTask; };
client.MessageDeleted += async (arg1, arg2) => await MessageDeleted(arg1, arg2); client.MessageDeleted += (arg1, arg2) => { MessageDeleted(arg1, arg2); return Task.CompletedTask; };
client.UserBanned += async (arg1, arg2) => await UserBanned(arg1, arg2); client.UserBanned += (arg1, arg2) => { UserBanned(arg1, arg2); return Task.CompletedTask; };
client.UserUnbanned += async (arg1, arg2) => await UserUnbanned(arg1, arg2); client.UserUnbanned += (arg1, arg2) => { UserUnbanned(arg1, arg2); return Task.CompletedTask; };
client.UserPresenceUpdated += async (arg1, arg2, arg3) => await UserPresenceUpdated(arg1, arg2, arg3); client.UserPresenceUpdated += (arg1, arg2, arg3) => { UserPresenceUpdated(arg1, arg2, arg3); return Task.CompletedTask; };
client.UserVoiceStateUpdated += async (arg1, arg2, arg3) => await UserVoiceStateUpdated(arg1, arg2, arg3); client.UserVoiceStateUpdated += (arg1, arg2, arg3) => { UserVoiceStateUpdated(arg1, arg2, arg3); return Task.CompletedTask; };
client.ChannelCreated += async arg => await ChannelCreated(arg); client.ChannelCreated += arg => { ChannelCreated(arg); return Task.CompletedTask; };
client.ChannelDestroyed += async arg => await ChannelDestroyed(arg); client.ChannelDestroyed += arg => { ChannelDestroyed(arg); return Task.CompletedTask; };
client.ChannelUpdated += async (arg1, arg2) => await ChannelUpdated(arg1, arg2); client.ChannelUpdated += (arg1, arg2) => { ChannelUpdated(arg1, arg2); return Task.CompletedTask; };
_log.Info($"Shard #{i} initialized."); _log.Info($"Shard #{i} initialized.");
} }