diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index bacb683d..7b4ad467 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Administration bool shouldDelete; using (var uow = DbHandler.UnitOfWork()) { - shouldDelete = uow.GuildConfigs.For(channel.Guild.Id, set => set).DeleteMessageOnCommand; + shouldDelete = uow.GuildConfigs.For(Context.Guild.Id, set => set).DeleteMessageOnCommand; } if (shouldDelete) diff --git a/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs index 14fd957a..53cfdce1 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs @@ -87,7 +87,7 @@ namespace NadekoBot.Modules.Administration if (msg == null || Context.User.IsBot) return Task.CompletedTask; - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; if (channel == null) return Task.CompletedTask; @@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Administration try { AntiSpamSetting spamSettings; - if (!antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings)) + if (!antiSpamGuilds.TryGetValue(Context.Guild.Id, out spamSettings)) return; var stats = spamSettings.UserStats.AddOrUpdate(Context.User.Id, new UserSpamStats(msg.Content), @@ -199,27 +199,27 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.Administrator)] public async Task AntiRaid(IUserMessage imsg, int userThreshold, int seconds, PunishmentAction action) { - var channel = (ITextChannel)Context.Channel; + ////var channel = (ITextChannel)Context.Channel; if (userThreshold < 2 || userThreshold > 30) { - await channel.SendErrorAsync("❗️User threshold must be between **2** and **30**.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("❗️User threshold must be between **2** and **30**.").ConfigureAwait(false); return; } if (seconds < 2 || seconds > 300) { - await channel.SendErrorAsync("❗️Time must be between **2** and **300** seconds.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("❗️Time must be between **2** and **300** seconds.").ConfigureAwait(false); return; } try { - await MuteCommands.GetMuteRole(channel.Guild).ConfigureAwait(false); + await MuteCommands.GetMuteRole(Context.Guild).ConfigureAwait(false); } catch (Exception ex) { - await channel.SendConfirmAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" + + await Context.Channel.SendConfirmAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" + "or create 'nadeko-mute' role with disabled SendMessages and try again.") .ConfigureAwait(false); _log.Warn(ex); @@ -232,9 +232,9 @@ namespace NadekoBot.Modules.Administration Seconds = seconds, UserThreshold = userThreshold, }; - antiRaidGuilds.AddOrUpdate(channel.Guild.Id, setting, (id, old) => setting); + antiRaidGuilds.AddOrUpdate(Context.Guild.Id, setting, (id, old) => setting); - await channel.SendConfirmAsync($"ℹ️ {Context.User.Mention} If **{userThreshold}** or more users join within **{seconds}** seconds, I will **{action}** them.") + await Context.Channel.SendConfirmAsync($"ℹ️ {Context.User.Mention} If **{userThreshold}** or more users join within **{seconds}** seconds, I will **{action}** them.") .ConfigureAwait(false); } @@ -243,37 +243,37 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.Administrator)] public async Task AntiSpam(IUserMessage imsg, int messageCount=3, PunishmentAction action = PunishmentAction.Mute) { - var channel = (ITextChannel)Context.Channel; + ////var channel = (ITextChannel)Context.Channel; if (messageCount < 2 || messageCount > 10) return; AntiSpamSetting throwaway; - if (antiSpamGuilds.TryRemove(channel.Guild.Id, out throwaway)) + if (antiSpamGuilds.TryRemove(Context.Guild.Id, out throwaway)) { - await channel.SendConfirmAsync("🆗 **Anti-Spam feature** has been **disabled** on this server.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("🆗 **Anti-Spam feature** has been **disabled** on this server.").ConfigureAwait(false); } else { try { - await MuteCommands.GetMuteRole(channel.Guild).ConfigureAwait(false); + await MuteCommands.GetMuteRole(Context.Guild).ConfigureAwait(false); } catch (Exception ex) { - await channel.SendErrorAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" + + await Context.Channel.SendErrorAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" + "or create 'nadeko-mute' role with disabled SendMessages and try again.") .ConfigureAwait(false); _log.Warn(ex); return; } - if (antiSpamGuilds.TryAdd(channel.Guild.Id, new AntiSpamSetting() + if (antiSpamGuilds.TryAdd(Context.Guild.Id, new AntiSpamSetting() { Action = action, MessageThreshold = messageCount, })) - await channel.SendConfirmAsync("✅ **Anti-Spam feature** has been **enabled** on this server.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("✅ **Anti-Spam feature** has been **enabled** on this server.").ConfigureAwait(false); } } diff --git a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs index 1009936c..3342e6c2 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs @@ -48,12 +48,12 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageRoles)] public async Task AutoAssignRole(IUserMessage umsg, [Remainder] IRole role = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; GuildConfig conf; using (var uow = DbHandler.UnitOfWork()) { - conf = uow.GuildConfigs.For(channel.Guild.Id, set => set); + conf = uow.GuildConfigs.For(Context.Guild.Id, set => set); if (role == null) conf.AutoAssignRoleId = 0; else @@ -64,11 +64,11 @@ namespace NadekoBot.Modules.Administration if (role == null) { - await channel.SendConfirmAsync("🆗 **Auto assign role** on user join is now **disabled**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("🆗 **Auto assign role** on user join is now **disabled**.").ConfigureAwait(false); return; } - await channel.SendConfirmAsync("✅ **Auto assign role** on user join is now **enabled**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("✅ **Auto assign role** on user join is now **enabled**.").ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs index d7f517b5..81a10732 100644 --- a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs +++ b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Administration if (msg == null) return Task.CompletedTask; - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; if (channel == null) return Task.CompletedTask; @@ -42,7 +42,7 @@ namespace NadekoBot.Modules.Administration continue; foreach (var chan in set.Except(new[] { channel })) { - try { await chan.SendMessageAsync(GetText(channel.Guild, channel, (IGuildUser)Context.User, msg)).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } + try { await chan.SendMessageAsync(GetText(Context.Guild, channel, (IGuildUser)Context.User, msg)).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } } } }); @@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Administration [OwnerOnly] public async Task Scsc() { - var channel = (ITextChannel)Context.Channel; + ////var channel = (ITextChannel)Context.Channel; var token = new NadekoRandom().Next(); var set = new ConcurrentHashSet(); if (Subscribers.TryAdd(token, set)) @@ -76,13 +76,13 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task Jcsc(IUserMessage imsg, int token) { - var channel = (ITextChannel)Context.Channel; + ////var channel = (ITextChannel)Context.Channel; ConcurrentHashSet set; if (!Subscribers.TryGetValue(token, out set)) return; set.Add(channel); - await channel.SendConfirmAsync("Joined cross server channel.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("Joined cross server channel.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -90,13 +90,13 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task Lcsc() { - var channel = (ITextChannel)Context.Channel; + ////var channel = (ITextChannel)Context.Channel; foreach (var subscriber in Subscribers) { subscriber.Value.TryRemove(channel); } - await channel.SendMessageAsync("Left cross server channel.").ConfigureAwait(false); + await Context.Channel.SendMessageAsync("Left cross server channel.").ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs b/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs index cc304cf8..a808510e 100644 --- a/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs @@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Administration [OwnerOnly] public async Task ForwardMessages() { - var channel = Context.Channel; + //var channel = Context.Channel; using (var uow = DbHandler.UnitOfWork()) { @@ -40,16 +40,16 @@ namespace NadekoBot.Modules.Administration uow.Complete(); } if (ForwardDMs) - await channel.SendConfirmAsync("✅ **I will forward DMs from now on.**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("✅ **I will forward DMs from now on.**").ConfigureAwait(false); else - await channel.SendConfirmAsync("🆗 **I will stop forwarding DMs from now on.**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("🆗 **I will stop forwarding DMs from now on.**").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [OwnerOnly] public async Task ForwardToAll() { - var channel = Context.Channel; + //var channel = Context.Channel; using (var uow = DbHandler.UnitOfWork()) { @@ -58,9 +58,9 @@ namespace NadekoBot.Modules.Administration uow.Complete(); } if (ForwardDMsToAllOwners) - await channel.SendConfirmAsync("ℹ️ **I will forward DMs to all owners.**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ **I will forward DMs to all owners.**").ConfigureAwait(false); else - await channel.SendConfirmAsync("ℹ️ **I will forward DMs only to the first owner.**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ **I will forward DMs only to the first owner.**").ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 2113d064..938ff9d8 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -469,19 +469,19 @@ namespace NadekoBot.Modules.Administration if (msg == null || msg.IsAuthor()) return Task.CompletedTask; - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; if (channel == null) return Task.CompletedTask; LogSetting logSetting; - if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) + if (!GuildLogSettings.TryGetValue(Context.Guild.Id, out logSetting) || !logSetting.IsLogging || !logSetting.MessageDeleted || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == msg.Id) + if ((logChannel = TryGetLogChannel(Context.Guild, logSetting)) == null || logChannel.Id == msg.Id) return Task.CompletedTask; var task = Task.Run(async () => @@ -510,19 +510,19 @@ namespace NadekoBot.Modules.Administration if (before == null) return Task.CompletedTask; - var channel = after.Channel as ITextChannel; + //var channel = after.Channel as ITextChannel; if (channel == null) return Task.CompletedTask; LogSetting logSetting; - if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) + if (!GuildLogSettings.TryGetValue(Context.Guild.Id, out logSetting) || !logSetting.IsLogging || !logSetting.MessageUpdated || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == after.Channel.Id) + if ((logChannel = TryGetLogChannel(Context.Guild, logSetting)) == null || logChannel.Id == after.Channel.Id) return Task.CompletedTask; var task = Task.Run(async () => @@ -553,7 +553,7 @@ namespace NadekoBot.Modules.Administration id = logSetting.UserPresenceChannelId; break; } - var channel = guild.GetTextChannel(id); + //var channel = guild.GetTextChannel(id); if (channel == null) using (var uow = DbHandler.UnitOfWork()) @@ -585,12 +585,12 @@ namespace NadekoBot.Modules.Administration [OwnerOnly] public async Task LogServer() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; LogSetting logSetting; using (var uow = DbHandler.UnitOfWork()) { - logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting; - GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); + logSetting = uow.GuildConfigs.For(Context.Guild.Id).LogSetting; + GuildLogSettings.AddOrUpdate(Context.Guild.Id, (id) => logSetting, (id, old) => logSetting); logSetting.IsLogging = !logSetting.IsLogging; if (logSetting.IsLogging) logSetting.ChannelId = channel.Id; @@ -598,9 +598,9 @@ namespace NadekoBot.Modules.Administration } if (logSetting.IsLogging) - await channel.SendMessageAsync("✅ **Logging enabled.**").ConfigureAwait(false); + await Context.Channel.SendMessageAsync("✅ **Logging enabled.**").ConfigureAwait(false); else - await channel.SendMessageAsync("ℹ️ **Logging disabled.**").ConfigureAwait(false); + await Context.Channel.SendMessageAsync("ℹ️ **Logging disabled.**").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -609,12 +609,12 @@ namespace NadekoBot.Modules.Administration [OwnerOnly] public async Task LogIgnore() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; int removed; using (var uow = DbHandler.UnitOfWork()) { - var config = uow.GuildConfigs.For(channel.Guild.Id); - LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); + var config = uow.GuildConfigs.For(Context.Guild.Id); + LogSetting logSetting = GuildLogSettings.GetOrAdd(Context.Guild.Id, (id) => config.LogSetting); removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id); config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id); if (removed == 0) @@ -627,9 +627,9 @@ namespace NadekoBot.Modules.Administration } if (removed == 0) - await channel.SendMessageAsync($"🆗 Logging will **now ignore** #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); + await Context.Channel.SendMessageAsync($"🆗 Logging will **now ignore** #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); else - await channel.SendMessageAsync($"ℹ️ Logging will **no longer ignore** #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); + await Context.Channel.SendMessageAsync($"ℹ️ Logging will **no longer ignore** #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); } //[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] @@ -637,7 +637,7 @@ namespace NadekoBot.Modules.Administration //[OwnerOnly] //public async Task LogAdd([Remainder] string eventName) //{ - // var channel = (ITextChannel)Context.Channel; + // //var channel = (ITextChannel)Context.Channel; // //eventName = eventName?.Replace(" ","").ToLowerInvariant(); // switch (eventName.ToLowerInvariant()) @@ -653,16 +653,16 @@ namespace NadekoBot.Modules.Administration // case "channelupdated": // using (var uow = DbHandler.UnitOfWork()) // { - // var logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting; - // GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); + // var logSetting = uow.GuildConfigs.For(Context.Guild.Id).LogSetting; + // GuildLogSettings.AddOrUpdate(Context.Guild.Id, (id) => logSetting, (id, old) => logSetting); // var prop = logSetting.GetType().GetProperty(eventName); // prop.SetValue(logSetting, true); // await uow.CompleteAsync().ConfigureAwait(false); // } - // await channel.SendMessageAsync($"`Now logging {eventName} event.`").ConfigureAwait(false); + // await Context.Channel.SendMessageAsync($"`Now logging {eventName} event.`").ConfigureAwait(false); // break; // default: - // await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false); + // await Context.Channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false); // break; // } //} @@ -671,7 +671,7 @@ namespace NadekoBot.Modules.Administration //[RequireContext(ContextType.Guild)] //public async Task LogRemove(string eventName) //{ - // var channel = (ITextChannel)Context.Channel; + // //var channel = (ITextChannel)Context.Channel; // eventName = eventName.ToLowerInvariant(); // switch (eventName) @@ -688,16 +688,16 @@ namespace NadekoBot.Modules.Administration // case "channelupdated": // using (var uow = DbHandler.UnitOfWork()) // { - // var config = uow.GuildConfigs.For(channel.Guild.Id); - // LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); + // var config = uow.GuildConfigs.For(Context.Guild.Id); + // LogSetting logSetting = GuildLogSettings.GetOrAdd(Context.Guild.Id, (id) => config.LogSetting); // logSetting.GetType().GetProperty(eventName).SetValue(logSetting, false); // config.LogSetting = logSetting; // await uow.CompleteAsync().ConfigureAwait(false); // } - // await channel.SendMessageAsync($"`No longer logging {eventName} event.`").ConfigureAwait(false); + // await Context.Channel.SendMessageAsync($"`No longer logging {eventName} event.`").ConfigureAwait(false); // break; // default: - // await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false); + // await Context.Channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false); // break; // } //} @@ -707,12 +707,12 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.Administrator)] public async Task UserPresence() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; bool enabled; using (var uow = DbHandler.UnitOfWork()) { - var logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting; - GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); + var logSetting = uow.GuildConfigs.For(Context.Guild.Id).LogSetting; + GuildLogSettings.AddOrUpdate(Context.Guild.Id, (id) => logSetting, (id, old) => logSetting); enabled = logSetting.LogUserPresence = !logSetting.LogUserPresence; if(enabled) logSetting.UserPresenceChannelId = channel.Id; @@ -720,9 +720,9 @@ namespace NadekoBot.Modules.Administration } if (enabled) - await channel.SendMessageAsync($"✅ Logging **user presence** updates in #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); + await Context.Channel.SendMessageAsync($"✅ Logging **user presence** updates in #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); else - await channel.SendMessageAsync($"ℹ️ Stopped logging **user presence** updates.").ConfigureAwait(false); + await Context.Channel.SendMessageAsync($"ℹ️ Stopped logging **user presence** updates.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -730,14 +730,14 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.Administrator)] public async Task VoicePresence() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; bool enabled; using (var uow = DbHandler.UnitOfWork()) { - var logSetting = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.LogSetting) + var logSetting = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(gc => gc.LogSetting) .ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds)) .LogSetting; - GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); + GuildLogSettings.AddOrUpdate(Context.Guild.Id, (id) => logSetting, (id, old) => logSetting); enabled = logSetting.LogVoicePresence = !logSetting.LogVoicePresence; if (enabled) logSetting.VoicePresenceChannelId = channel.Id; @@ -745,21 +745,21 @@ namespace NadekoBot.Modules.Administration } if (enabled) - await channel.SendMessageAsync($"✅ Logging **voice presence** updates in #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); + await Context.Channel.SendMessageAsync($"✅ Logging **voice presence** updates in #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); else - await channel.SendMessageAsync($"ℹ️ Stopped logging **voice presence** updates.").ConfigureAwait(false); + await Context.Channel.SendMessageAsync($"ℹ️ Stopped logging **voice presence** updates.").ConfigureAwait(false); } //[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] //[RequireContext(ContextType.Guild)] //public async Task VoiPresIgnore(IUserMessage imsg, IVoiceChannel voiceChannel) //{ - // var channel = (ITextChannel)Context.Channel; + // //var channel = (ITextChannel)Context.Channel; // int removed; // using (var uow = DbHandler.UnitOfWork()) // { - // var config = uow.GuildConfigs.For(channel.Guild.Id); - // LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); + // var config = uow.GuildConfigs.For(Context.Guild.Id); + // LogSetting logSetting = GuildLogSettings.GetOrAdd(Context.Guild.Id, (id) => config.LogSetting); // removed = logSetting.IgnoredVoicePresenceChannelIds.RemoveWhere(ivpc => ivpc.ChannelId == voiceChannel.Id); // if (removed == 0) // logSetting.IgnoredVoicePresenceChannelIds.Add(new IgnoredVoicePresenceChannel { ChannelId = voiceChannel.Id }); @@ -768,9 +768,9 @@ namespace NadekoBot.Modules.Administration // } // if (removed == 0) - // await channel.SendMessageAsync($"`Enabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false); + // await Context.Channel.SendMessageAsync($"`Enabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false); // else - // await channel.SendMessageAsync($"`Disabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false); + // await Context.Channel.SendMessageAsync($"`Disabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false); //} } } diff --git a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index 9e0975af..54e480fe 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Administration await Task.Delay(Repeater.Interval, token).ConfigureAwait(false); if (oldMsg != null) try { await oldMsg.DeleteAsync(); } catch { } - try { oldMsg = await Channel.SendMessageAsync("🔄 " + Repeater.Message).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); try { source.Cancel(); } catch { } } + try { oldMsg = await Context.Channel.SendMessageAsync("🔄 " + Repeater.Message).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); try { source.Cancel(); } catch { } } } } catch (OperationCanceledException) { } @@ -84,16 +84,16 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageMessages)] public async Task RepeatInvoke() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; RepeatRunner rep; if (!repeaters.TryGetValue(channel.Id, out rep)) { - await channel.SendErrorAsync("ℹ️ **No repeating message found on this server.**").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("ℹ️ **No repeating message found on this server.**").ConfigureAwait(false); return; } rep.Reset(); - await channel.SendMessageAsync("🔄 " + rep.Repeater.Message).ConfigureAwait(false); + await Context.Channel.SendMessageAsync("🔄 " + rep.Repeater.Message).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -101,7 +101,7 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageMessages)] public async Task Repeat() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; RepeatRunner rep; if (repeaters.TryRemove(channel.Id, out rep)) { @@ -111,10 +111,10 @@ namespace NadekoBot.Modules.Administration await uow.CompleteAsync(); } rep.Stop(); - await channel.SendConfirmAsync("✅ **Stopped repeating a message.**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("✅ **Stopped repeating a message.**").ConfigureAwait(false); } else - await channel.SendConfirmAsync("ℹ️ **No message is repeating.**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ **No message is repeating.**").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -122,7 +122,7 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageMessages)] public async Task Repeat(IUserMessage imsg, int minutes, [Remainder] string message) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (minutes < 1 || minutes > 10080) return; @@ -139,7 +139,7 @@ namespace NadekoBot.Modules.Administration var localRep = new Repeater { ChannelId = channel.Id, - GuildId = channel.Guild.Id, + GuildId = Context.Guild.Id, Interval = TimeSpan.FromMinutes(minutes), Message = message, }; @@ -160,7 +160,7 @@ namespace NadekoBot.Modules.Administration return old; }); - await channel.SendConfirmAsync($"🔁 Repeating **\"{rep.Repeater.Message}\"** every `{rep.Repeater.Interval.Days} day(s), {rep.Repeater.Interval.Hours} hour(s) and {rep.Repeater.Interval.Minutes} minute(s)`.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🔁 Repeating **\"{rep.Repeater.Message}\"** every `{rep.Repeater.Interval.Days} day(s), {rep.Repeater.Interval.Hours} hour(s) and {rep.Repeater.Interval.Minutes} minute(s)`.").ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/Migration.cs b/src/NadekoBot/Modules/Administration/Commands/Migration.cs index a16dad79..59509501 100644 --- a/src/NadekoBot/Modules/Administration/Commands/Migration.cs +++ b/src/NadekoBot/Modules/Administration/Commands/Migration.cs @@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Administration [OwnerOnly] public async Task MigrateData() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; var version = 0; using (var uow = DbHandler.UnitOfWork()) diff --git a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs index 1efe2e90..481e8d5c 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs @@ -141,19 +141,19 @@ namespace NadekoBot.Modules.Administration [Priority(1)] public async Task SetMuteRole(IUserMessage imsg, [Remainder] string name) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; name = name.Trim(); if (string.IsNullOrWhiteSpace(name)) return; using (var uow = DbHandler.UnitOfWork()) { - var config = uow.GuildConfigs.For(channel.Guild.Id, set => set); + var config = uow.GuildConfigs.For(Context.Guild.Id, set => set); config.MuteRoleName = name; - GuildMuteRoles.AddOrUpdate(channel.Guild.Id, name, (id, old) => name); + GuildMuteRoles.AddOrUpdate(Context.Guild.Id, name, (id, old) => name); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendConfirmAsync("☑️ **New mute role set.**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("☑️ **New mute role set.**").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -169,16 +169,16 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.MuteMembers)] public async Task Mute(IUserMessage umsg, IGuildUser user) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; try { await Mute(user).ConfigureAwait(false); - await channel.SendConfirmAsync($"🔇 **{user}** has been **muted** from text and voice chat.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🔇 **{user}** has been **muted** from text and voice chat.").ConfigureAwait(false); } catch { - await channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); } } @@ -188,16 +188,16 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.MuteMembers)] public async Task Unmute(IUserMessage umsg, IGuildUser user) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; try { await Unmute(user).ConfigureAwait(false); - await channel.SendConfirmAsync($"🔉 **{user}** has been **unmuted** from text and voice chat.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🔉 **{user}** has been **unmuted** from text and voice chat.").ConfigureAwait(false); } catch { - await channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); } } @@ -206,17 +206,17 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageRoles)] public async Task ChatMute(IUserMessage umsg, IGuildUser user) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; try { - await user.AddRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false); + await user.AddRolesAsync(await GetMuteRole(Context.Guild).ConfigureAwait(false)).ConfigureAwait(false); await UserMuted(user, MuteType.Chat).ConfigureAwait(false); - await channel.SendConfirmAsync($"✏️🚫 **{user}** has been **muted** from chatting.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"✏️🚫 **{user}** has been **muted** from chatting.").ConfigureAwait(false); } catch { - await channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); } } @@ -225,17 +225,17 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageRoles)] public async Task ChatUnmute(IUserMessage umsg, IGuildUser user) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; try { - await user.RemoveRolesAsync(await GetMuteRole(channel.Guild).ConfigureAwait(false)).ConfigureAwait(false); + await user.RemoveRolesAsync(await GetMuteRole(Context.Guild).ConfigureAwait(false)).ConfigureAwait(false); await UserUnmuted(user, MuteType.Chat).ConfigureAwait(false); - await channel.SendConfirmAsync($"✏️✅ **{user}** has been **unmuted** from chatting.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"✏️✅ **{user}** has been **unmuted** from chatting.").ConfigureAwait(false); } catch { - await channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); } } @@ -244,17 +244,17 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.MuteMembers)] public async Task VoiceMute(IUserMessage umsg, IGuildUser user) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; try { await user.ModifyAsync(usr => usr.Mute = true).ConfigureAwait(false); await UserMuted(user, MuteType.Voice).ConfigureAwait(false); - await channel.SendConfirmAsync($"🎙🚫 **{user}** has been **voice muted**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🎙🚫 **{user}** has been **voice muted**.").ConfigureAwait(false); } catch { - await channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); } } @@ -263,16 +263,16 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.MuteMembers)] public async Task VoiceUnmute(IUserMessage umsg, IGuildUser user) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; try { await user.ModifyAsync(usr => usr.Mute = false).ConfigureAwait(false); await UserUnmuted(user, MuteType.Voice).ConfigureAwait(false); - await channel.SendConfirmAsync($"🎙✅ **{user}** has been **voice unmuted**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🎙✅ **{user}** has been **voice unmuted**.").ConfigureAwait(false); } catch { - await channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("⚠️ I most likely don't have the permission necessary for that.").ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs index 610b3bb7..1fecbd91 100644 --- a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs @@ -68,7 +68,7 @@ namespace NadekoBot.Modules.Administration var t = Task.Run(async () => { var usrMsg = umsg as IUserMessage; - var channel = usrContext.Channel as ITextChannel; + //var channel = usrContext.Channel as ITextChannel; if (channel == null || usrMsg.IsAuthor()) return; @@ -88,13 +88,13 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageMessages)] public async Task Slowmode() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; Ratelimiter throwaway; if (RatelimitingChannels.TryRemove(channel.Id, out throwaway)) { throwaway.cancelSource.Cancel(); - await channel.SendConfirmAsync("ℹ️ Slow mode disabled.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ Slow mode disabled.").ConfigureAwait(false); return; } } @@ -105,11 +105,11 @@ namespace NadekoBot.Modules.Administration public async Task Slowmode(IUserMessage umsg, int msg, int perSec) { await Slowmode(umsg).ConfigureAwait(false); // disable if exists - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (msg < 1 || perSec < 1 || msg > 100 || perSec > 3600) { - await channel.SendErrorAsync("⚠️ Invalid parameters."); + await Context.Channel.SendErrorAsync("⚠️ Invalid parameters."); return; } var toAdd = new Ratelimiter() @@ -120,7 +120,7 @@ namespace NadekoBot.Modules.Administration }; if(RatelimitingChannels.TryAdd(channel.Id, toAdd)) { - await channel.SendConfirmAsync("Slow mode initiated", + await Context.Channel.SendConfirmAsync("Slow mode initiated", $"Users can't send more than `{toAdd.MaxMessages} message(s)` every `{toAdd.PerSeconds} second(s)`.") .ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index e05a7a09..55319653 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -24,16 +24,16 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageMessages)] public async Task AdSarm() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; bool newval; using (var uow = DbHandler.UnitOfWork()) { - var config = uow.GuildConfigs.For(channel.Guild.Id, set => set); + var config = uow.GuildConfigs.For(Context.Guild.Id, set => set); newval = config.AutoDeleteSelfAssignedRoleMessages = !config.AutoDeleteSelfAssignedRoleMessages; await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendConfirmAsync($"ℹ️ Automatic deleting of `iam` and `iamn` confirmations has been {(newval ? "**enabled**" : "**disabled**")}.") + await Context.Channel.SendConfirmAsync($"ℹ️ Automatic deleting of `iam` and `iamn` confirmations has been {(newval ? "**enabled**" : "**disabled**")}.") .ConfigureAwait(false); } @@ -42,17 +42,17 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageRoles)] public async Task Asar(IUserMessage umsg, [Remainder] IRole role) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; IEnumerable roles; string msg; using (var uow = DbHandler.UnitOfWork()) { - roles = uow.SelfAssignedRoles.GetFromGuild(channel.Guild.Id); + roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id); if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.GuildId)) { - await channel.SendMessageAsync($"💢 Role **{role.Name}** is already in the list.").ConfigureAwait(false); + await Context.Channel.SendMessageAsync($"💢 Role **{role.Name}** is already in the list.").ConfigureAwait(false); return; } else @@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Administration msg = $"🆗 Role **{role.Name}** added to the list."; } } - await channel.SendConfirmAsync(msg.ToString()).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync(msg.ToString()).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageRoles)] public async Task Rsar(IUserMessage umsg, [Remainder] IRole role) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; bool success; using (var uow = DbHandler.UnitOfWork()) @@ -83,17 +83,17 @@ namespace NadekoBot.Modules.Administration } if (!success) { - await channel.SendErrorAsync("❎ That role is not self-assignable.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("❎ That role is not self-assignable.").ConfigureAwait(false); return; } - await channel.SendConfirmAsync($"🗑 **{role.Name}** has been removed from the list of self-assignable roles.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🗑 **{role.Name}** has been removed from the list of self-assignable roles.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Lsar() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; var toRemove = new ConcurrentHashSet(); var removeMsg = new StringBuilder(); @@ -101,13 +101,13 @@ namespace NadekoBot.Modules.Administration var roleCnt = 0; using (var uow = DbHandler.UnitOfWork()) { - var roleModels = uow.SelfAssignedRoles.GetFromGuild(channel.Guild.Id).ToList(); + var roleModels = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id).ToList(); roleCnt = roleModels.Count; msg.AppendLine(); foreach (var roleModel in roleModels) { - var role = channel.Guild.Roles.FirstOrDefault(r => r.Id == roleModel.RoleId); + var role = Context.Guild.Roles.FirstOrDefault(r => r.Id == roleModel.RoleId); if (role == null) { uow.SelfAssignedRoles.Remove(roleModel); @@ -123,7 +123,7 @@ namespace NadekoBot.Modules.Administration } await uow.CompleteAsync(); } - await channel.SendConfirmAsync($"ℹ️ There are `{roleCnt}` self assignable roles:", msg.ToString() + "\n\n" + removeMsg.ToString()).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"ℹ️ There are `{roleCnt}` self assignable roles:", msg.ToString() + "\n\n" + removeMsg.ToString()).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -131,25 +131,25 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageRoles)] public async Task Tesar() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; bool areExclusive; using (var uow = DbHandler.UnitOfWork()) { - var config = uow.GuildConfigs.For(channel.Guild.Id, set => set); + var config = uow.GuildConfigs.For(Context.Guild.Id, set => set); areExclusive = config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles; await uow.CompleteAsync(); } string exl = areExclusive ? "**exclusive**." : "**not exclusive**."; - await channel.SendConfirmAsync("ℹ️ Self assigned roles are now " + exl); + await Context.Channel.SendConfirmAsync("ℹ️ Self assigned roles are now " + exl); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Iam(IUserMessage umsg, [Remainder] IRole role) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; var guildUser = (IGuildUser)Context.User; var usrMsg = (IUserMessage)umsg; @@ -157,18 +157,18 @@ namespace NadekoBot.Modules.Administration IEnumerable roles; using (var uow = DbHandler.UnitOfWork()) { - conf = uow.GuildConfigs.For(channel.Guild.Id, set => set); - roles = uow.SelfAssignedRoles.GetFromGuild(channel.Guild.Id); + conf = uow.GuildConfigs.For(Context.Guild.Id, set => set); + roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id); } SelfAssignedRole roleModel; if ((roleModel = roles.FirstOrDefault(r=>r.RoleId == role.Id)) == null) { - await channel.SendErrorAsync("That role is not self-assignable.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("That role is not self-assignable.").ConfigureAwait(false); return; } if (guildUser.Roles.Contains(role)) { - await channel.SendErrorAsync($"You already have **{role.Name}** role.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"You already have **{role.Name}** role.").ConfigureAwait(false); return; } @@ -177,7 +177,7 @@ namespace NadekoBot.Modules.Administration var sameRoles = guildUser.Roles.Where(r => roles.Any(rm => rm.RoleId == r.Id)); if (sameRoles.Any()) { - await channel.SendErrorAsync($"You already have **{sameRoles.FirstOrDefault().Name}** `exclusive self-assigned` role.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"You already have **{sameRoles.FirstOrDefault().Name}** `exclusive self-assigned` role.").ConfigureAwait(false); return; } } @@ -187,11 +187,11 @@ namespace NadekoBot.Modules.Administration } catch (Exception ex) { - await channel.SendErrorAsync($"⚠️ I am unable to add that role to you. `I can't add roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"⚠️ I am unable to add that role to you. `I can't add roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false); Console.WriteLine(ex); return; } - var msg = await channel.SendConfirmAsync($"🆗 You now have **{role.Name}** role.").ConfigureAwait(false); + var msg = await Context.Channel.SendConfirmAsync($"🆗 You now have **{role.Name}** role.").ConfigureAwait(false); if (conf.AutoDeleteSelfAssignedRoleMessages) { @@ -208,25 +208,25 @@ namespace NadekoBot.Modules.Administration [RequireContext(ContextType.Guild)] public async Task Iamnot(IUserMessage umsg, [Remainder] IRole role) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; var guildUser = (IGuildUser)Context.User; bool autoDeleteSelfAssignedRoleMessages; IEnumerable roles; using (var uow = DbHandler.UnitOfWork()) { - autoDeleteSelfAssignedRoleMessages = uow.GuildConfigs.For(channel.Guild.Id, set => set).AutoDeleteSelfAssignedRoleMessages; - roles = uow.SelfAssignedRoles.GetFromGuild(channel.Guild.Id); + autoDeleteSelfAssignedRoleMessages = uow.GuildConfigs.For(Context.Guild.Id, set => set).AutoDeleteSelfAssignedRoleMessages; + roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id); } SelfAssignedRole roleModel; if ((roleModel = roles.FirstOrDefault(r => r.RoleId == role.Id)) == null) { - await channel.SendErrorAsync("💢 That role is not self-assignable.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("💢 That role is not self-assignable.").ConfigureAwait(false); return; } if (!guildUser.Roles.Contains(role)) { - await channel.SendErrorAsync($"❎ You don't have **{role.Name}** role.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"❎ You don't have **{role.Name}** role.").ConfigureAwait(false); return; } try @@ -235,10 +235,10 @@ namespace NadekoBot.Modules.Administration } catch (Exception) { - await channel.SendErrorAsync($"⚠️ I am unable to add that role to you. `I can't remove roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"⚠️ I am unable to add that role to you. `I can't remove roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false); return; } - var msg = await channel.SendConfirmAsync($"🆗 You no longer have **{role.Name}** role.").ConfigureAwait(false); + var msg = await Context.Channel.SendConfirmAsync($"🆗 You no longer have **{role.Name}** role.").ConfigureAwait(false); if (autoDeleteSelfAssignedRoleMessages) { diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs index 9b888321..a671d73e 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Administration [OwnerOnly] public async Task Leave(IUserMessage umsg, [Remainder] string guildStr) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; guildStr = guildStr.Trim().ToUpperInvariant(); var server = _client.GetGuilds().FirstOrDefault(g => g.Id.ToString().Trim().ToUpperInvariant() == guildStr) ?? @@ -32,18 +32,18 @@ namespace NadekoBot.Modules.Administration if (server == null) { - await channel.SendErrorAsync("⚠️ Cannot find that server").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("⚠️ Cannot find that server").ConfigureAwait(false); return; } if (server.OwnerId != _client.CurrentUser().Id) { await server.LeaveAsync().ConfigureAwait(false); - await channel.SendConfirmAsync("✅ Left server " + server.Name).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("✅ Left server " + server.Name).ConfigureAwait(false); } else { await server.DeleteAsync().ConfigureAwait(false); - await channel.SendConfirmAsync("Deleted server " + server.Name).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("Deleted server " + server.Name).ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs index 96dcf125..5309f750 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs @@ -39,7 +39,7 @@ namespace NadekoBot.Modules.Administration } 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 (channel == null) //maybe warn the server owner that the channel is missing return; @@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Administration return; try { - var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false); + var toDelete = await Context.Channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false); if (conf.AutoDeleteByeMessagesTimer > 0) { var t = Task.Run(async () => @@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Administration if (conf.SendChannelGreetMessage) { - var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId); + //var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId); if (channel != null) //maybe warn the server owner that the channel is missing { var msg = conf.ChannelGreetMessageText.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name); @@ -88,7 +88,7 @@ namespace NadekoBot.Modules.Administration { try { - var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false); + var toDelete = await Context.Channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false); if (conf.AutoDeleteGreetMessagesTimer > 0) { var t = Task.Run(async () => @@ -105,14 +105,14 @@ namespace NadekoBot.Modules.Administration if (conf.SendDmGreetMessage) { - var channel = await user.CreateDMChannelAsync(); + //var channel = await user.CreateDMChannelAsync(); if (channel != null) { var msg = conf.DmGreetMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name); if (!string.IsNullOrWhiteSpace(msg)) { - await channel.SendConfirmAsync(msg).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync(msg).ConfigureAwait(false); } } } @@ -127,16 +127,16 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task GreetDel(IUserMessage umsg, int timer = 30) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (timer < 0 || timer > 600) return; - await ServerGreetCommands.SetGreetDel(channel.Guild.Id, timer).ConfigureAwait(false); + await ServerGreetCommands.SetGreetDel(Context.Guild.Id, timer).ConfigureAwait(false); if (timer > 0) - await channel.SendConfirmAsync($"🆗 Greet messages **will be deleted** after `{timer} seconds`.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🆗 Greet messages **will be deleted** after `{timer} seconds`.").ConfigureAwait(false); else - await channel.SendConfirmAsync("ℹ️ Automatic deletion of greet messages has been **disabled**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ Automatic deletion of greet messages has been **disabled**.").ConfigureAwait(false); } private static async Task SetGreetDel(ulong id, int timer) @@ -158,14 +158,14 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task Greet() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; - var enabled = await ServerGreetCommands.SetGreet(channel.Guild.Id, channel.Id).ConfigureAwait(false); + var enabled = await ServerGreetCommands.SetGreet(Context.Guild.Id, channel.Id).ConfigureAwait(false); if (enabled) - await channel.SendConfirmAsync("✅ Greeting messages **enabled** on this channel.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("✅ Greeting messages **enabled** on this channel.").ConfigureAwait(false); else - await channel.SendConfirmAsync("ℹ️ Greeting messages **disabled**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ Greeting messages **disabled**.").ConfigureAwait(false); } private static async Task SetGreet(ulong guildId, ulong channelId, bool? value = null) @@ -187,24 +187,24 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task GreetMsg(IUserMessage umsg, [Remainder] string text = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (string.IsNullOrWhiteSpace(text)) { string channelGreetMessageText; using (var uow = DbHandler.UnitOfWork()) { - channelGreetMessageText = uow.GuildConfigs.For(channel.Guild.Id, set => set).ChannelGreetMessageText; + channelGreetMessageText = uow.GuildConfigs.For(Context.Guild.Id, set => set).ChannelGreetMessageText; } - await channel.SendConfirmAsync("Current greet message: ", channelGreetMessageText?.SanitizeMentions()); + await Context.Channel.SendConfirmAsync("Current greet message: ", channelGreetMessageText?.SanitizeMentions()); return; } - var sendGreetEnabled = ServerGreetCommands.SetGreetMessage(channel.Guild.Id, ref text); + var sendGreetEnabled = ServerGreetCommands.SetGreetMessage(Context.Guild.Id, ref text); - await channel.SendConfirmAsync("🆗 New greet message **set**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("🆗 New greet message **set**.").ConfigureAwait(false); if (!sendGreetEnabled) - await channel.SendConfirmAsync("ℹ️ Enable greet messsages by typing `.greet`").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ Enable greet messsages by typing `.greet`").ConfigureAwait(false); } public static bool SetGreetMessage(ulong guildId, ref string message) @@ -231,14 +231,14 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task GreetDm() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; - var enabled = await ServerGreetCommands.SetGreetDm(channel.Guild.Id).ConfigureAwait(false); + var enabled = await ServerGreetCommands.SetGreetDm(Context.Guild.Id).ConfigureAwait(false); if (enabled) - await channel.SendConfirmAsync("🆗 DM Greet announcements **enabled**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("🆗 DM Greet announcements **enabled**.").ConfigureAwait(false); else - await channel.SendConfirmAsync("ℹ️ Greet announcements **disabled**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ Greet announcements **disabled**.").ConfigureAwait(false); } private static async Task SetGreetDm(ulong guildId, bool? value = null) @@ -259,24 +259,24 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task GreetDmMsg(IUserMessage umsg, [Remainder] string text = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (string.IsNullOrWhiteSpace(text)) { GuildConfig config; using (var uow = DbHandler.UnitOfWork()) { - config = uow.GuildConfigs.For(channel.Guild.Id); + config = uow.GuildConfigs.For(Context.Guild.Id); } - await channel.SendConfirmAsync("ℹ️ Current **DM greet** message: `" + config.DmGreetMessageText?.SanitizeMentions() + "`"); + await Context.Channel.SendConfirmAsync("ℹ️ Current **DM greet** message: `" + config.DmGreetMessageText?.SanitizeMentions() + "`"); return; } - var sendGreetEnabled = ServerGreetCommands.SetGreetDmMessage(channel.Guild.Id, ref text); + var sendGreetEnabled = ServerGreetCommands.SetGreetDmMessage(Context.Guild.Id, ref text); - await channel.SendConfirmAsync("🆗 New DM greet message **set**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("🆗 New DM greet message **set**.").ConfigureAwait(false); if (!sendGreetEnabled) - await channel.SendConfirmAsync($"ℹ️ Enable DM greet messsages by typing `{NadekoBot.ModulePrefixes[typeof(Administration).Name]}greetdm`").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"ℹ️ Enable DM greet messsages by typing `{NadekoBot.ModulePrefixes[typeof(Administration).Name]}greetdm`").ConfigureAwait(false); } public static bool SetGreetDmMessage(ulong guildId, ref string message) @@ -303,14 +303,14 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task Bye() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; - var enabled = await ServerGreetCommands.SetBye(channel.Guild.Id, channel.Id).ConfigureAwait(false); + var enabled = await ServerGreetCommands.SetBye(Context.Guild.Id, channel.Id).ConfigureAwait(false); if (enabled) - await channel.SendConfirmAsync("✅ Bye announcements **enabled** on this channel.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("✅ Bye announcements **enabled** on this channel.").ConfigureAwait(false); else - await channel.SendConfirmAsync("ℹ️ Bye announcements **disabled**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ Bye announcements **disabled**.").ConfigureAwait(false); } private static async Task SetBye(ulong guildId, ulong channelId, bool? value = null) @@ -332,24 +332,24 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task ByeMsg(IUserMessage umsg, [Remainder] string text = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (string.IsNullOrWhiteSpace(text)) { string byeMessageText; using (var uow = DbHandler.UnitOfWork()) { - byeMessageText = uow.GuildConfigs.For(channel.Guild.Id, set => set).ChannelByeMessageText; + byeMessageText = uow.GuildConfigs.For(Context.Guild.Id, set => set).ChannelByeMessageText; } - await channel.SendConfirmAsync("ℹ️ Current **bye** message: `" + byeMessageText?.SanitizeMentions() + "`"); + await Context.Channel.SendConfirmAsync("ℹ️ Current **bye** message: `" + byeMessageText?.SanitizeMentions() + "`"); return; } - var sendByeEnabled = ServerGreetCommands.SetByeMessage(channel.Guild.Id, ref text); + var sendByeEnabled = ServerGreetCommands.SetByeMessage(Context.Guild.Id, ref text); - await channel.SendConfirmAsync("🆗 New bye message **set**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("🆗 New bye message **set**.").ConfigureAwait(false); if (!sendByeEnabled) - await channel.SendConfirmAsync($"ℹ️ Enable bye messsages by typing `{NadekoBot.ModulePrefixes[typeof(Administration).Name]}bye`").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"ℹ️ Enable bye messsages by typing `{NadekoBot.ModulePrefixes[typeof(Administration).Name]}bye`").ConfigureAwait(false); } public static bool SetByeMessage(ulong guildId, ref string message) @@ -376,14 +376,14 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task ByeDel(IUserMessage umsg, int timer = 30) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; - await ServerGreetCommands.SetByeDel(channel.Guild.Id, timer).ConfigureAwait(false); + await ServerGreetCommands.SetByeDel(Context.Guild.Id, timer).ConfigureAwait(false); if (timer > 0) - await channel.SendConfirmAsync($"🆗 Bye messages **will be deleted** after `{timer} seconds`.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🆗 Bye messages **will be deleted** after `{timer} seconds`.").ConfigureAwait(false); else - await channel.SendConfirmAsync("ℹ️ Automatic deletion of bye messages has been **disabled**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ Automatic deletion of bye messages has been **disabled**.").ConfigureAwait(false); } private static async Task SetByeDel(ulong id, int timer) diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index 0abb0527..70172381 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -110,13 +110,13 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageChannels)] public async Task VoicePlusText() { - var channel = (ITextChannel)Context.Channel; - var guild = channel.Guild; + //var channel = (ITextChannel)Context.Channel; + var guild = Context.Guild; var botUser = await guild.GetCurrentUserAsync().ConfigureAwait(false); if (!botUser.GuildPermissions.ManageRoles || !botUser.GuildPermissions.ManageChannels) { - await channel.SendErrorAsync("I require atleast **manage roles** and **manage channels permissions** to enable this feature. `(preffered Administration permission)`"); + await Context.Channel.SendErrorAsync("I require atleast **manage roles** and **manage channels permissions** to enable this feature. `(preffered Administration permission)`"); return; } @@ -124,7 +124,7 @@ namespace NadekoBot.Modules.Administration { try { - await channel.SendErrorAsync("⚠️ You are enabling this feature and **I do not have ADMINISTRATOR permissions**. " + + await Context.Channel.SendErrorAsync("⚠️ You are enabling this feature and **I do not have ADMINISTRATOR permissions**. " + "`This may cause some issues, and you will have to clean up text channels yourself afterwards.`"); } catch { } @@ -145,16 +145,16 @@ namespace NadekoBot.Modules.Administration { try { await textChannel.DeleteAsync().ConfigureAwait(false); } catch { } } - await channel.SendConfirmAsync("ℹ️ Successfuly **removed** voice + text feature.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("ℹ️ Successfuly **removed** voice + text feature.").ConfigureAwait(false); return; } voicePlusTextCache.Add(guild.Id); - await channel.SendConfirmAsync("🆗 Successfuly **enabled** voice + text feature.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("🆗 Successfuly **enabled** voice + text feature.").ConfigureAwait(false); } catch (Exception ex) { - await channel.SendErrorAsync(ex.ToString()).ConfigureAwait(false); + await Context.Channel.SendErrorAsync(ex.ToString()).ConfigureAwait(false); } } [NadekoCommand, Usage, Description, Aliases] @@ -163,12 +163,12 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageRoles)] public async Task CleanVPlusT() { - var channel = (ITextChannel)Context.Channel; - var guild = channel.Guild; + //var channel = (ITextChannel)Context.Channel; + var guild = Context.Guild; var botUser = await guild.GetCurrentUserAsync().ConfigureAwait(false); if (!botUser.GuildPermissions.Administrator) { - await channel.SendErrorAsync("I need **Administrator permission** to do that.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("I need **Administrator permission** to do that.").ConfigureAwait(false); return; } @@ -183,7 +183,7 @@ namespace NadekoBot.Modules.Administration await Task.Delay(500); } - await channel.SendConfirmAsync("Cleaned v+t.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("Cleaned v+t.").ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index 7364c63b..357d2cd7 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -59,7 +59,7 @@ namespace NadekoBot.Modules.ClashOfClans [RequireContext(ContextType.Guild)] public async Task CreateWar(IUserMessage umsg, int size, [Remainder] string enemyClan = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (!(Context.User as IGuildUser).GuildPermissions.ManageChannels) return; @@ -69,29 +69,32 @@ namespace NadekoBot.Modules.ClashOfClans if (size < 10 || size > 50 || size % 5 != 0) { - await channel.SendErrorAsync("🔰 Not a Valid war size").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("🔰 Not a Valid war size").ConfigureAwait(false); return; } List wars; - if (!ClashWars.TryGetValue(channel.Guild.Id, out wars)) + //if (!ClashWars.TryGetValue(channel.Guild.Id, out wars)) + if (!ClashWars.TryGetValue(Context.Guild.Id, out wars)) { wars = new List(); - if (!ClashWars.TryAdd(channel.Guild.Id, wars)) + if (!ClashWars.TryAdd(Context.Guild.Id, wars)) + //if (!ClashWars.TryAdd(channel.Guild.Id, wars)) return; } - var cw = await CreateWar(enemyClan, size, channel.Guild.Id, Context.Channel.Id); + var cw = await CreateWar(enemyClan, size, Context.Guild.Id, Context.Channel.Id); + //var cw = await CreateWar(enemyClan, size, channel.Guild.Id, Context.Channel.Id); wars.Add(cw); - await channel.SendConfirmAsync($"❗🔰**CREATED CLAN WAR AGAINST {cw.ShortPrint()}**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"❗🔰**CREATED CLAN WAR AGAINST {cw.ShortPrint()}**").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task StartWar(IUserMessage umsg, [Remainder] string number = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; int num = 0; int.TryParse(number, out num); @@ -99,18 +102,18 @@ namespace NadekoBot.Modules.ClashOfClans var warsInfo = GetWarInfo(umsg, num); if (warsInfo == null) { - await channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); return; } var war = warsInfo.Item1[warsInfo.Item2]; try { war.Start(); - await channel.SendConfirmAsync($"🔰**STARTED WAR AGAINST {war.ShortPrint()}**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🔰**STARTED WAR AGAINST {war.ShortPrint()}**").ConfigureAwait(false); } catch { - await channel.SendErrorAsync($"🔰**WAR AGAINST {war.ShortPrint()} HAS ALREADY STARTED**").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"🔰**WAR AGAINST {war.ShortPrint()} HAS ALREADY STARTED**").ConfigureAwait(false); } SaveWar(war); } @@ -119,17 +122,18 @@ namespace NadekoBot.Modules.ClashOfClans [RequireContext(ContextType.Guild)] public async Task ListWar(IUserMessage umsg, [Remainder] string number = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; // if number is null, print all wars in a short way if (string.IsNullOrWhiteSpace(number)) { //check if there are any wars List wars = null; - ClashWars.TryGetValue(channel.Guild.Id, out wars); + ClashWars.TryGetValue(Context.Guild.Id, out wars); + //ClashWars.TryGetValue(channel.Guild.Id, out wars); if (wars == null || wars.Count == 0) { - await channel.SendErrorAsync("🔰 **No active wars.**").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("🔰 **No active wars.**").ConfigureAwait(false); return; } @@ -142,7 +146,7 @@ namespace NadekoBot.Modules.ClashOfClans sb.AppendLine($"\t\t`Size:` **{wars[i].Size} v {wars[i].Size}**"); sb.AppendLine("**-------------------------**"); } - await channel.SendConfirmAsync(sb.ToString()).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync(sb.ToString()).ConfigureAwait(false); return; } @@ -152,21 +156,21 @@ namespace NadekoBot.Modules.ClashOfClans var warsInfo = GetWarInfo(umsg, num); if (warsInfo == null) { - await channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); return; } - await channel.SendConfirmAsync(warsInfo.Item1[warsInfo.Item2].ToPrettyString()).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync(warsInfo.Item1[warsInfo.Item2].ToPrettyString()).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Claim(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; var warsInfo = GetWarInfo(umsg, number); if (warsInfo == null || warsInfo.Item1.Count == 0) { - await channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); return; } var usr = @@ -178,11 +182,11 @@ namespace NadekoBot.Modules.ClashOfClans var war = warsInfo.Item1[warsInfo.Item2]; war.Call(usr, baseNumber - 1); SaveWar(war); - await channel.SendConfirmAsync($"🔰**{usr}** claimed a base #{baseNumber} for a war against {war.ShortPrint()}").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🔰**{usr}** claimed a base #{baseNumber} for a war against {war.ShortPrint()}").ConfigureAwait(false); } catch (Exception ex) { - await channel.SendErrorAsync($"🔰 {ex.Message}").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"🔰 {ex.Message}").ConfigureAwait(false); } } @@ -190,7 +194,7 @@ namespace NadekoBot.Modules.ClashOfClans [RequireContext(ContextType.Guild)] public async Task ClaimFinish1(IUserMessage umsg, int number, int baseNumber = 0) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; await FinishClaim(umsg, number, baseNumber - 1, 1); } @@ -198,7 +202,7 @@ namespace NadekoBot.Modules.ClashOfClans [RequireContext(ContextType.Guild)] public async Task ClaimFinish2(IUserMessage umsg, int number, int baseNumber = 0) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; await FinishClaim(umsg, number, baseNumber - 1, 2); } @@ -206,7 +210,7 @@ namespace NadekoBot.Modules.ClashOfClans [RequireContext(ContextType.Guild)] public async Task ClaimFinish(IUserMessage umsg, int number, int baseNumber = 0) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; await FinishClaim(umsg, number, baseNumber - 1); } @@ -214,18 +218,18 @@ namespace NadekoBot.Modules.ClashOfClans [RequireContext(ContextType.Guild)] public async Task EndWar(IUserMessage umsg, int number) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; var warsInfo = GetWarInfo(umsg,number); if (warsInfo == null) { - await channel.SendErrorAsync("🔰 That war does not exist.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("🔰 That war does not exist.").ConfigureAwait(false); return; } var war = warsInfo.Item1[warsInfo.Item2]; war.End(); SaveWar(war); - await channel.SendConfirmAsync($"❗🔰**War against {warsInfo.Item1[warsInfo.Item2].ShortPrint()} ended.**").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"❗🔰**War against {warsInfo.Item1[warsInfo.Item2].ShortPrint()} ended.**").ConfigureAwait(false); var size = warsInfo.Item1[warsInfo.Item2].Size; warsInfo.Item1.RemoveAt(warsInfo.Item2); @@ -235,12 +239,12 @@ namespace NadekoBot.Modules.ClashOfClans [RequireContext(ContextType.Guild)] public async Task Unclaim(IUserMessage umsg, int number, [Remainder] string otherName = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; var warsInfo = GetWarInfo(umsg, number); if (warsInfo == null || warsInfo.Item1.Count == 0) { - await channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); return; } var usr = @@ -252,21 +256,21 @@ namespace NadekoBot.Modules.ClashOfClans var war = warsInfo.Item1[warsInfo.Item2]; var baseNumber = war.Uncall(usr); SaveWar(war); - await channel.SendConfirmAsync($"🔰 @{usr} has **UNCLAIMED** a base #{baseNumber + 1} from a war against {war.ShortPrint()}").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"🔰 @{usr} has **UNCLAIMED** a base #{baseNumber + 1} from a war against {war.ShortPrint()}").ConfigureAwait(false); } catch (Exception ex) { - await channel.SendErrorAsync($"🔰 {ex.Message}").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"🔰 {ex.Message}").ConfigureAwait(false); } } private async Task FinishClaim(IUserMessage umsg, int number, int baseNumber, int stars = 3) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; var warInfo = GetWarInfo(umsg, number); if (warInfo == null || warInfo.Item1.Count == 0) { - await channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); return; } var war = warInfo.Item1[warInfo.Item2]; @@ -281,17 +285,17 @@ namespace NadekoBot.Modules.ClashOfClans { war.FinishClaim(baseNumber, stars); } - await channel.SendConfirmAsync($"❗🔰{Context.User.Mention} **DESTROYED** a base #{baseNumber + 1} in a war against {war.ShortPrint()}").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"❗🔰{Context.User.Mention} **DESTROYED** a base #{baseNumber + 1} in a war against {war.ShortPrint()}").ConfigureAwait(false); } catch (Exception ex) { - await channel.SendErrorAsync($"🔰 {ex.Message}").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"🔰 {ex.Message}").ConfigureAwait(false); } } private static Tuple, int> GetWarInfo(IUserMessage umsg, int num) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; //check if there are any wars List wars = null; ClashWars.TryGetValue(Context.Guild.Id, out wars); diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index 71bb62bc..81aa2a43 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -35,13 +35,14 @@ namespace NadekoBot.Modules.CustomReactions public static async Task TryExecuteCustomReaction() { - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; if (channel == null) return false; var content = umsg.Content.Trim().ToLowerInvariant(); ConcurrentHashSet reactions; - GuildReactions.TryGetValue(channel.Guild.Id, out reactions); + //GuildReactions.TryGetValue(channel.Guild.Id, out reactions); + GuildReactions.TryGetValue(Context.Guild.Id, out reactions); if (reactions != null && reactions.Any()) { var reaction = reactions.Where(cr => @@ -53,7 +54,7 @@ namespace NadekoBot.Modules.CustomReactions if (reaction != null) { if (reaction.Response != "-") - try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } + try { await Context.Channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } ReactionStats.AddOrUpdate(reaction.Trigger, 1, (k, old) => ++old); return true; @@ -68,7 +69,7 @@ namespace NadekoBot.Modules.CustomReactions if (greaction != null) { - try { await channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } + try { await Context.Channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } ReactionStats.AddOrUpdate(greaction.Trigger, 1, (k, old) => ++old); return true; } @@ -78,7 +79,7 @@ namespace NadekoBot.Modules.CustomReactions [NadekoCommand, Usage, Description, Aliases] public async Task AddCustReact(IUserMessage imsg, string key, [Remainder] string message) { - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; if (string.IsNullOrWhiteSpace(message) || string.IsNullOrWhiteSpace(key)) return; @@ -111,7 +112,8 @@ namespace NadekoBot.Modules.CustomReactions } else { - var reactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); + var reactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet()); + //var reactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); reactions.Add(cr); } @@ -127,7 +129,7 @@ namespace NadekoBot.Modules.CustomReactions [Priority(0)] public async Task ListCustReact(IUserMessage imsg, int page = 1) { - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; if (page < 1 || page > 1000) return; @@ -135,7 +137,8 @@ namespace NadekoBot.Modules.CustomReactions if (channel == null) customReactions = GlobalReactions; else - customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); + customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet()); + //customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); if (customReactions == null || !customReactions.Any()) await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); @@ -158,13 +161,14 @@ namespace NadekoBot.Modules.CustomReactions [Priority(1)] public async Task ListCustReact(IUserMessage imsg, All x) { - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; ConcurrentHashSet customReactions; if (channel == null) customReactions = GlobalReactions; else - customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); + customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet()); + //customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); if (customReactions == null || !customReactions.Any()) await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); @@ -186,14 +190,15 @@ namespace NadekoBot.Modules.CustomReactions [NadekoCommand, Usage, Description, Aliases] public async Task ListCustReactG(IUserMessage imsg, int page = 1) { - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; if (page < 1 || page > 10000) return; ConcurrentHashSet customReactions; if (channel == null) customReactions = GlobalReactions; else - customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); + customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet()); + //customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); if (customReactions == null || !customReactions.Any()) await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); @@ -211,13 +216,14 @@ namespace NadekoBot.Modules.CustomReactions [NadekoCommand, Usage, Description, Aliases] public async Task ShowCustReact(IUserMessage imsg, int id) { - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; ConcurrentHashSet customReactions; if (channel == null) customReactions = GlobalReactions; else - customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); + customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet()); + //customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); var found = customReactions.FirstOrDefault(cr => cr.Id == id); @@ -236,7 +242,7 @@ namespace NadekoBot.Modules.CustomReactions [NadekoCommand, Usage, Description, Aliases] public async Task DelCustReact(IUserMessage imsg, int id) { - var channel = Context.Channel as ITextChannel; + //var channel = Context.Channel as ITextChannel; if ((channel == null && !NadekoBot.Credentials.IsOwner(Context.User)) || (channel != null && !((IGuildUser)Context.User).GuildPermissions.Administrator)) { @@ -261,7 +267,8 @@ namespace NadekoBot.Modules.CustomReactions else if ((toDelete.GuildId != null && toDelete.GuildId != 0) && channel?.Guild.Id == toDelete.GuildId) { uow.CustomReactions.Remove(toDelete); - GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()).RemoveWhere(cr => cr.Id == toDelete.Id); + GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet()).RemoveWhere(cr => cr.Id == toDelete.Id); + //GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()).RemoveWhere(cr => cr.Id == toDelete.Id); success = true; } if (success) diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index 926903f8..f45ab74b 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -24,28 +24,28 @@ namespace NadekoBot.Modules.Gambling [RequireContext(ContextType.Guild)] public async Task Race() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; - var ar = new AnimalRace(channel.Guild.Id, channel); + var ar = new AnimalRace(Context.Guild.Id, channel); if (ar.Fail) - await channel.SendErrorAsync("🏁 `Failed starting a race. Another race is probably running.`"); + await Context.Channel.SendErrorAsync("🏁 `Failed starting a race. Another race is probably running.`"); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task JoinRace(IUserMessage umsg, int amount = 0) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (amount < 0) amount = 0; AnimalRace ar; - if (!AnimalRaces.TryGetValue(channel.Guild.Id, out ar)) + if (!AnimalRaces.TryGetValue(Context.Guild.Id, out ar)) { - await channel.SendErrorAsync("No race exists on this server"); + await Context.Channel.SendErrorAsync("No race exists on this server"); return; } await ar.JoinRace(Context.User as IGuildUser, amount); diff --git a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs index 06571677..a83b08fb 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs @@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Gambling [RequireContext(ContextType.Guild)] public async Task Roll() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (channel == null) return; var rng = new NadekoRandom(); @@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Gambling catch { return new MemoryStream(); } }); - await channel.SendFileAsync(imageStream, "dice.png", $"{Context.User.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false); + await Context.Channel.SendFileAsync(imageStream, "dice.png", $"{Context.User.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false); } //todo merge into internallDndRoll and internalRoll [NadekoCommand, Usage, Description, Aliases] @@ -52,7 +52,7 @@ namespace NadekoBot.Modules.Gambling [Priority(1)] public async Task Roll(IUserMessage umsg, string arg) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (channel == null) return; @@ -78,7 +78,7 @@ namespace NadekoBot.Modules.Gambling arr[i] = rng.Next(1, n2 + 1) + add - sub; } var elemCnt = 0; - await channel.SendConfirmAsync($"{Context.User.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"{Context.User.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false); } } } @@ -88,7 +88,7 @@ namespace NadekoBot.Modules.Gambling [Priority(0)] public async Task Roll(IUserMessage umsg, int num) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (channel == null) return; @@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Gambling if (num < 1 || num > 30) { - await channel.SendErrorAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false); return; } @@ -134,14 +134,14 @@ namespace NadekoBot.Modules.Gambling var ms = new MemoryStream(); bitmap.SaveAsPng(ms); ms.Position = 0; - await channel.SendFileAsync(ms, "dice.png", $"{Context.User.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false); + await Context.Channel.SendFileAsync(ms, "dice.png", $"{Context.User.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Rolluo(IUserMessage umsg, string arg) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (channel == null) return; @@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Gambling arr[i] = rng.Next(1, n2 + 1) + add - sub; } var elemCnt = 0; - await channel.SendConfirmAsync($"{Context.User.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"{Context.User.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false); } } } @@ -176,7 +176,7 @@ namespace NadekoBot.Modules.Gambling [RequireContext(ContextType.Guild)] public async Task Rolluo(IUserMessage umsg, int num) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (channel == null) return; @@ -184,7 +184,7 @@ namespace NadekoBot.Modules.Gambling if (num < 1 || num > 30) { - await channel.SendErrorAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false); return; } @@ -222,14 +222,14 @@ namespace NadekoBot.Modules.Gambling var ms = new MemoryStream(); bitmap.SaveAsPng(ms); ms.Position = 0; - await channel.SendFileAsync(ms, "dice.png", $"{Context.User.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false); + await Context.Channel.SendFileAsync(ms, "dice.png", $"{Context.User.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task NRoll(IUserMessage umsg, [Remainder] string range) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; try { @@ -249,11 +249,11 @@ namespace NadekoBot.Modules.Gambling rolled = new NadekoRandom().Next(0, int.Parse(range) + 1); } - await channel.SendConfirmAsync($"{Context.User.Mention} rolled **{rolled}**.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"{Context.User.Mention} rolled **{rolled}**.").ConfigureAwait(false); } catch (Exception ex) { - await channel.SendErrorAsync($":anger: {ex.Message}").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($":anger: {ex.Message}").ConfigureAwait(false); } } diff --git a/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs index 53571526..19acfc47 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs @@ -33,8 +33,8 @@ namespace NadekoBot.Modules.Gambling [RequireContext(ContextType.Guild)] public async Task Draw(int num = 1) { - var channel = (ITextChannel)Context.Channel; - var cards = AllDecks.GetOrAdd(channel.Guild, (s) => new Cards()); + //var channel = (ITextChannel)Context.Channel; + var cards = AllDecks.GetOrAdd(Context.Guild, (s) => new Cards()); var images = new List(); var cardObjects = new List(); if (num > 5) num = 5; @@ -42,7 +42,7 @@ namespace NadekoBot.Modules.Gambling { if (cards.CardPool.Count == 0 && i != 0) { - try { await channel.SendErrorAsync("No more cards in a deck.").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } + try { await Context.Channel.SendErrorAsync("No more cards in a deck.").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } break; } var currentCard = cards.DrawACard(); @@ -58,16 +58,16 @@ namespace NadekoBot.Modules.Gambling if (cardObjects.Count == 5) toSend += $" drew `{Cards.GetHandValue(cardObjects)}`"; - await channel.SendFileAsync(bitmapStream, images.Count + " cards.jpg", toSend).ConfigureAwait(false); + await Context.Channel.SendFileAsync(bitmapStream, images.Count + " cards.jpg", toSend).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task ShuffleDeck() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; - AllDecks.AddOrUpdate(channel.Guild, + AllDecks.AddOrUpdate(Context.Guild, (g) => new Cards(), (g, c) => { @@ -75,7 +75,7 @@ namespace NadekoBot.Modules.Gambling return c; }); - await channel.SendConfirmAsync("Deck reshuffled.").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("Deck reshuffled.").ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs index 66fb228e..554bcfef 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs @@ -23,18 +23,18 @@ namespace NadekoBot.Modules.Gambling [RequireContext(ContextType.Guild)] public async Task Flip(IUserMessage imsg, int count = 1) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (count == 1) { if (rng.Next(0, 2) == 1) - await channel.SendFileAsync(headsPath, $"{Context.User.Mention} flipped " + Format.Code("Heads") + ".").ConfigureAwait(false); + await Context.Channel.SendFileAsync(headsPath, $"{Context.User.Mention} flipped " + Format.Code("Heads") + ".").ConfigureAwait(false); else - await channel.SendFileAsync(tailsPath, $"{Context.User.Mention} flipped " + Format.Code("Tails") + ".").ConfigureAwait(false); + await Context.Channel.SendFileAsync(tailsPath, $"{Context.User.Mention} flipped " + Format.Code("Tails") + ".").ConfigureAwait(false); return; } if (count > 10 || count < 1) { - await channel.SendErrorAsync("`Invalid number specified. You can flip 1 to 10 coins.`"); + await Context.Channel.SendErrorAsync("`Invalid number specified. You can flip 1 to 10 coins.`"); return; } var imgs = new Image[count]; @@ -44,14 +44,14 @@ namespace NadekoBot.Modules.Gambling new Image(File.OpenRead(headsPath)) : new Image(File.OpenRead(tailsPath)); } - await channel.SendFileAsync(imgs.Merge().ToStream(), $"{count} coins.png").ConfigureAwait(false); + await Context.Channel.SendFileAsync(imgs.Merge().ToStream(), $"{count} coins.png").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Betflip(IUserMessage umsg, int amount, string guess) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; var guildUser = (IGuildUser)Context.User; var guessStr = guess.Trim().ToUpperInvariant(); if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS") @@ -59,7 +59,7 @@ namespace NadekoBot.Modules.Gambling if (amount < 3) { - await channel.SendErrorAsync($"You can't bet less than 3{Gambling.CurrencySign}.") + await Context.Channel.SendErrorAsync($"You can't bet less than 3{Gambling.CurrencySign}.") .ConfigureAwait(false); return; } @@ -72,7 +72,7 @@ namespace NadekoBot.Modules.Gambling if (userFlowers < amount) { - await channel.SendErrorAsync($"{Context.User.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"{Context.User.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false); return; } @@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Gambling str = $"{Context.User.Mention}`Better luck next time.`"; } - await channel.SendFileAsync(imgPathToSend, str).ConfigureAwait(false); + await Context.Channel.SendFileAsync(imgPathToSend, str).ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 066d4fd1..d60a45d9 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -44,51 +44,52 @@ namespace NadekoBot.Modules.Gambling [RequireContext(ContextType.Guild)] public async Task Raffle(IUserMessage umsg, [Remainder] IRole role = null) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; - role = role ?? channel.Guild.EveryoneRole; + //role = role ?? channel.Guild.EveryoneRole; + role = role ?? Context.Guild.EveryoneRole; var members = role.Members().Where(u => u.Status != UserStatus.Offline && u.Status != UserStatus.Unknown); var membersArray = members as IUser[] ?? members.ToArray(); var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)]; - await channel.SendConfirmAsync("🎟 Raffled user", $"**{usr.Username}#{usr.Discriminator}** ID: `{usr.Id}`").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync("🎟 Raffled user", $"**{usr.Username}#{usr.Discriminator}** ID: `{usr.Id}`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [Priority(0)] public async Task Cash(IUserMessage umsg, [Remainder] IUser user = null) { - var channel = Context.Channel; + //var channel = Context.Channel; user = user ?? Context.User; - await channel.SendConfirmAsync($"{user.Username} has {GetCurrency(user.Id)} {CurrencySign}").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"{user.Username} has {GetCurrency(user.Id)} {CurrencySign}").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [Priority(1)] public async Task Cash(IUserMessage umsg, ulong userId) { - var channel = Context.Channel; + //var channel = Context.Channel; - await channel.SendConfirmAsync($"`{userId}` has {GetCurrency(userId)} {CurrencySign}").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"`{userId}` has {GetCurrency(userId)} {CurrencySign}").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Give(IUserMessage umsg, long amount, [Remainder] IGuildUser receiver) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (amount <= 0 || Context.User.Id == receiver.Id) return; var success = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)Context.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, true).ConfigureAwait(false); if (!success) { - await channel.SendErrorAsync($"{Context.User.Mention} You don't have enough {Gambling.CurrencyPluralName}.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"{Context.User.Mention} You don't have enough {Gambling.CurrencyPluralName}.").ConfigureAwait(false); return; } await CurrencyHandler.AddCurrencyAsync(receiver, $"Gift from {Context.User.Username} ({Context.User.Id}).", amount, true).ConfigureAwait(false); - await channel.SendConfirmAsync($"{Context.User.Mention} successfully sent {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} to {receiver.Mention}!").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"{Context.User.Mention} successfully sent {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} to {receiver.Mention}!").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -104,14 +105,14 @@ namespace NadekoBot.Modules.Gambling [Priority(1)] public async Task Award(IUserMessage umsg, int amount, ulong usrId) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (amount <= 0) return; await CurrencyHandler.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false); - await channel.SendConfirmAsync($"{Context.User.Mention} successfully awarded {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} to <@{usrId}>!").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"{Context.User.Mention} successfully awarded {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} to <@{usrId}>!").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -121,7 +122,8 @@ namespace NadekoBot.Modules.Gambling public async Task Award(IUserMessage umsg, int amount, [Remainder] IRole role) { var channel = (ITextChannel)Context.Channel; - var users = channel.Guild.GetUsers() + var users = Context.Guild.GetUsers() + //var users = channel.Guild.GetUsers() .Where(u => u.Roles.Contains(role)) .ToList(); await Task.WhenAll(users.Select(u => CurrencyHandler.AddCurrencyAsync(u.Id, @@ -129,7 +131,8 @@ namespace NadekoBot.Modules.Gambling amount))) .ConfigureAwait(false); - await channel.SendConfirmAsync($"Awarded `{amount}` {Gambling.CurrencyPluralName} to `{users.Count}` users from `{role.Name}` role.") + await Context.Channel.SendConfirmAsync($"Awarded `{amount}` {Gambling.CurrencyPluralName} to `{users.Count}` users from `{role.Name}` role.") + //await channel.SendConfirmAsync($"Awarded `{amount}` {Gambling.CurrencyPluralName} to `{users.Count}` users from `{role.Name}` role.") .ConfigureAwait(false); } @@ -139,14 +142,14 @@ namespace NadekoBot.Modules.Gambling [OwnerOnly] public async Task Take(IUserMessage umsg, long amount, [Remainder] IGuildUser user) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (amount <= 0) return; if(await CurrencyHandler.RemoveCurrencyAsync(user, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount, true).ConfigureAwait(false)) - await channel.SendConfirmAsync($"{Context.User.Mention} successfully took {amount} {(amount == 1? Gambling.CurrencyName : Gambling.CurrencyPluralName)} from {user}!").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"{Context.User.Mention} successfully took {amount} {(amount == 1? Gambling.CurrencyName : Gambling.CurrencyPluralName)} from {user}!").ConfigureAwait(false); else - await channel.SendErrorAsync($"{Context.User.Mention} was unable to take {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} from {user} because the user doesn't have that much {Gambling.CurrencyPluralName}!").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"{Context.User.Mention} was unable to take {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} from {user} because the user doesn't have that much {Gambling.CurrencyPluralName}!").ConfigureAwait(false); } @@ -155,21 +158,21 @@ namespace NadekoBot.Modules.Gambling [OwnerOnly] public async Task Take(IUserMessage umsg, long amount, [Remainder] ulong usrId) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (amount <= 0) return; if(await CurrencyHandler.RemoveCurrencyAsync(usrId, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false)) - await channel.SendConfirmAsync($"{Context.User.Mention} successfully took {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} from <@{usrId}>!").ConfigureAwait(false); + await Context.Channel.SendConfirmAsync($"{Context.User.Mention} successfully took {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} from <@{usrId}>!").ConfigureAwait(false); else - await channel.SendErrorAsync($"{Context.User.Mention} was unable to take {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} from `{usrId}` because the user doesn't have that much {Gambling.CurrencyPluralName}!").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"{Context.User.Mention} was unable to take {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} from `{usrId}` because the user doesn't have that much {Gambling.CurrencyPluralName}!").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task BetRoll(IUserMessage umsg, long amount) { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; if (amount < 1) return; @@ -184,7 +187,7 @@ namespace NadekoBot.Modules.Gambling if (userFlowers < amount) { - await channel.SendErrorAsync($"{guildUser.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"{guildUser.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false); return; } @@ -212,14 +215,14 @@ namespace NadekoBot.Modules.Gambling await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 10, false).ConfigureAwait(false); } - await channel.SendConfirmAsync(str).ConfigureAwait(false); + await Context.Channel.SendConfirmAsync(str).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Leaderboard() { - var channel = (ITextChannel)Context.Channel; + //var channel = (ITextChannel)Context.Channel; IEnumerable richest = new List(); using (var uow = DbHandler.UnitOfWork()) @@ -228,14 +231,14 @@ namespace NadekoBot.Modules.Gambling } if (!richest.Any()) return; - await channel.SendMessageAsync( + await Context.Channel.SendMessageAsync( richest.Aggregate(new StringBuilder( $@"```xl ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓ ┃ Id ┃ $$$ ┃ "), (cur, cs) => cur.AppendLine($@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━┫ -┃{(channel.Guild.GetUser(cs.UserId)?.Username?.TrimTo(18, true) ?? cs.UserId.ToString()),-20} ┃ {cs.Amount,6} ┃") +┃{(Context.Guild.GetUser(cs.UserId)?.Username?.TrimTo(18, true) ?? cs.UserId.ToString()),-20} ┃ {cs.Amount,6} ┃") ).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━┛```").ConfigureAwait(false); } }