From 6e3ff9661678c28e5bbc1d915b28fcdad981ea83 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 31 Dec 2016 17:34:21 +0100 Subject: [PATCH] Compiles and runs --- .../Commands/CrossServerTextChannel.cs | 2 +- .../Administration/Commands/LogCommand.cs | 87 +++++++++++-------- .../Administration/Commands/MuteCommands.cs | 6 +- .../Commands/RatelimitCommand.cs | 1 - .../Commands/ServerGreetCommands.cs | 2 - .../Modules/ClashOfClans/ClashOfClans.cs | 18 ---- .../Modules/Games/Commands/Acropobia.cs | 14 +-- .../Games/Commands/Hangman/HangmanGame.cs | 2 +- .../Games/Commands/PlantAndPickCommands.cs | 8 +- .../Games/Commands/SpeedTypingCommands.cs | 6 +- .../Games/Commands/Trivia/TriviaGame.cs | 7 +- src/NadekoBot/Modules/Help/Help.cs | 3 +- src/NadekoBot/Modules/NSFW/NSFW.cs | 9 +- .../Modules/Permissions/Permissions.cs | 2 + .../Searches/Commands/AnimeSearchCommands.cs | 2 +- .../Commands/StreamNotificationCommands.cs | 6 +- .../Modules/Searches/Commands/Translator.cs | 2 +- .../Modules/Utility/Commands/InfoCommands.cs | 3 +- src/NadekoBot/NadekoBot.cs | 5 +- src/NadekoBot/Services/CommandHandler.cs | 9 +- 20 files changed, 97 insertions(+), 97 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs index bab5090a..62af02da 100644 --- a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs +++ b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs @@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Administration var channel = imsg.Channel as ITextChannel; if (channel == null) return; - if (msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return; + if (msg.Author.Id == NadekoBot.Client.CurrentUser().Id) return; foreach (var subscriber in Subscribers) { var set = subscriber.Value; diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index ddea0a30..776071f8 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -91,7 +91,7 @@ namespace NadekoBot.Modules.Administration 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 { @@ -111,7 +111,7 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null) + if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null) return; string str = null; @@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) + if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) return; string mutes = ""; switch (muteType) @@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) + if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) return; string mutes = ""; @@ -206,7 +206,7 @@ namespace NadekoBot.Modules.Administration || (logSetting.LogOtherId == null)) return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(users.First().Guild, logSetting, LogType.Other)) == null) + if ((logChannel = await TryGetLogChannel(users.First().Guild, logSetting, LogType.Other)) == null) return; var punishment = ""; @@ -232,19 +232,27 @@ namespace NadekoBot.Modules.Administration 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 { + var before = uBefore as SocketGuildUser; + if (before == null) + return; + var after = uAfter as SocketGuildUser; + if (after == null) + return; + LogSetting logSetting; if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting) || (logSetting.UserUpdatedId == null)) return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null) + if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null) return; string str = $"🕔`{prettyCurrentTime}`"; + if (before.Username != after.Username) //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()}**"; @@ -254,19 +262,19 @@ namespace NadekoBot.Modules.Administration 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 += $"👤__**{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 += $"👤__**{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 += $"👤__**{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 @@ -292,7 +300,7 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null) + if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null) return; if (before.Name != after.Name) //await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{after.Name}` ({after.Id}) @@ -323,7 +331,7 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null) + if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null) return; 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; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null) + if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null) return; 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); } } - 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 { @@ -373,7 +381,7 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null) + if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null) return; string str = null; @@ -396,20 +404,25 @@ namespace NadekoBot.Modules.Administration { _log.Warn(ex); } - }); + } - private async void _client_UserPresenceUpdated(IGuildUser usr, IPresence before, IPresence after) => await Task.Run(() => + private async void _client_UserPresenceUpdated(Optional optGuild, SocketUser usr, SocketPresence before, SocketPresence after) { try { + var guild = optGuild.IsSpecified ? optGuild.Value : null; + + if (guild == null) + return; + LogSetting logSetting; - if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) + if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting) || (logSetting.LogUserPresenceId == null) || before.Status == after.Status) return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserPresence)) == null) + if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserPresence)) == null) return; string str; if (before.Status != after.Status) @@ -420,7 +433,7 @@ namespace NadekoBot.Modules.Administration UserPresenceUpdates.AddOrUpdate(logChannel, new List() { str }, (id, list) => { list.Add(str); return list; }); } catch { } - }); + } private async void _client_UserLeft(IGuildUser usr) { @@ -432,7 +445,7 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)) == null) + if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)) == null) return; await logChannel.SendMessageAsync($"❗️🕛`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__❌ **| USER LEFT |** 🆔 `{usr.Id}`").ConfigureAwait(false); } @@ -449,7 +462,7 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null) + if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null) return; await logChannel.SendMessageAsync($"❕🕓`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__✅ **| USER JOINED |** 🆔 `{usr.Id}`").ConfigureAwait(false); @@ -467,7 +480,7 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null) + if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null) return; await logChannel.SendMessageAsync($"❕🕘`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__♻️ **| USER UN-BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); @@ -485,14 +498,14 @@ namespace NadekoBot.Modules.Administration return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null) + if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null) return; await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🚫 **| USER BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } } - private async void _client_MessageDeleted(ulong arg1, Optional imsg) + private async void _client_MessageDeleted(ulong arg1, Optional imsg) { try @@ -512,10 +525,10 @@ namespace NadekoBot.Modules.Administration return; 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; 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()) str += $"{Environment.NewLine}📎 {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}"; await logChannel.SendMessageAsync(str.SanitizeMentions()).ConfigureAwait(false); @@ -523,7 +536,7 @@ namespace NadekoBot.Modules.Administration catch (Exception ex) { _log.Warn(ex); } } - private async void _client_MessageUpdated(Optional optmsg, IMessage imsg2) + private async void _client_MessageUpdated(Optional optmsg, SocketMessage imsg2) { try { @@ -549,11 +562,11 @@ namespace NadekoBot.Modules.Administration return; 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; 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); + `Old:` {before.Resolve(userHandling: TagHandling.FullName).SanitizeMentions()} + **`New:`** {after.Resolve(userHandling: TagHandling.FullName).SanitizeMentions()}").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } } @@ -577,7 +590,7 @@ namespace NadekoBot.Modules.Administration UserMuted }; - private static ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogType logChannelType) + private static async Task TryGetLogChannel(IGuild guild, LogSetting logSetting, LogType logChannelType) { ulong? id = null; switch (logChannelType) @@ -636,7 +649,7 @@ namespace NadekoBot.Modules.Administration UnsetLogSetting(guild.Id, logChannelType); return null; } - var channel = guild.GetTextChannel(id.Value); + var channel = await guild.GetTextChannelAsync(id.Value).ConfigureAwait(false); if (channel == null) { diff --git a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs index d7db545c..b4993bf2 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs @@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Administration if (muted == null || !muted.Contains(usr.Id)) return; else - await Mute(usr).ConfigureAwait(false); + await MuteUser(usr).ConfigureAwait(false); } catch (Exception ex) { @@ -215,7 +215,7 @@ namespace NadekoBot.Modules.Administration { 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); await Context.Channel.SendConfirmAsync($"✏️🚫 **{user}** has been **muted** from chatting.").ConfigureAwait(false); } @@ -232,7 +232,7 @@ namespace NadekoBot.Modules.Administration { 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); await Context.Channel.SendConfirmAsync($"✏️✅ **{user}** has been **unmuted** from chatting.").ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs index 38ab1987..ccff187d 100644 --- a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs @@ -118,7 +118,6 @@ namespace NadekoBot.Modules.Administration MaxMessages = msg, PerSeconds = perSec, }; - if (RatelimitingChannels.TryAdd(channel.Id, toAdd)) if(RatelimitingChannels.TryAdd(Context.Channel.Id, toAdd)) { await Context.Channel.SendConfirmAsync("Slow mode initiated", diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs index e5130b56..80b8c394 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs @@ -38,8 +38,6 @@ namespace NadekoBot.Modules.Administration if (!conf.SendChannelByeMessage) return; 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 return; diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index ae012241..26b18995 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -58,24 +58,6 @@ namespace NadekoBot.Modules.ClashOfClans } }, 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) { diff --git a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs index 6d27ee78..dc727a6c 100644 --- a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs +++ b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs @@ -123,7 +123,7 @@ namespace NadekoBot.Modules.Games var embed = GetEmbed(); //SUBMISSIONS PHASE - await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); + await channel.EmbedAsync(embed).ConfigureAwait(false); try { await Task.Delay(time * 1000, source.Token).ConfigureAwait(false); @@ -144,13 +144,13 @@ namespace NadekoBot.Modules.Games { await channel.EmbedAsync(new EmbedBuilder().WithOkColor() .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())) - .Build()).ConfigureAwait(false); + .WithFooter(efb => efb.WithText(submissions.First().Key.ToLowerInvariant().ToTitleCase()))) + .ConfigureAwait(false); return; } var submissionClosedEmbed = GetEmbed(); - await channel.EmbedAsync(submissionClosedEmbed.Build()).ConfigureAwait(false); + await channel.EmbedAsync(submissionClosedEmbed).ConfigureAwait(false); //VOTING PHASE this.phase = AcroPhase.Voting; @@ -186,7 +186,7 @@ namespace NadekoBot.Modules.Games if (spamCount > 10) { spamCount = 0; - try { await channel.EmbedAsync(GetEmbed().Build()).ConfigureAwait(false); } + try { await channel.EmbedAsync(GetEmbed()).ConfigureAwait(false); } catch { } } //user didn't input something already @@ -226,7 +226,7 @@ namespace NadekoBot.Modules.Games if (spamCount > 10) { spamCount = 0; - try { await channel.EmbedAsync(GetEmbed().Build()).ConfigureAwait(false); } + try { await channel.EmbedAsync(GetEmbed()).ConfigureAwait(false); } catch { } } @@ -277,7 +277,7 @@ namespace NadekoBot.Modules.Games .WithDescription($"Winner is {submissions[winner.Key].Mention} with {winner.Value} points.\n") .WithFooter(efb => efb.WithText(winner.Key.ToLowerInvariant().ToTitleCase())); - await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); + await channel.EmbedAsync(embed).ConfigureAwait(false); } public void EnsureStopped() diff --git a/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs b/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs index cd41dc2e..27afb9f2 100644 --- a/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs @@ -120,7 +120,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman var embed = new EmbedBuilder().WithTitle("Hangman Game") .WithDescription(toSend) .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))); if (Errors >= MaxErrors) await GameChannel.EmbedAsync(embed.WithErrorColor()).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index 8746b631..80ac37d5 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -107,7 +107,7 @@ namespace NadekoBot.Modules.Games { 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; try @@ -121,14 +121,14 @@ namespace NadekoBot.Modules.Games await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false); - await CurrencyHandler.AddCurrencyAsync((IGuildUser)imsg.Author, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false); - var msg = await channel.SendConfirmAsync($"**{imsg.Author}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false); + await CurrencyHandler.AddCurrencyAsync((IGuildUser)Context.User, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false); + var msg = await channel.SendConfirmAsync($"**{Context.User}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false); msg.DeleteAfter(10); } finally { await Task.Delay(60000); - usersRecentlyPicked.TryRemove(imsg.Author.Id); + usersRecentlyPicked.TryRemove(Context.User.Id); } } diff --git a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs index d3a3da2b..ea69ab37 100644 --- a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs @@ -125,12 +125,12 @@ namespace NadekoBot.Modules.Games { var wpm = CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60; 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!") .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((string)"Errors").WithValue((string)distance.ToString()).WithIsInline((bool)true)) - .Build()).ConfigureAwait(false); + .AddField(efb => efb.WithName((string)"Errors").WithValue((string)distance.ToString()).WithIsInline((bool)true))) + .ConfigureAwait(false); 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); diff --git a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs index 15d0b47f..00b3f9ec 100644 --- a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs @@ -70,7 +70,7 @@ namespace NadekoBot.Modules.Games.Trivia .AddField(eab => eab.WithName("Category").WithValue(CurrentQuestion.Category)) .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) { @@ -97,7 +97,7 @@ namespace NadekoBot.Modules.Games.Trivia if (ShowHints) 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); } 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() .WithAuthor(eab => eab.WithName("Trivia Game Ended")) .WithTitle("Final Results") - .WithDescription(GetLeaderboard()) - .Build()).ConfigureAwait(false); + .WithDescription(GetLeaderboard())).ConfigureAwait(false); } public async Task StopGame() diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index b892f19b..46b5fc78 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -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`")) - .WithTitle("📜 List Of Modules").WithDescription("\n• " + string.Join("\n• ", NadekoBot.CommandService.Modules.Select(m => m.Name).OrderBy(s=>s))) - .Build(); + .WithTitle("📜 List Of Modules").WithDescription("\n• " + string.Join("\n• ", NadekoBot.CommandService.Modules.Select(m => m.Name).OrderBy(s=>s))); await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index 2268393f..e29a2fe4 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -61,8 +61,7 @@ namespace NadekoBot.Modules.NSFW else await channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithImageUrl(link) - .WithDescription("Tag: " + tag) - .Build()).ConfigureAwait(false); + .WithDescription("Tag: " + tag)).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -148,8 +147,7 @@ namespace NadekoBot.Modules.NSFW await channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithDescription(umsg.Author.Mention + " " + tag) .WithImageUrl(url) - .WithFooter(efb => efb.WithText("Danbooru")) - .Build()).ConfigureAwait(false); + .WithFooter(efb => efb.WithText("Danbooru"))).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -188,8 +186,7 @@ namespace NadekoBot.Modules.NSFW await channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithDescription(umsg.Author.Mention + " " + tag) .WithImageUrl(url) - .WithFooter(efb => efb.WithText("e621")) - .Build()).ConfigureAwait(false); + .WithFooter(efb => efb.WithText("e621"))).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index 28aa2fd8..505b55e1 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -9,6 +9,8 @@ using NadekoBot.Services.Database.Models; using System.Collections.Concurrent; using NadekoBot.Extensions; using Discord.WebSocket; +using System.Diagnostics; +using NLog; namespace NadekoBot.Modules.Permissions { diff --git a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs index d93554df..aff6635e 100644 --- a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs @@ -78,7 +78,7 @@ namespace NadekoBot.Modules.Searches .AddField(efb => efb.WithName("Status").WithValue(animeData.AiringStatus.ToString()).WithIsInline(true)) .AddField(efb => efb.WithName("Genres").WithValue(String.Join(", ", animeData.Genres)).WithIsInline(true)) .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] diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index 4f739431..fc315327 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -103,12 +103,14 @@ namespace NadekoBot.Modules.Searches oldStatus.IsLive != newStatus.IsLive) { 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) return; 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) msg.DeleteAfter(60); } diff --git a/src/NadekoBot/Modules/Searches/Commands/Translator.cs b/src/NadekoBot/Modules/Searches/Commands/Translator.cs index adf5774b..3ee67e6c 100644 --- a/src/NadekoBot/Modules/Searches/Commands/Translator.cs +++ b/src/NadekoBot/Modules/Searches/Commands/Translator.cs @@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Searches if (!UserLanguages.TryGetValue(key, out langs)) return; - var text = await TranslateInternal(langs, umsg.Resolve(UserMentionHandling.Ignore), true) + var text = await TranslateInternal(langs, umsg.Resolve(TagHandling.Ignore), true) .ConfigureAwait(false); if (autoDelete) try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { } diff --git a/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs b/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs index 26c8ea16..ca2ab738 100644 --- a/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs @@ -122,8 +122,7 @@ namespace NadekoBot.Modules.Utility 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()); + .WithDescription(str.ToString())); } } } \ No newline at end of file diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index eaeed098..a3a7a85b 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -67,7 +67,10 @@ namespace NadekoBot }); //initialize Services - CommandService = new CommandService(); + CommandService = new CommandService(new CommandServiceConfig() { + CaseSensitiveCommands = false, + SeparatorChar = '-' + }); Google = new GoogleApiService(); CommandHandler = new CommandHandler(Client, CommandService); Stats = new StatsService(Client, CommandHandler); diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 58a5bb50..9b2e2f51 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -16,6 +16,7 @@ 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 { @@ -35,6 +36,9 @@ namespace NadekoBot.Services public event Func CommandExecuted = delegate { return Task.CompletedTask; }; + //userid/msg count + public ConcurrentDictionary UserMessagesSent { get; } = new ConcurrentDictionary(); + public CommandHandler(ShardedDiscordClient client, CommandService commandService) { _client = client; @@ -64,6 +68,9 @@ namespace NadekoBot.Services if (usrMsg == null) return; + if (!usrMsg.IsAuthor()) + UserMessagesSent.AddOrUpdate(usrMsg.Author.Id, 1, (key, old) => ++old); + if (msg.Author.IsBot || !NadekoBot.Ready) //no bots return; @@ -294,7 +301,7 @@ namespace NadekoBot.Services 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(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."));