Huge amounts of changes, hopefully nothing broken
This commit is contained in:
parent
84703f4bf0
commit
3a68a8b4f6
@ -85,11 +85,11 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
var msg = imsg as IUserMessage;
|
||||
if (msg == null || msg.Author.IsBot)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
@ -113,20 +113,18 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
};
|
||||
|
||||
NadekoBot.Client.UserJoined += (usr) =>
|
||||
NadekoBot.Client.UserJoined += async (usr) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (usr.IsBot)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return;
|
||||
AntiRaidSetting settings;
|
||||
if (!antiRaidGuilds.TryGetValue(usr.Guild.Id, out settings))
|
||||
return Task.CompletedTask;
|
||||
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
return;
|
||||
if (!settings.RaidUsers.Add(usr))
|
||||
return;
|
||||
|
||||
@ -143,9 +141,9 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
settings.RaidUsers.TryRemove(usr);
|
||||
--settings.UsersCount;
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch { }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,7 @@ namespace NadekoBot.Modules.Administration
|
||||
AutoAssignedRoles = new ConcurrentDictionary<ulong, ulong>(NadekoBot.AllGuildConfigs.Where(x => x.AutoAssignRoleId != 0)
|
||||
.ToDictionary(k => k.GuildId, v => v.AutoAssignRoleId));
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
NadekoBot.Client.UserJoined += (user) =>
|
||||
{
|
||||
var t = Task.Run(async () =>
|
||||
NadekoBot.Client.UserJoined += async (user) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -44,8 +42,6 @@ namespace NadekoBot.Modules.Administration
|
||||
await user.AddRolesAsync(role).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -19,21 +19,18 @@ namespace NadekoBot.Modules.Administration
|
||||
static CrossServerTextChannel()
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
NadekoBot.Client.MessageReceived += (imsg) =>
|
||||
NadekoBot.Client.MessageReceived += async (imsg) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (imsg.Author.IsBot)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return;
|
||||
var msg = imsg as IUserMessage;
|
||||
if (msg == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return;
|
||||
var channel = imsg.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
return;
|
||||
if (msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return;
|
||||
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); }
|
||||
}
|
||||
}
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
_log.Warn(ex);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -86,26 +86,28 @@ namespace NadekoBot.Modules.Administration
|
||||
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;
|
||||
if (usr == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var beforeVch = before.VoiceChannel;
|
||||
var afterVch = after.VoiceChannel;
|
||||
|
||||
if (beforeVch == afterVch)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| (logSetting.LogVoicePresenceTTSId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
string str = null;
|
||||
if (beforeVch?.Guild == afterVch?.Guild)
|
||||
@ -120,33 +122,24 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
str = $"{usr.Username} has left {beforeVch.Name}";
|
||||
}
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var toDelete = await logChannel.SendMessageAsync(str, true).ConfigureAwait(false);
|
||||
toDelete.DeleteAfter(5);
|
||||
}
|
||||
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;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| (logSetting.UserMutedId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
return;
|
||||
string mutes = "";
|
||||
switch (muteType)
|
||||
{
|
||||
@ -160,25 +153,24 @@ namespace NadekoBot.Modules.Administration
|
||||
mutes = "text and voice chat";
|
||||
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); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🔇 **| User muted from the {mutes}. |** 🆔 `{usr.Id}`").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
private Task MuteCommands_UserUnmuted(IGuildUser usr, MuteCommands.MuteType muteType)
|
||||
private async void MuteCommands_UserUnmuted(IGuildUser usr, MuteCommands.MuteType muteType)
|
||||
{
|
||||
try
|
||||
{
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| (logSetting.UserMutedId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
string mutes = "";
|
||||
switch (muteType)
|
||||
{
|
||||
@ -192,13 +184,14 @@ namespace NadekoBot.Modules.Administration
|
||||
mutes = "text and voice chat";
|
||||
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); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🔊 **| User unmuted from the {mutes}. |** 🆔 `{usr.Id}`").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
public static async Task TriggeredAntiProtection(IGuildUser[] users, PunishmentAction action, ProtectionType protection)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (users.Length == 0)
|
||||
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.")))
|
||||
.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;
|
||||
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting)
|
||||
|| (logSetting.UserUpdatedId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return;
|
||||
string str = $"🕔`{prettyCurrentTime}`";
|
||||
if (before.Username != after.Username)
|
||||
//str += $"**Name Changed**`{before.Username}#{before.Discriminator}`\n\t\t`New:`{after.ToString()}`";
|
||||
@ -276,33 +268,27 @@ namespace NadekoBot.Modules.Administration
|
||||
return;
|
||||
try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
private Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
|
||||
private async void _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var before = cbefore as IGuildChannel;
|
||||
if (before == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
var after = (IGuildChannel)cafter;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting)
|
||||
|| (logSetting.ChannelUpdatedId == null)
|
||||
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == after.Id))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return;
|
||||
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})`
|
||||
@ -314,79 +300,76 @@ namespace NadekoBot.Modules.Administration
|
||||
`Old:` {((ITextChannel)before).Topic}
|
||||
**`New:`** {((ITextChannel)after).Topic}").ConfigureAwait(false);
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
private Task _client_ChannelDestroyed(IChannel ich)
|
||||
private async void _client_ChannelDestroyed(IChannel ich)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ch = ich as IGuildChannel;
|
||||
if (ch == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting)
|
||||
|| (logSetting.ChannelDestroyedId == null)
|
||||
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == ch.Id))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
try { await logChannel.SendMessageAsync($"🕕`{prettyCurrentTime}`🗑 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Deleted #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
await logChannel.SendMessageAsync($"🕕`{prettyCurrentTime}`🗑 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Deleted #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
private Task _client_ChannelCreated(IChannel ich)
|
||||
private async void _client_ChannelCreated(IChannel ich)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ch = ich as IGuildChannel;
|
||||
if (ch == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting)
|
||||
|| (logSetting.ChannelCreatedId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
try { await logChannel.SendMessageAsync($"🕓`{prettyCurrentTime}`🆕 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Created: #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
await logChannel.SendMessageAsync($"🕓`{prettyCurrentTime}`🆕 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Created: #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
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;
|
||||
if (usr == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var beforeVch = before.VoiceChannel;
|
||||
var afterVch = after.VoiceChannel;
|
||||
|
||||
if (beforeVch == afterVch)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| (logSetting.LogVoicePresenceId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
string str = null;
|
||||
if (beforeVch?.Guild == afterVch?.Guild)
|
||||
@ -403,21 +386,26 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
if (str != null)
|
||||
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;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| (logSetting.LogUserPresenceId == null)
|
||||
|| before.Status == after.Status)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserPresence)) == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
string str;
|
||||
if (before.Status != 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}**.";
|
||||
|
||||
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;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| (logSetting.UserLeftId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)) == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
try { await logChannel.SendMessageAsync($"❗️🕛`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__❌ **| USER LEFT |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
await logChannel.SendMessageAsync($"❗️🕛`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__❌ **| USER LEFT |** 🆔 `{usr.Id}`").ConfigureAwait(false);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private Task _client_UserJoined(IGuildUser usr)
|
||||
private async void _client_UserJoined(IGuildUser usr)
|
||||
{
|
||||
try
|
||||
{
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| (logSetting.UserJoinedId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
try { await logChannel.SendMessageAsync($"❕🕓`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__✅ **| USER JOINED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
await logChannel.SendMessageAsync($"❕🕓`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__✅ **| USER JOINED |** 🆔 `{usr.Id}`").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
private Task _client_UserUnbanned(IUser usr, IGuild guild)
|
||||
private async void _client_UserUnbanned(IUser usr, IGuild guild)
|
||||
{
|
||||
try
|
||||
{
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|
||||
|| (logSetting.UserUnbannedId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
try { await logChannel.SendMessageAsync($"❕🕘`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__♻️ **| USER UN-BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
await logChannel.SendMessageAsync($"❕🕘`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__♻️ **| USER UN-BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
private Task _client_UserBanned(IUser usr, IGuild guild)
|
||||
private async void _client_UserBanned(IUser usr, IGuild guild)
|
||||
{
|
||||
try
|
||||
{
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|
||||
|| (logSetting.UserBannedId == null))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
try { await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🚫 **| USER BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🚫 **| USER BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
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;
|
||||
if (msg == null || msg.IsAuthor())
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
|| (logSetting.MessageDeletedId == null)
|
||||
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageDeleted)) == null || logChannel.Id == msg.Id)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return;
|
||||
var str = $@"🕔`{prettyCurrentTime}`👤__**{msg.Author.Username}#{msg.Author.Discriminator}**__ **| Deleted Message |** 🆔 `{msg.Author.Id}` #⃣ `{channel.Name}`
|
||||
🗑 {msg.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}";
|
||||
if (msg.Attachments.Any())
|
||||
@ -536,48 +516,41 @@ namespace NadekoBot.Modules.Administration
|
||||
await logChannel.SendMessageAsync(str.SanitizeMentions()).ConfigureAwait(false);
|
||||
}
|
||||
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;
|
||||
if (after == null || after.IsAuthor())
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var before = (optmsg.IsSpecified ? optmsg.Value : null) as IUserMessage;
|
||||
if (before == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var channel = after.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
if (before.Content == after.Content)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
|| (logSetting.MessageUpdatedId == null)
|
||||
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated)) == null || logChannel.Id == after.Channel.Id)
|
||||
return Task.CompletedTask;
|
||||
|
||||
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}`
|
||||
return;
|
||||
await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}`👤__**{before.Author.Username}#{before.Author.Discriminator}**__ **| 📝 Edited Message |** 🆔 `{before.Author.Id}` #⃣ `{channel.Name}`
|
||||
`Old:` {before.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}
|
||||
**`New:`** {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
**`New:`** {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
public enum LogType
|
||||
|
@ -24,8 +24,8 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
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 Func<IGuildUser, MuteType, Task> UserUnmuted = delegate { return Task.CompletedTask; };
|
||||
public static event Action<IGuildUser, MuteType> UserMuted = delegate { };
|
||||
public static event Action<IGuildUser, MuteType> UserUnmuted = delegate { };
|
||||
|
||||
|
||||
public enum MuteType {
|
||||
@ -51,7 +51,9 @@ namespace NadekoBot.Modules.Administration
|
||||
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;
|
||||
MutedUsers.TryGetValue(usr.Guild.Id, out muted);
|
||||
@ -60,6 +62,11 @@ namespace NadekoBot.Modules.Administration
|
||||
return;
|
||||
else
|
||||
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 UserMuted(usr, MuteType.All).ConfigureAwait(false);
|
||||
UserMuted(usr, MuteType.All);
|
||||
}
|
||||
|
||||
public static async Task Unmute(IGuildUser usr)
|
||||
@ -99,7 +106,7 @@ namespace NadekoBot.Modules.Administration
|
||||
muted.TryRemove(usr.Id);
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
await UserUnmuted(usr, MuteType.All).ConfigureAwait(false);
|
||||
UserUnmuted(usr, MuteType.All);
|
||||
}
|
||||
|
||||
public static async Task<IRole> GetMuteRole(IGuild guild)
|
||||
@ -211,7 +218,7 @@ namespace NadekoBot.Modules.Administration
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch
|
||||
@ -230,7 +237,7 @@ namespace NadekoBot.Modules.Administration
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch
|
||||
@ -249,7 +256,7 @@ namespace NadekoBot.Modules.Administration
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch
|
||||
@ -267,7 +274,7 @@ namespace NadekoBot.Modules.Administration
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch
|
||||
|
@ -79,7 +79,7 @@ namespace NadekoBot.Modules.Administration
|
||||
if (limiter.CheckUserRatelimit(usrMsg.Author.Id))
|
||||
try { await usrMsg.DeleteAsync(); } catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -25,10 +25,8 @@ namespace NadekoBot.Modules.Administration
|
||||
NadekoBot.Client.UserLeft += UserLeft;
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
||||
private static Task UserLeft(IGuildUser user)
|
||||
{
|
||||
var leftTask = Task.Run(async () =>
|
||||
//todo optimize ASAP
|
||||
private static async void UserLeft(IGuildUser user)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -58,13 +56,9 @@ namespace NadekoBot.Modules.Administration
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static Task UserJoined(IGuildUser user)
|
||||
{
|
||||
var joinedTask = Task.Run(async () =>
|
||||
private static async void UserJoined(IGuildUser user)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -110,8 +104,6 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
|
@ -29,15 +29,14 @@ namespace NadekoBot.Modules.Administration
|
||||
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 guild = user?.Guild;
|
||||
|
||||
if (guild == null)
|
||||
return Task.CompletedTask;
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var botUserPerms = guild.GetCurrentUser().GuildPermissions;
|
||||
@ -97,8 +96,6 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static string GetChannelName(string voiceName) =>
|
||||
|
@ -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;
|
||||
if (msg == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
if (msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
messagesSinceGameStarted++;
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
private async Task CheckForFullGameAsync(CancellationToken cancelToken)
|
||||
@ -277,10 +277,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
this.AmountBet = amount;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return User.GetHashCode();
|
||||
}
|
||||
public override int GetHashCode() => User.GetHashCode();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
@ -163,9 +163,7 @@ namespace NadekoBot.Modules.Games
|
||||
await End().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private Task PotentialAcro(IMessage arg)
|
||||
{
|
||||
var t = Task.Run(async () =>
|
||||
private async void PotentialAcro(IMessage arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -256,8 +254,6 @@ namespace NadekoBot.Modules.Games
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task End()
|
||||
|
@ -124,17 +124,15 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
|
||||
await GameChannel.EmbedAsync(embed.WithOkColor().Build()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private Task PotentialGuess(IMessage msg)
|
||||
private async void PotentialGuess(IMessage msg)
|
||||
{
|
||||
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 (++MessagesSinceLastPost > 10)
|
||||
{
|
||||
MessagesSinceLastPost = 0;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await GameChannel.SendConfirmAsync("Hangman Game",
|
||||
@ -142,18 +140,13 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
|
||||
footer: string.Join(" ", Guesses)).ConfigureAwait(false);
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Guesses.Contains(guess))
|
||||
@ -180,8 +173,12 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
|
||||
return;
|
||||
}
|
||||
MessagesSinceLastPost = 0;
|
||||
try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!\n" + ScrambledWord + "\n" + GetHangman(),
|
||||
footer: string.Join(" ", Guesses)).ConfigureAwait(false); } catch { }
|
||||
try
|
||||
{
|
||||
await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!\n" + ScrambledWord + "\n" + GetHangman(),
|
||||
footer: string.Join(" ", Guesses)).ConfigureAwait(false);
|
||||
}
|
||||
catch { }
|
||||
|
||||
}
|
||||
else
|
||||
@ -197,15 +194,9 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
|
||||
|
||||
}
|
||||
catch { }
|
||||
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public string GetHangman()
|
||||
{
|
||||
return
|
||||
$@"\_\_\_\_\_\_\_\_\_
|
||||
public string GetHangman() => $@"\_\_\_\_\_\_\_\_\_
|
||||
| |
|
||||
| |
|
||||
{(Errors > 0 ? "😲" : " ")} |
|
||||
@ -214,4 +205,3 @@ $@"\_\_\_\_\_\_\_\_\_
|
||||
/-\";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
if (msg == null || msg.IsAuthor() || msg.Author.IsBot)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var channel = imsg.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
if (!generationChannels.Contains(channel.Id))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue);
|
||||
var rng = new NadekoRandom();
|
||||
|
||||
@ -94,9 +92,8 @@ namespace NadekoBot.Modules.Games
|
||||
catch { }
|
||||
|
||||
}
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Pick(IUserMessage imsg)
|
||||
|
@ -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
|
||||
var msg = imsg as IUserMessage;
|
||||
if (msg == null || msg.Author.IsBot)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
// has to be an integer
|
||||
int vote;
|
||||
if (!int.TryParse(imsg.Content, out vote))
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
if (vote < 1 || vote > answers.Length)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
return;
|
||||
try
|
||||
{
|
||||
IMessageChannel ch;
|
||||
@ -177,8 +174,6 @@ namespace NadekoBot.Modules.Games
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@ -105,15 +105,13 @@ namespace NadekoBot.Modules.Games
|
||||
NadekoBot.Client.MessageReceived += AnswerReceived;
|
||||
}
|
||||
|
||||
private Task AnswerReceived(IMessage imsg)
|
||||
private async void AnswerReceived(IMessage imsg)
|
||||
{
|
||||
if (imsg.Author.IsBot)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
var msg = imsg as IUserMessage;
|
||||
if (msg == null)
|
||||
return Task.CompletedTask;
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
return;
|
||||
try
|
||||
{
|
||||
if (this.Channel == null || this.Channel.Id != this.Channel.Id) return;
|
||||
@ -138,9 +136,7 @@ namespace NadekoBot.Modules.Games
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
|
||||
private bool Judge(int errors, int textLength) => errors <= textLength / 25;
|
||||
|
@ -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); }
|
||||
}
|
||||
|
||||
private Task PotentialGuess(IMessage imsg)
|
||||
private async void PotentialGuess(IMessage imsg)
|
||||
{
|
||||
if (imsg.Author.IsBot)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
var umsg = imsg as IUserMessage;
|
||||
if (umsg == null)
|
||||
return Task.CompletedTask;
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
return;
|
||||
try
|
||||
{
|
||||
var textChannel = umsg.Channel as ITextChannel;
|
||||
@ -174,7 +173,8 @@ namespace NadekoBot.Modules.Games.Trivia
|
||||
triviaCancelSource.Cancel();
|
||||
|
||||
|
||||
if (Users[guildUser] == WinRequirement) {
|
||||
if (Users[guildUser] == WinRequirement)
|
||||
{
|
||||
ShouldStopGame = true;
|
||||
await channel.SendConfirmAsync("Trivia Game", $"{guildUser.Mention} guessed it and WON the game! The answer was: **{CurrentQuestion.Answer}**").ConfigureAwait(false);
|
||||
return;
|
||||
@ -183,8 +183,6 @@ namespace NadekoBot.Modules.Games.Trivia
|
||||
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public string GetLeaderboard()
|
||||
|
@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Music.Classes
|
||||
public bool Autoplay { get; set; } = false;
|
||||
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)}%";
|
||||
|
||||
|
@ -36,17 +36,15 @@ namespace NadekoBot.Modules.Music
|
||||
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;
|
||||
if (usr == null ||
|
||||
oldState.VoiceChannel == newState.VoiceChannel)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return;
|
||||
MusicPlayer 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
|
||||
player.Paused &&
|
||||
player.PlaybackVoiceChannel.GetUsers().Count == 2) || // keep in mind bot is in the channel (+1)
|
||||
@ -56,7 +54,7 @@ namespace NadekoBot.Modules.Music
|
||||
{
|
||||
player.TogglePause();
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
|
@ -28,18 +28,15 @@ namespace NadekoBot.Modules.Searches
|
||||
TranslatedChannels = new ConcurrentDictionary<ulong, bool>();
|
||||
UserLanguages = new ConcurrentDictionary<UserChannelPair, string>();
|
||||
|
||||
NadekoBot.Client.MessageReceived += (msg) =>
|
||||
NadekoBot.Client.MessageReceived += async (msg) =>
|
||||
{
|
||||
var umsg = msg as IUserMessage;
|
||||
if (umsg == null)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
bool autoDelete;
|
||||
if (!TranslatedChannels.TryGetValue(umsg.Channel.Id, out autoDelete))
|
||||
return Task.CompletedTask;
|
||||
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
return;
|
||||
var key = new UserChannelPair()
|
||||
{
|
||||
UserId = umsg.Author.Id,
|
||||
@ -59,9 +56,6 @@ namespace NadekoBot.Modules.Searches
|
||||
await umsg.Channel.SendConfirmAsync($"{umsg.Author.Mention} `:` " + text.Replace("<@ ", "<@").Replace("<@! ", "<@!")).ConfigureAwait(false);
|
||||
}
|
||||
catch { }
|
||||
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -95,5 +95,31 @@ namespace NadekoBot.Modules.Utility
|
||||
.WithOkColor();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -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>
|
||||
/// Looks up a localized string similar to addcustreact acr.
|
||||
/// </summary>
|
||||
|
@ -2835,4 +2835,13 @@
|
||||
<data name="setmaxplaytime_usage" xml:space="preserve">
|
||||
<value>`{0}smp 0` or `{0}smp 270`</value>
|
||||
</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>
|
@ -16,20 +16,15 @@ using NadekoBot.Modules.Help;
|
||||
using static NadekoBot.Modules.Administration.Administration;
|
||||
using NadekoBot.Modules.CustomReactions;
|
||||
using NadekoBot.Modules.Games;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
public class IGuildUserComparer : IEqualityComparer<IGuildUser>
|
||||
{
|
||||
public bool Equals(IGuildUser x, IGuildUser y)
|
||||
{
|
||||
return x.Id == y.Id;
|
||||
}
|
||||
public bool Equals(IGuildUser x, IGuildUser y) => x.Id == y.Id;
|
||||
|
||||
public int GetHashCode(IGuildUser obj)
|
||||
{
|
||||
return obj.Id.GetHashCode();
|
||||
}
|
||||
public int GetHashCode(IGuildUser obj) => obj.Id.GetHashCode();
|
||||
}
|
||||
public class CommandHandler
|
||||
{
|
||||
@ -41,6 +36,9 @@ namespace NadekoBot.Services
|
||||
|
||||
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)
|
||||
{
|
||||
_client = client;
|
||||
@ -64,17 +62,17 @@ namespace NadekoBot.Services
|
||||
_client.MessageReceived += MessageReceivedHandler;
|
||||
}
|
||||
|
||||
private Task MessageReceivedHandler(IMessage msg)
|
||||
private async void MessageReceivedHandler(IMessage msg)
|
||||
{
|
||||
var usrMsg = msg as IUserMessage;
|
||||
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
|
||||
return Task.CompletedTask;
|
||||
|
||||
var throwaway = Task.Run(async () =>
|
||||
{
|
||||
return;
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
@ -208,9 +206,6 @@ namespace NadekoBot.Services
|
||||
if (ex.InnerException != null)
|
||||
_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) {
|
||||
|
@ -13,20 +13,20 @@ namespace NadekoBot
|
||||
private DiscordSocketConfig discordSocketConfig;
|
||||
private Logger _log { get; }
|
||||
|
||||
public event Func<IGuildUser, Task> UserJoined = delegate { return Task.CompletedTask; };
|
||||
public event Func<IMessage, Task> MessageReceived = delegate { return Task.CompletedTask; };
|
||||
public event Func<IGuildUser, Task> UserLeft = delegate { return Task.CompletedTask; };
|
||||
public event Func<IGuildUser, IGuildUser, Task> UserUpdated = delegate { return Task.CompletedTask; };
|
||||
public event Func<Optional<IMessage>, IMessage, Task> MessageUpdated = delegate { return Task.CompletedTask; };
|
||||
public event Func<ulong, Optional<IMessage>, Task> MessageDeleted = delegate { return Task.CompletedTask; };
|
||||
public event Func<IUser, IGuild, Task> UserBanned = delegate { return Task.CompletedTask; };
|
||||
public event Func<IUser, IGuild, Task> UserUnbanned = delegate { return Task.CompletedTask; };
|
||||
public event Func<IGuildUser, IPresence, IPresence, Task> UserPresenceUpdated = delegate { return Task.CompletedTask; };
|
||||
public event Func<IUser, IVoiceState, IVoiceState, Task> UserVoiceStateUpdated = delegate { return Task.CompletedTask; };
|
||||
public event Func<IChannel, Task> ChannelCreated = delegate { return Task.CompletedTask; };
|
||||
public event Func<IChannel, Task> ChannelDestroyed = delegate { return Task.CompletedTask; };
|
||||
public event Func<IChannel, IChannel, Task> ChannelUpdated = delegate { return Task.CompletedTask; };
|
||||
public event Func<Exception, Task> Disconnected = delegate { return Task.CompletedTask; };
|
||||
public event Action<IGuildUser> UserJoined = delegate { };
|
||||
public event Action<IMessage> MessageReceived = delegate { };
|
||||
public event Action<IGuildUser> UserLeft = delegate { };
|
||||
public event Action<IGuildUser, IGuildUser> UserUpdated = delegate { };
|
||||
public event Action<Optional<IMessage>, IMessage> MessageUpdated = delegate { };
|
||||
public event Action<ulong, Optional<IMessage>> MessageDeleted = delegate { };
|
||||
public event Action<IUser, IGuild> UserBanned = delegate { };
|
||||
public event Action<IUser, IGuild> UserUnbanned = delegate { };
|
||||
public event Action<IGuildUser, IPresence, IPresence> UserPresenceUpdated = delegate { };
|
||||
public event Action<IUser, IVoiceState, IVoiceState> UserVoiceStateUpdated = delegate { };
|
||||
public event Action<IChannel> ChannelCreated = delegate { };
|
||||
public event Action<IChannel> ChannelDestroyed = delegate { };
|
||||
public event Action<IChannel, IChannel> ChannelUpdated = delegate { };
|
||||
public event Action<Exception> Disconnected = delegate { };
|
||||
|
||||
private IReadOnlyList<DiscordSocketClient> Clients { get; }
|
||||
|
||||
@ -41,19 +41,19 @@ namespace NadekoBot
|
||||
discordSocketConfig.ShardId = i;
|
||||
var client = new DiscordSocketClient(discordSocketConfig);
|
||||
clientList.Add(client);
|
||||
client.UserJoined += async arg1 => await UserJoined(arg1);
|
||||
client.MessageReceived += async arg1 => await MessageReceived(arg1);
|
||||
client.UserLeft += async arg1 => await UserLeft(arg1);
|
||||
client.UserUpdated += async (arg1, gu2) => await UserUpdated(arg1, gu2);
|
||||
client.MessageUpdated += async (arg1, m2) => await MessageUpdated(arg1, m2);
|
||||
client.MessageDeleted += async (arg1, arg2) => await MessageDeleted(arg1, arg2);
|
||||
client.UserBanned += async (arg1, arg2) => await UserBanned(arg1, arg2);
|
||||
client.UserUnbanned += async (arg1, arg2) => await UserUnbanned(arg1, arg2);
|
||||
client.UserPresenceUpdated += async (arg1, arg2, arg3) => await UserPresenceUpdated(arg1, arg2, arg3);
|
||||
client.UserVoiceStateUpdated += async (arg1, arg2, arg3) => await UserVoiceStateUpdated(arg1, arg2, arg3);
|
||||
client.ChannelCreated += async arg => await ChannelCreated(arg);
|
||||
client.ChannelDestroyed += async arg => await ChannelDestroyed(arg);
|
||||
client.ChannelUpdated += async (arg1, arg2) => await ChannelUpdated(arg1, arg2);
|
||||
client.UserJoined += arg1 => { UserJoined(arg1); return Task.CompletedTask; };
|
||||
client.MessageReceived += arg1 => { MessageReceived(arg1); return Task.CompletedTask; };
|
||||
client.UserLeft += arg1 => { UserLeft(arg1); return Task.CompletedTask; };
|
||||
client.UserUpdated += (arg1, gu2) => { UserUpdated(arg1, gu2); return Task.CompletedTask; };
|
||||
client.MessageUpdated += (arg1, m2) => { MessageUpdated(arg1, m2); return Task.CompletedTask; };
|
||||
client.MessageDeleted += (arg1, arg2) => { MessageDeleted(arg1, arg2); return Task.CompletedTask; };
|
||||
client.UserBanned += (arg1, arg2) => { UserBanned(arg1, arg2); return Task.CompletedTask; };
|
||||
client.UserUnbanned += (arg1, arg2) => { UserUnbanned(arg1, arg2); return Task.CompletedTask; };
|
||||
client.UserPresenceUpdated += (arg1, arg2, arg3) => { UserPresenceUpdated(arg1, arg2, arg3); return Task.CompletedTask; };
|
||||
client.UserVoiceStateUpdated += (arg1, arg2, arg3) => { UserVoiceStateUpdated(arg1, arg2, arg3); return Task.CompletedTask; };
|
||||
client.ChannelCreated += arg => { ChannelCreated(arg); return Task.CompletedTask; };
|
||||
client.ChannelDestroyed += arg => { ChannelDestroyed(arg); return Task.CompletedTask; };
|
||||
client.ChannelUpdated += (arg1, arg2) => { ChannelUpdated(arg1, arg2); return Task.CompletedTask; };
|
||||
|
||||
_log.Info($"Shard #{i} initialized.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user