Compiles and runs

This commit is contained in:
Kwoth 2016-12-31 17:34:21 +01:00
parent 48fcc4c923
commit 6e3ff96616
20 changed files with 97 additions and 97 deletions

View File

@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Administration
var channel = imsg.Channel as ITextChannel; var channel = imsg.Channel as ITextChannel;
if (channel == null) if (channel == null)
return; return;
if (msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return; if (msg.Author.Id == NadekoBot.Client.CurrentUser().Id) return;
foreach (var subscriber in Subscribers) foreach (var subscriber in Subscribers)
{ {
var set = subscriber.Value; var set = subscriber.Value;

View File

@ -91,7 +91,7 @@ namespace NadekoBot.Modules.Administration
MuteCommands.UserUnmuted += MuteCommands_UserUnmuted; MuteCommands.UserUnmuted += MuteCommands_UserUnmuted;
} }
private async void _client_UserVoiceStateUpdated_TTS(IUser iusr, IVoiceState before, IVoiceState after) private async void _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
{ {
try try
{ {
@ -111,7 +111,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null) if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null)
return; return;
string str = null; string str = null;
@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
return; return;
string mutes = ""; string mutes = "";
switch (muteType) switch (muteType)
@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
return; return;
string mutes = ""; string mutes = "";
@ -206,7 +206,7 @@ namespace NadekoBot.Modules.Administration
|| (logSetting.LogOtherId == null)) || (logSetting.LogOtherId == null))
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(users.First().Guild, logSetting, LogType.Other)) == null) if ((logChannel = await TryGetLogChannel(users.First().Guild, logSetting, LogType.Other)) == null)
return; return;
var punishment = ""; var punishment = "";
@ -232,19 +232,27 @@ namespace NadekoBot.Modules.Administration
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
} }
private async void _client_UserUpdated(IGuildUser before, IGuildUser after) private async void _client_UserUpdated(SocketUser uBefore, SocketUser uAfter)
{ {
try try
{ {
var before = uBefore as SocketGuildUser;
if (before == null)
return;
var after = uAfter as SocketGuildUser;
if (after == null)
return;
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; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null) if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null)
return; return;
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()}`";
str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Name Changed |** 🆔 `{before.Id}`\n\t\t`New:` **{after.ToString()}**"; str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Name Changed |** 🆔 `{before.Id}`\n\t\t`New:` **{after.ToString()}**";
@ -254,19 +262,19 @@ namespace NadekoBot.Modules.Administration
else if (before.AvatarUrl != after.AvatarUrl) else if (before.AvatarUrl != after.AvatarUrl)
//str += $"**Avatar Changed**👤`{before.Username}#{before.Discriminator}`\n\t {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}"; //str += $"**Avatar Changed**👤`{before.Username}#{before.Discriminator}`\n\t {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}";
str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Avatar Changed |** 🆔 `{before.Id}`\n\t🖼 {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}"; str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Avatar Changed |** 🆔 `{before.Id}`\n\t🖼 {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}";
else if (!before.Roles.SequenceEqual(after.Roles)) else if (!before.RoleIds.SequenceEqual(after.RoleIds))
{ {
if (before.Roles.Count() < after.Roles.Count()) if (before.RoleIds.Count < after.RoleIds.Count)
{ {
var diffRoles = after.Roles.Where(r => !before.Roles.Contains(r)).Select(r => "**" + r.Name + "**"); var diffRoles = after.RoleIds.Where(r => !before.RoleIds.Contains(r)).Select(r => "**" + before.Guild.GetRole(r).Name + "**");
//str += $"**User's Roles changed ⚔➕**👤`{before.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role."; //str += $"**User's Roles changed ⚔➕**👤`{before.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role.";
str += $"👤__**{before.ToString()}**__ **| User's Role Added |** 🆔 `{before.Id}`\n\t✅ {string.Join(", ", diffRoles).SanitizeMentions()}\n\t\t⚔ **`{string.Join(", ", after.Roles.Select(r => r.Name)).SanitizeMentions()}`** ⚔"; str += $"👤__**{before.ToString()}**__ **| User's Role Added |** 🆔 `{before.Id}`\n\t✅ {string.Join(", ", diffRoles).SanitizeMentions()}\n\t\t⚔ **`{string.Join(", ", after.GetRoles().Select(r => r.Name)).SanitizeMentions()}`** ⚔";
} }
else if (before.Roles.Count() > after.Roles.Count()) else if (before.RoleIds.Count > after.RoleIds.Count)
{ {
var diffRoles = before.Roles.Where(r => !after.Roles.Contains(r)).Select(r => "**" + r.Name + "**"); var diffRoles = before.RoleIds.Where(r => !after.RoleIds.Contains(r)).Select(r => "**" + before.Guild.GetRole(r).Name + "**");
//str += $"**User's Roles changed **`{before.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role."; //str += $"**User's Roles changed **`{before.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role.";
str += $"👤__**{before.ToString()}**__ **| User's Role Removed |** 🆔 `{before.Id}`\n\t🚮 {string.Join(", ", diffRoles).SanitizeMentions()}\n\t\t⚔ **`{string.Join(", ", after.Roles.Select(r => r.Name)).SanitizeMentions()}`** ⚔"; str += $"👤__**{before.ToString()}**__ **| User's Role Removed |** 🆔 `{before.Id}`\n\t🚮 {string.Join(", ", diffRoles).SanitizeMentions()}\n\t\t⚔ **`{string.Join(", ", after.GetRoles().Select(r => r.Name)).SanitizeMentions()}`** ⚔";
} }
} }
else else
@ -292,7 +300,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null) if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null)
return; return;
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})
@ -323,7 +331,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null) if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null)
return; return;
await logChannel.SendMessageAsync($"🕕`{prettyCurrentTime}`🗑 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Deleted #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false); await logChannel.SendMessageAsync($"🕕`{prettyCurrentTime}`🗑 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Deleted #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false);
@ -345,7 +353,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null) if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null)
return; return;
await logChannel.SendMessageAsync($"🕓`{prettyCurrentTime}`🆕 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Created: #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false); await logChannel.SendMessageAsync($"🕓`{prettyCurrentTime}`🆕 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Created: #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false);
@ -353,7 +361,7 @@ namespace NadekoBot.Modules.Administration
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
} }
private async void _client_UserVoiceStateUpdated(IUser iusr, IVoiceState before, IVoiceState after) => await Task.Run(() => private async void _client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
{ {
try try
{ {
@ -373,7 +381,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null) if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null)
return; return;
string str = null; string str = null;
@ -396,20 +404,25 @@ namespace NadekoBot.Modules.Administration
{ {
_log.Warn(ex); _log.Warn(ex);
} }
}); }
private async void _client_UserPresenceUpdated(IGuildUser usr, IPresence before, IPresence after) => await Task.Run(() => private async void _client_UserPresenceUpdated(Optional<SocketGuild> optGuild, SocketUser usr, SocketPresence before, SocketPresence after)
{ {
try try
{ {
var guild = optGuild.IsSpecified ? optGuild.Value : null;
if (guild == null)
return;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|| (logSetting.LogUserPresenceId == null) || (logSetting.LogUserPresenceId == null)
|| before.Status == after.Status) || before.Status == after.Status)
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserPresence)) == null) if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserPresence)) == null)
return; return;
string str; string str;
if (before.Status != after.Status) if (before.Status != after.Status)
@ -420,7 +433,7 @@ namespace NadekoBot.Modules.Administration
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; });
} }
catch { } catch { }
}); }
private async void _client_UserLeft(IGuildUser usr) private async void _client_UserLeft(IGuildUser usr)
{ {
@ -432,7 +445,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)) == null) if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)) == null)
return; return;
await logChannel.SendMessageAsync($"❗️🕛`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__❌ **| USER LEFT |** 🆔 `{usr.Id}`").ConfigureAwait(false); await logChannel.SendMessageAsync($"❗️🕛`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__❌ **| USER LEFT |** 🆔 `{usr.Id}`").ConfigureAwait(false);
} }
@ -449,7 +462,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null) if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null)
return; return;
await logChannel.SendMessageAsync($"❕🕓`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__✅ **| USER JOINED |** 🆔 `{usr.Id}`").ConfigureAwait(false); await logChannel.SendMessageAsync($"❕🕓`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__✅ **| USER JOINED |** 🆔 `{usr.Id}`").ConfigureAwait(false);
@ -467,7 +480,7 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null) if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null)
return; return;
await logChannel.SendMessageAsync($"❕🕘`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__♻ **| USER UN-BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); await logChannel.SendMessageAsync($"❕🕘`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__♻ **| USER UN-BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false);
@ -485,14 +498,14 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null) if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null)
return; return;
await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🚫 **| USER BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🚫 **| USER BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false);
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
} }
private async void _client_MessageDeleted(ulong arg1, Optional<IMessage> imsg) private async void _client_MessageDeleted(ulong arg1, Optional<SocketMessage> imsg)
{ {
try try
@ -512,10 +525,10 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageDeleted)) == null || logChannel.Id == msg.Id) if ((logChannel = await TryGetLogChannel(channel.Guild, logSetting, LogType.MessageDeleted)) == null || logChannel.Id == msg.Id)
return; return;
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: TagHandling.FullName)}";
if (msg.Attachments.Any()) if (msg.Attachments.Any())
str += $"{Environment.NewLine}📎 {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}"; str += $"{Environment.NewLine}📎 {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}";
await logChannel.SendMessageAsync(str.SanitizeMentions()).ConfigureAwait(false); await logChannel.SendMessageAsync(str.SanitizeMentions()).ConfigureAwait(false);
@ -523,7 +536,7 @@ namespace NadekoBot.Modules.Administration
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
} }
private async void _client_MessageUpdated(Optional<IMessage> optmsg, IMessage imsg2) private async void _client_MessageUpdated(Optional<SocketMessage> optmsg, SocketMessage imsg2)
{ {
try try
{ {
@ -549,11 +562,11 @@ namespace NadekoBot.Modules.Administration
return; return;
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated)) == null || logChannel.Id == after.Channel.Id) if ((logChannel = await TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated)) == null || logChannel.Id == after.Channel.Id)
return; return;
await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}`👤__**{before.Author.Username}#{before.Author.Discriminator}**__ **| 📝 Edited Message |** 🆔 `{before.Author.Id}` #⃣ `{channel.Name}` 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: TagHandling.FullName).SanitizeMentions()}
**`New:`** {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}").ConfigureAwait(false); **`New:`** {after.Resolve(userHandling: TagHandling.FullName).SanitizeMentions()}").ConfigureAwait(false);
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
} }
@ -577,7 +590,7 @@ namespace NadekoBot.Modules.Administration
UserMuted UserMuted
}; };
private static ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogType logChannelType) private static async Task<ITextChannel> TryGetLogChannel(IGuild guild, LogSetting logSetting, LogType logChannelType)
{ {
ulong? id = null; ulong? id = null;
switch (logChannelType) switch (logChannelType)
@ -636,7 +649,7 @@ namespace NadekoBot.Modules.Administration
UnsetLogSetting(guild.Id, logChannelType); UnsetLogSetting(guild.Id, logChannelType);
return null; return null;
} }
var channel = guild.GetTextChannel(id.Value); var channel = await guild.GetTextChannelAsync(id.Value).ConfigureAwait(false);
if (channel == null) if (channel == null)
{ {

View File

@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Administration
if (muted == null || !muted.Contains(usr.Id)) if (muted == null || !muted.Contains(usr.Id))
return; return;
else else
await Mute(usr).ConfigureAwait(false); await MuteUser(usr).ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -215,7 +215,7 @@ namespace NadekoBot.Modules.Administration
{ {
try try
{ {
await user.AddRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false); await user.AddRolesAsync(await GetMuteRole(Context.Guild).ConfigureAwait(false)).ConfigureAwait(false);
UserMuted(user, MuteType.Chat); UserMuted(user, MuteType.Chat);
await Context.Channel.SendConfirmAsync($"✏️🚫 **{user}** has been **muted** from chatting.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync($"✏️🚫 **{user}** has been **muted** from chatting.").ConfigureAwait(false);
} }
@ -232,7 +232,7 @@ namespace NadekoBot.Modules.Administration
{ {
try try
{ {
await user.RemoveRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false); await user.RemoveRolesAsync(await GetMuteRole(Context.Guild).ConfigureAwait(false)).ConfigureAwait(false);
UserUnmuted(user, MuteType.Chat); UserUnmuted(user, MuteType.Chat);
await Context.Channel.SendConfirmAsync($"✏️✅ **{user}** has been **unmuted** from chatting.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync($"✏️✅ **{user}** has been **unmuted** from chatting.").ConfigureAwait(false);
} }

View File

@ -118,7 +118,6 @@ namespace NadekoBot.Modules.Administration
MaxMessages = msg, MaxMessages = msg,
PerSeconds = perSec, PerSeconds = perSec,
}; };
if (RatelimitingChannels.TryAdd(channel.Id, toAdd))
if(RatelimitingChannels.TryAdd(Context.Channel.Id, toAdd)) if(RatelimitingChannels.TryAdd(Context.Channel.Id, toAdd))
{ {
await Context.Channel.SendConfirmAsync("Slow mode initiated", await Context.Channel.SendConfirmAsync("Slow mode initiated",

View File

@ -38,8 +38,6 @@ namespace NadekoBot.Modules.Administration
if (!conf.SendChannelByeMessage) return; if (!conf.SendChannelByeMessage) return;
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.ByeMessageChannelId); var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.ByeMessageChannelId);
if (!conf.SendChannelByeMessage) return;
var channel = (await user.Guild.GetTextChannelsAsync()).FirstOrDefault(c => c.Id == conf.ByeMessageChannelId);
if (channel == null) //maybe warn the server owner that the channel is missing if (channel == null) //maybe warn the server owner that the channel is missing
return; return;

View File

@ -58,24 +58,6 @@ namespace NadekoBot.Modules.ClashOfClans
} }
}, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1)); }, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
} }
public ClashOfClans() : base()
{
checkWarTimer = new Timer(async _ =>
{
foreach (var kvp in ClashWars)
{
foreach (var war in kvp.Value)
{
try { await CheckWar(TimeSpan.FromHours(2), war).ConfigureAwait(false); } catch { }
}
}
}, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
sw.Stop();
_log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s");
}
private static async Task CheckWar(TimeSpan callExpire, ClashWar war) private static async Task CheckWar(TimeSpan callExpire, ClashWar war)
{ {

View File

@ -123,7 +123,7 @@ namespace NadekoBot.Modules.Games
var embed = GetEmbed(); var embed = GetEmbed();
//SUBMISSIONS PHASE //SUBMISSIONS PHASE
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed).ConfigureAwait(false);
try try
{ {
await Task.Delay(time * 1000, source.Token).ConfigureAwait(false); await Task.Delay(time * 1000, source.Token).ConfigureAwait(false);
@ -144,13 +144,13 @@ namespace NadekoBot.Modules.Games
{ {
await channel.EmbedAsync(new EmbedBuilder().WithOkColor() await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithDescription($"{submissions.First().Value.Mention} is the winner for being the only user who made a submission!") .WithDescription($"{submissions.First().Value.Mention} is the winner for being the only user who made a submission!")
.WithFooter(efb => efb.WithText(submissions.First().Key.ToLowerInvariant().ToTitleCase())) .WithFooter(efb => efb.WithText(submissions.First().Key.ToLowerInvariant().ToTitleCase())))
.Build()).ConfigureAwait(false); .ConfigureAwait(false);
return; return;
} }
var submissionClosedEmbed = GetEmbed(); var submissionClosedEmbed = GetEmbed();
await channel.EmbedAsync(submissionClosedEmbed.Build()).ConfigureAwait(false); await channel.EmbedAsync(submissionClosedEmbed).ConfigureAwait(false);
//VOTING PHASE //VOTING PHASE
this.phase = AcroPhase.Voting; this.phase = AcroPhase.Voting;
@ -186,7 +186,7 @@ namespace NadekoBot.Modules.Games
if (spamCount > 10) if (spamCount > 10)
{ {
spamCount = 0; spamCount = 0;
try { await channel.EmbedAsync(GetEmbed().Build()).ConfigureAwait(false); } try { await channel.EmbedAsync(GetEmbed()).ConfigureAwait(false); }
catch { } catch { }
} }
//user didn't input something already //user didn't input something already
@ -226,7 +226,7 @@ namespace NadekoBot.Modules.Games
if (spamCount > 10) if (spamCount > 10)
{ {
spamCount = 0; spamCount = 0;
try { await channel.EmbedAsync(GetEmbed().Build()).ConfigureAwait(false); } try { await channel.EmbedAsync(GetEmbed()).ConfigureAwait(false); }
catch { } catch { }
} }
@ -277,7 +277,7 @@ namespace NadekoBot.Modules.Games
.WithDescription($"Winner is {submissions[winner.Key].Mention} with {winner.Value} points.\n") .WithDescription($"Winner is {submissions[winner.Key].Mention} with {winner.Value} points.\n")
.WithFooter(efb => efb.WithText(winner.Key.ToLowerInvariant().ToTitleCase())); .WithFooter(efb => efb.WithText(winner.Key.ToLowerInvariant().ToTitleCase()));
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed).ConfigureAwait(false);
} }
public void EnsureStopped() public void EnsureStopped()

View File

@ -120,7 +120,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
var embed = new EmbedBuilder().WithTitle("Hangman Game") var embed = new EmbedBuilder().WithTitle("Hangman Game")
.WithDescription(toSend) .WithDescription(toSend)
.AddField(efb => efb.WithName("It was").WithValue(Term.Word)) .AddField(efb => efb.WithName("It was").WithValue(Term.Word))
.WithImage(eib => eib.WithUrl(Term.ImageUrl)) .WithImageUrl(Term.ImageUrl)
.WithFooter(efb => efb.WithText(string.Join(" ", Guesses))); .WithFooter(efb => efb.WithText(string.Join(" ", Guesses)));
if (Errors >= MaxErrors) if (Errors >= MaxErrors)
await GameChannel.EmbedAsync(embed.WithErrorColor()).ConfigureAwait(false); await GameChannel.EmbedAsync(embed.WithErrorColor()).ConfigureAwait(false);

View File

@ -107,7 +107,7 @@ namespace NadekoBot.Modules.Games
{ {
var channel = (ITextChannel)Context.Channel; var channel = (ITextChannel)Context.Channel;
if (!channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages || !usersRecentlyPicked.Add(imsg.Author.Id)) if (!(await channel.Guild.GetCurrentUserAsync()).GetPermissions(channel).ManageMessages || !usersRecentlyPicked.Add(Context.User.Id))
return; return;
try try
@ -121,14 +121,14 @@ namespace NadekoBot.Modules.Games
await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false); await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);
await CurrencyHandler.AddCurrencyAsync((IGuildUser)imsg.Author, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false); await CurrencyHandler.AddCurrencyAsync((IGuildUser)Context.User, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false);
var msg = await channel.SendConfirmAsync($"**{imsg.Author}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false); var msg = await channel.SendConfirmAsync($"**{Context.User}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);
msg.DeleteAfter(10); msg.DeleteAfter(10);
} }
finally finally
{ {
await Task.Delay(60000); await Task.Delay(60000);
usersRecentlyPicked.TryRemove(imsg.Author.Id); usersRecentlyPicked.TryRemove(Context.User.Id);
} }
} }

View File

@ -125,12 +125,12 @@ namespace NadekoBot.Modules.Games
{ {
var wpm = CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60; var wpm = CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60;
finishedUserIds.Add(msg.Author.Id); finishedUserIds.Add(msg.Author.Id);
await Extensions.Extensions.EmbedAsync(this.Channel, (Discord.API.Embed)new EmbedBuilder().WithColor((uint)NadekoBot.OkColor) await this.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithTitle((string)$"{msg.Author} finished the race!") .WithTitle((string)$"{msg.Author} finished the race!")
.AddField(efb => efb.WithName("Place").WithValue($"#{finishedUserIds.Count}").WithIsInline(true)) .AddField(efb => efb.WithName("Place").WithValue($"#{finishedUserIds.Count}").WithIsInline(true))
.AddField(efb => efb.WithName("WPM").WithValue($"{wpm:F2} *[{sw.Elapsed.Seconds.ToString()}sec]*").WithIsInline(true)) .AddField(efb => efb.WithName("WPM").WithValue($"{wpm:F2} *[{sw.Elapsed.Seconds.ToString()}sec]*").WithIsInline(true))
.AddField(efb => efb.WithName((string)"Errors").WithValue((string)distance.ToString()).WithIsInline((bool)true)) .AddField(efb => efb.WithName((string)"Errors").WithValue((string)distance.ToString()).WithIsInline((bool)true)))
.Build()).ConfigureAwait(false); .ConfigureAwait(false);
if (finishedUserIds.Count % 4 == 0) if (finishedUserIds.Count % 4 == 0)
{ {
await this.Channel.SendConfirmAsync($":exclamation: A lot of people finished, here is the text for those still typing:\n\n**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B")).SanitizeMentions()}**").ConfigureAwait(false); await this.Channel.SendConfirmAsync($":exclamation: A lot of people finished, here is the text for those still typing:\n\n**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B")).SanitizeMentions()}**").ConfigureAwait(false);

View File

@ -70,7 +70,7 @@ namespace NadekoBot.Modules.Games.Trivia
.AddField(eab => eab.WithName("Category").WithValue(CurrentQuestion.Category)) .AddField(eab => eab.WithName("Category").WithValue(CurrentQuestion.Category))
.AddField(eab => eab.WithName("Question").WithValue(CurrentQuestion.Question)); .AddField(eab => eab.WithName("Question").WithValue(CurrentQuestion.Question));
questionMessage = await channel.EmbedAsync(questionEmbed.Build()).ConfigureAwait(false); questionMessage = await channel.EmbedAsync(questionEmbed).ConfigureAwait(false);
} }
catch (HttpException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound || ex.StatusCode == System.Net.HttpStatusCode.Forbidden) catch (HttpException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound || ex.StatusCode == System.Net.HttpStatusCode.Forbidden)
{ {
@ -97,7 +97,7 @@ namespace NadekoBot.Modules.Games.Trivia
if (ShowHints) if (ShowHints)
try try
{ {
await questionMessage.ModifyAsync(m => m.Embed = questionEmbed.WithFooter(efb => efb.WithText(CurrentQuestion.GetHint())).Build()) await questionMessage.ModifyAsync(m => m.Embed = questionEmbed.WithFooter(efb => efb.WithText(CurrentQuestion.GetHint())))
.ConfigureAwait(false); .ConfigureAwait(false);
} }
catch (HttpException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound || ex.StatusCode == System.Net.HttpStatusCode.Forbidden) catch (HttpException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound || ex.StatusCode == System.Net.HttpStatusCode.Forbidden)
@ -130,8 +130,7 @@ namespace NadekoBot.Modules.Games.Trivia
await channel.EmbedAsync(new EmbedBuilder().WithOkColor() await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithAuthor(eab => eab.WithName("Trivia Game Ended")) .WithAuthor(eab => eab.WithName("Trivia Game Ended"))
.WithTitle("Final Results") .WithTitle("Final Results")
.WithDescription(GetLeaderboard()) .WithDescription(GetLeaderboard())).ConfigureAwait(false);
.Build()).ConfigureAwait(false);
} }
public async Task StopGame() public async Task StopGame()

View File

@ -41,8 +41,7 @@ namespace NadekoBot.Modules.Help
{ {
var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText($" Type `-cmds ModuleName` to get a list of commands in that module. eg `-cmds games`")) var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText($" Type `-cmds ModuleName` to get a list of commands in that module. eg `-cmds games`"))
.WithTitle("📜 List Of Modules").WithDescription("\n• " + string.Join("\n• ", NadekoBot.CommandService.Modules.Select(m => m.Name).OrderBy(s=>s))) .WithTitle("📜 List Of Modules").WithDescription("\n• " + string.Join("\n• ", NadekoBot.CommandService.Modules.Select(m => m.Name).OrderBy(s=>s)));
.Build();
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
} }

View File

@ -61,8 +61,7 @@ namespace NadekoBot.Modules.NSFW
else else
await channel.EmbedAsync(new EmbedBuilder().WithOkColor() await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithImageUrl(link) .WithImageUrl(link)
.WithDescription("Tag: " + tag) .WithDescription("Tag: " + tag)).ConfigureAwait(false);
.Build()).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -148,8 +147,7 @@ namespace NadekoBot.Modules.NSFW
await channel.EmbedAsync(new EmbedBuilder().WithOkColor() await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithDescription(umsg.Author.Mention + " " + tag) .WithDescription(umsg.Author.Mention + " " + tag)
.WithImageUrl(url) .WithImageUrl(url)
.WithFooter(efb => efb.WithText("Danbooru")) .WithFooter(efb => efb.WithText("Danbooru"))).ConfigureAwait(false);
.Build()).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -188,8 +186,7 @@ namespace NadekoBot.Modules.NSFW
await channel.EmbedAsync(new EmbedBuilder().WithOkColor() await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithDescription(umsg.Author.Mention + " " + tag) .WithDescription(umsg.Author.Mention + " " + tag)
.WithImageUrl(url) .WithImageUrl(url)
.WithFooter(efb => efb.WithText("e621")) .WithFooter(efb => efb.WithText("e621"))).ConfigureAwait(false);
.Build()).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -9,6 +9,8 @@ using NadekoBot.Services.Database.Models;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using Discord.WebSocket; using Discord.WebSocket;
using System.Diagnostics;
using NLog;
namespace NadekoBot.Modules.Permissions namespace NadekoBot.Modules.Permissions
{ {

View File

@ -78,7 +78,7 @@ namespace NadekoBot.Modules.Searches
.AddField(efb => efb.WithName("Status").WithValue(animeData.AiringStatus.ToString()).WithIsInline(true)) .AddField(efb => efb.WithName("Status").WithValue(animeData.AiringStatus.ToString()).WithIsInline(true))
.AddField(efb => efb.WithName("Genres").WithValue(String.Join(", ", animeData.Genres)).WithIsInline(true)) .AddField(efb => efb.WithName("Genres").WithValue(String.Join(", ", animeData.Genres)).WithIsInline(true))
.WithFooter(efb => efb.WithText("Score: " + animeData.average_score + " / 100")); .WithFooter(efb => efb.WithText("Score: " + animeData.average_score + " / 100"));
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -103,12 +103,14 @@ namespace NadekoBot.Modules.Searches
oldStatus.IsLive != newStatus.IsLive) oldStatus.IsLive != newStatus.IsLive)
{ {
var server = NadekoBot.Client.GetGuild(fs.GuildId); var server = NadekoBot.Client.GetGuild(fs.GuildId);
var channel = server?.GetTextChannelAsync(fs.ChannelId); if (server == null)
return;
var channel = await server.GetTextChannelAsync(fs.ChannelId);
if (channel == null) if (channel == null)
return; return;
try try
{ {
var msg = await channel.EmbedAsync(fs.GetEmbed(newStatus).Build()).ConfigureAwait(false); var msg = await channel.EmbedAsync(fs.GetEmbed(newStatus)).ConfigureAwait(false);
if (!newStatus.IsLive) if (!newStatus.IsLive)
msg.DeleteAfter(60); msg.DeleteAfter(60);
} }

View File

@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Searches
if (!UserLanguages.TryGetValue(key, out langs)) if (!UserLanguages.TryGetValue(key, out langs))
return; return;
var text = await TranslateInternal(langs, umsg.Resolve(UserMentionHandling.Ignore), true) var text = await TranslateInternal(langs, umsg.Resolve(TagHandling.Ignore), true)
.ConfigureAwait(false); .ConfigureAwait(false);
if (autoDelete) if (autoDelete)
try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { } try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { }

View File

@ -122,8 +122,7 @@ namespace NadekoBot.Modules.Utility
await imsg.Channel.EmbedAsync(new EmbedBuilder().WithTitle($"Activity Page #{page}") await imsg.Channel.EmbedAsync(new EmbedBuilder().WithTitle($"Activity Page #{page}")
.WithOkColor() .WithOkColor()
.WithFooter(efb => efb.WithText($"{NadekoBot.CommandHandler.UserMessagesSent.Count} users total.")) .WithFooter(efb => efb.WithText($"{NadekoBot.CommandHandler.UserMessagesSent.Count} users total."))
.WithDescription(str.ToString()) .WithDescription(str.ToString()));
.Build());
} }
} }
} }

View File

@ -67,7 +67,10 @@ namespace NadekoBot
}); });
//initialize Services //initialize Services
CommandService = new CommandService(); CommandService = new CommandService(new CommandServiceConfig() {
CaseSensitiveCommands = false,
SeparatorChar = '-'
});
Google = new GoogleApiService(); Google = new GoogleApiService();
CommandHandler = new CommandHandler(Client, CommandService); CommandHandler = new CommandHandler(Client, CommandService);
Stats = new StatsService(Client, CommandHandler); Stats = new StatsService(Client, CommandHandler);

View File

@ -16,6 +16,7 @@ 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
{ {
@ -35,6 +36,9 @@ namespace NadekoBot.Services
public event Func<SocketUserMessage, CommandInfo, Task> CommandExecuted = delegate { return Task.CompletedTask; }; public event Func<SocketUserMessage, CommandInfo, 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,6 +68,9 @@ namespace NadekoBot.Services
if (usrMsg == null) if (usrMsg == null)
return; return;
if (!usrMsg.IsAuthor())
UserMessagesSent.AddOrUpdate(usrMsg.Author.Id, 1, (key, old) => ++old);
if (msg.Author.IsBot || !NadekoBot.Ready) //no bots if (msg.Author.IsBot || !NadekoBot.Ready) //no bots
return; return;
@ -294,7 +301,7 @@ namespace NadekoBot.Services
if (CmdCdsCommands.HasCooldown(cmd, context.Guild, context.User)) if (CmdCdsCommands.HasCooldown(cmd, context.Guild, context.User))
return new ExecuteCommandResult(cmd, null, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you.")); return new ExecuteCommandResult(cmd, null, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you."));
return new ExecuteCommandResult(commands[i], null, await commands[i].Execute(context, parseResult, dependencyMap)); return new ExecuteCommandResult(cmd, null, await commands[i].ExecuteAsync(context, parseResult, dependencyMap));
} }
return new ExecuteCommandResult(null, null, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload.")); return new ExecuteCommandResult(null, null, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."));