This commit is contained in:
samvaio 2016-12-17 03:14:26 +05:30
parent 372d50895b
commit 0b2ea82542
21 changed files with 336 additions and 322 deletions

View File

@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Administration
bool shouldDelete; bool shouldDelete;
using (var uow = DbHandler.UnitOfWork()) 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) if (shouldDelete)

View File

@ -87,7 +87,7 @@ namespace NadekoBot.Modules.Administration
if (msg == null || Context.User.IsBot) if (msg == null || Context.User.IsBot)
return Task.CompletedTask; return Task.CompletedTask;
var channel = Context.Channel as ITextChannel; //var channel = Context.Channel as ITextChannel;
if (channel == null) if (channel == null)
return Task.CompletedTask; return Task.CompletedTask;
@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Administration
try try
{ {
AntiSpamSetting spamSettings; AntiSpamSetting spamSettings;
if (!antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings)) if (!antiSpamGuilds.TryGetValue(Context.Guild.Id, out spamSettings))
return; return;
var stats = spamSettings.UserStats.AddOrUpdate(Context.User.Id, new UserSpamStats(msg.Content), var stats = spamSettings.UserStats.AddOrUpdate(Context.User.Id, new UserSpamStats(msg.Content),
@ -199,27 +199,27 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.Administrator)] [RequireUserPermission(GuildPermission.Administrator)]
public async Task AntiRaid(IUserMessage imsg, int userThreshold, int seconds, PunishmentAction action) 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) 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; return;
} }
if (seconds < 2 || seconds > 300) 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; return;
} }
try try
{ {
await MuteCommands.GetMuteRole(channel.Guild).ConfigureAwait(false); await MuteCommands.GetMuteRole(Context.Guild).ConfigureAwait(false);
} }
catch (Exception ex) 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.") "or create 'nadeko-mute' role with disabled SendMessages and try again.")
.ConfigureAwait(false); .ConfigureAwait(false);
_log.Warn(ex); _log.Warn(ex);
@ -232,9 +232,9 @@ namespace NadekoBot.Modules.Administration
Seconds = seconds, Seconds = seconds,
UserThreshold = userThreshold, 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); .ConfigureAwait(false);
} }
@ -243,37 +243,37 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.Administrator)] [RequireUserPermission(GuildPermission.Administrator)]
public async Task AntiSpam(IUserMessage imsg, int messageCount=3, PunishmentAction action = PunishmentAction.Mute) 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) if (messageCount < 2 || messageCount > 10)
return; return;
AntiSpamSetting throwaway; 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 else
{ {
try try
{ {
await MuteCommands.GetMuteRole(channel.Guild).ConfigureAwait(false); await MuteCommands.GetMuteRole(Context.Guild).ConfigureAwait(false);
} }
catch (Exception ex) 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.") "or create 'nadeko-mute' role with disabled SendMessages and try again.")
.ConfigureAwait(false); .ConfigureAwait(false);
_log.Warn(ex); _log.Warn(ex);
return; return;
} }
if (antiSpamGuilds.TryAdd(channel.Guild.Id, new AntiSpamSetting() if (antiSpamGuilds.TryAdd(Context.Guild.Id, new AntiSpamSetting()
{ {
Action = action, Action = action,
MessageThreshold = messageCount, 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);
} }
} }

View File

@ -48,12 +48,12 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)]
public async Task AutoAssignRole(IUserMessage umsg, [Remainder] IRole role = null) public async Task AutoAssignRole(IUserMessage umsg, [Remainder] IRole role = null)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
GuildConfig conf; GuildConfig conf;
using (var uow = DbHandler.UnitOfWork()) 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) if (role == null)
conf.AutoAssignRoleId = 0; conf.AutoAssignRoleId = 0;
else else
@ -64,11 +64,11 @@ namespace NadekoBot.Modules.Administration
if (role == null) 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; 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);
} }
} }
} }

View File

@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Administration
if (msg == null) if (msg == null)
return Task.CompletedTask; return Task.CompletedTask;
var channel = Context.Channel as ITextChannel; //var channel = Context.Channel as ITextChannel;
if (channel == null) if (channel == null)
return Task.CompletedTask; return Task.CompletedTask;
@ -42,7 +42,7 @@ namespace NadekoBot.Modules.Administration
continue; continue;
foreach (var chan in set.Except(new[] { channel })) 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] [OwnerOnly]
public async Task Scsc() public async Task Scsc()
{ {
var channel = (ITextChannel)Context.Channel; ////var channel = (ITextChannel)Context.Channel;
var token = new NadekoRandom().Next(); var token = new NadekoRandom().Next();
var set = new ConcurrentHashSet<ITextChannel>(); var set = new ConcurrentHashSet<ITextChannel>();
if (Subscribers.TryAdd(token, set)) if (Subscribers.TryAdd(token, set))
@ -76,13 +76,13 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task Jcsc(IUserMessage imsg, int token) public async Task Jcsc(IUserMessage imsg, int token)
{ {
var channel = (ITextChannel)Context.Channel; ////var channel = (ITextChannel)Context.Channel;
ConcurrentHashSet<ITextChannel> set; ConcurrentHashSet<ITextChannel> set;
if (!Subscribers.TryGetValue(token, out set)) if (!Subscribers.TryGetValue(token, out set))
return; return;
set.Add(channel); 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] [NadekoCommand, Usage, Description, Aliases]
@ -90,13 +90,13 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task Lcsc() public async Task Lcsc()
{ {
var channel = (ITextChannel)Context.Channel; ////var channel = (ITextChannel)Context.Channel;
foreach (var subscriber in Subscribers) foreach (var subscriber in Subscribers)
{ {
subscriber.Value.TryRemove(channel); subscriber.Value.TryRemove(channel);
} }
await channel.SendMessageAsync("Left cross server channel.").ConfigureAwait(false); await Context.Channel.SendMessageAsync("Left cross server channel.").ConfigureAwait(false);
} }
} }
} }

View File

@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Administration
[OwnerOnly] [OwnerOnly]
public async Task ForwardMessages() public async Task ForwardMessages()
{ {
var channel = Context.Channel; //var channel = Context.Channel;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -40,16 +40,16 @@ namespace NadekoBot.Modules.Administration
uow.Complete(); uow.Complete();
} }
if (ForwardDMs) 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 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] [NadekoCommand, Usage, Description, Aliases]
[OwnerOnly] [OwnerOnly]
public async Task ForwardToAll() public async Task ForwardToAll()
{ {
var channel = Context.Channel; //var channel = Context.Channel;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -58,9 +58,9 @@ namespace NadekoBot.Modules.Administration
uow.Complete(); uow.Complete();
} }
if (ForwardDMsToAllOwners) 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 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);
} }

View File

@ -469,19 +469,19 @@ namespace NadekoBot.Modules.Administration
if (msg == null || msg.IsAuthor()) if (msg == null || msg.IsAuthor())
return Task.CompletedTask; return Task.CompletedTask;
var channel = Context.Channel as ITextChannel; //var channel = Context.Channel as ITextChannel;
if (channel == null) if (channel == null)
return Task.CompletedTask; return Task.CompletedTask;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(Context.Guild.Id, out logSetting)
|| !logSetting.IsLogging || !logSetting.IsLogging
|| !logSetting.MessageDeleted || !logSetting.MessageDeleted
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
return Task.CompletedTask; return Task.CompletedTask;
ITextChannel logChannel; 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; return Task.CompletedTask;
var task = Task.Run(async () => var task = Task.Run(async () =>
@ -510,19 +510,19 @@ namespace NadekoBot.Modules.Administration
if (before == null) if (before == null)
return Task.CompletedTask; return Task.CompletedTask;
var channel = after.Channel as ITextChannel; //var channel = after.Channel as ITextChannel;
if (channel == null) if (channel == null)
return Task.CompletedTask; return Task.CompletedTask;
LogSetting logSetting; LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) if (!GuildLogSettings.TryGetValue(Context.Guild.Id, out logSetting)
|| !logSetting.IsLogging || !logSetting.IsLogging
|| !logSetting.MessageUpdated || !logSetting.MessageUpdated
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
return Task.CompletedTask; return Task.CompletedTask;
ITextChannel logChannel; 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; return Task.CompletedTask;
var task = Task.Run(async () => var task = Task.Run(async () =>
@ -553,7 +553,7 @@ namespace NadekoBot.Modules.Administration
id = logSetting.UserPresenceChannelId; id = logSetting.UserPresenceChannelId;
break; break;
} }
var channel = guild.GetTextChannel(id); //var channel = guild.GetTextChannel(id);
if (channel == null) if (channel == null)
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
@ -585,12 +585,12 @@ namespace NadekoBot.Modules.Administration
[OwnerOnly] [OwnerOnly]
public async Task LogServer() public async Task LogServer()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
LogSetting logSetting; LogSetting logSetting;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting; logSetting = uow.GuildConfigs.For(Context.Guild.Id).LogSetting;
GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); GuildLogSettings.AddOrUpdate(Context.Guild.Id, (id) => logSetting, (id, old) => logSetting);
logSetting.IsLogging = !logSetting.IsLogging; logSetting.IsLogging = !logSetting.IsLogging;
if (logSetting.IsLogging) if (logSetting.IsLogging)
logSetting.ChannelId = channel.Id; logSetting.ChannelId = channel.Id;
@ -598,9 +598,9 @@ namespace NadekoBot.Modules.Administration
} }
if (logSetting.IsLogging) if (logSetting.IsLogging)
await channel.SendMessageAsync("✅ **Logging enabled.**").ConfigureAwait(false); await Context.Channel.SendMessageAsync("✅ **Logging enabled.**").ConfigureAwait(false);
else else
await channel.SendMessageAsync(" **Logging disabled.**").ConfigureAwait(false); await Context.Channel.SendMessageAsync(" **Logging disabled.**").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -609,12 +609,12 @@ namespace NadekoBot.Modules.Administration
[OwnerOnly] [OwnerOnly]
public async Task LogIgnore() public async Task LogIgnore()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
int removed; int removed;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
var config = uow.GuildConfigs.For(channel.Guild.Id); var config = uow.GuildConfigs.For(Context.Guild.Id);
LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); LogSetting logSetting = GuildLogSettings.GetOrAdd(Context.Guild.Id, (id) => config.LogSetting);
removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id); removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id); config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
if (removed == 0) if (removed == 0)
@ -627,9 +627,9 @@ namespace NadekoBot.Modules.Administration
} }
if (removed == 0) 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 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] //[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
@ -637,7 +637,7 @@ namespace NadekoBot.Modules.Administration
//[OwnerOnly] //[OwnerOnly]
//public async Task LogAdd([Remainder] string eventName) //public async Task LogAdd([Remainder] string eventName)
//{ //{
// var channel = (ITextChannel)Context.Channel; // //var channel = (ITextChannel)Context.Channel;
// //eventName = eventName?.Replace(" ","").ToLowerInvariant(); // //eventName = eventName?.Replace(" ","").ToLowerInvariant();
// switch (eventName.ToLowerInvariant()) // switch (eventName.ToLowerInvariant())
@ -653,16 +653,16 @@ namespace NadekoBot.Modules.Administration
// case "channelupdated": // case "channelupdated":
// using (var uow = DbHandler.UnitOfWork()) // using (var uow = DbHandler.UnitOfWork())
// { // {
// var logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting; // var logSetting = uow.GuildConfigs.For(Context.Guild.Id).LogSetting;
// GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); // GuildLogSettings.AddOrUpdate(Context.Guild.Id, (id) => logSetting, (id, old) => logSetting);
// var prop = logSetting.GetType().GetProperty(eventName); // var prop = logSetting.GetType().GetProperty(eventName);
// prop.SetValue(logSetting, true); // prop.SetValue(logSetting, true);
// await uow.CompleteAsync().ConfigureAwait(false); // 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; // break;
// default: // default:
// await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false); // await Context.Channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false);
// break; // break;
// } // }
//} //}
@ -671,7 +671,7 @@ namespace NadekoBot.Modules.Administration
//[RequireContext(ContextType.Guild)] //[RequireContext(ContextType.Guild)]
//public async Task LogRemove(string eventName) //public async Task LogRemove(string eventName)
//{ //{
// var channel = (ITextChannel)Context.Channel; // //var channel = (ITextChannel)Context.Channel;
// eventName = eventName.ToLowerInvariant(); // eventName = eventName.ToLowerInvariant();
// switch (eventName) // switch (eventName)
@ -688,16 +688,16 @@ namespace NadekoBot.Modules.Administration
// case "channelupdated": // case "channelupdated":
// using (var uow = DbHandler.UnitOfWork()) // using (var uow = DbHandler.UnitOfWork())
// { // {
// var config = uow.GuildConfigs.For(channel.Guild.Id); // var config = uow.GuildConfigs.For(Context.Guild.Id);
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); // LogSetting logSetting = GuildLogSettings.GetOrAdd(Context.Guild.Id, (id) => config.LogSetting);
// logSetting.GetType().GetProperty(eventName).SetValue(logSetting, false); // logSetting.GetType().GetProperty(eventName).SetValue(logSetting, false);
// config.LogSetting = logSetting; // config.LogSetting = logSetting;
// await uow.CompleteAsync().ConfigureAwait(false); // 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; // break;
// default: // default:
// await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false); // await Context.Channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false);
// break; // break;
// } // }
//} //}
@ -707,12 +707,12 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.Administrator)] [RequireUserPermission(GuildPermission.Administrator)]
public async Task UserPresence() public async Task UserPresence()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
bool enabled; bool enabled;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
var logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting; var logSetting = uow.GuildConfigs.For(Context.Guild.Id).LogSetting;
GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); GuildLogSettings.AddOrUpdate(Context.Guild.Id, (id) => logSetting, (id, old) => logSetting);
enabled = logSetting.LogUserPresence = !logSetting.LogUserPresence; enabled = logSetting.LogUserPresence = !logSetting.LogUserPresence;
if(enabled) if(enabled)
logSetting.UserPresenceChannelId = channel.Id; logSetting.UserPresenceChannelId = channel.Id;
@ -720,9 +720,9 @@ namespace NadekoBot.Modules.Administration
} }
if (enabled) 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 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] [NadekoCommand, Usage, Description, Aliases]
@ -730,14 +730,14 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.Administrator)] [RequireUserPermission(GuildPermission.Administrator)]
public async Task VoicePresence() public async Task VoicePresence()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
bool enabled; bool enabled;
using (var uow = DbHandler.UnitOfWork()) 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)) .ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds))
.LogSetting; .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; enabled = logSetting.LogVoicePresence = !logSetting.LogVoicePresence;
if (enabled) if (enabled)
logSetting.VoicePresenceChannelId = channel.Id; logSetting.VoicePresenceChannelId = channel.Id;
@ -745,21 +745,21 @@ namespace NadekoBot.Modules.Administration
} }
if (enabled) 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 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] //[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
//[RequireContext(ContextType.Guild)] //[RequireContext(ContextType.Guild)]
//public async Task VoiPresIgnore(IUserMessage imsg, IVoiceChannel voiceChannel) //public async Task VoiPresIgnore(IUserMessage imsg, IVoiceChannel voiceChannel)
//{ //{
// var channel = (ITextChannel)Context.Channel; // //var channel = (ITextChannel)Context.Channel;
// int removed; // int removed;
// using (var uow = DbHandler.UnitOfWork()) // using (var uow = DbHandler.UnitOfWork())
// { // {
// var config = uow.GuildConfigs.For(channel.Guild.Id); // var config = uow.GuildConfigs.For(Context.Guild.Id);
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); // LogSetting logSetting = GuildLogSettings.GetOrAdd(Context.Guild.Id, (id) => config.LogSetting);
// removed = logSetting.IgnoredVoicePresenceChannelIds.RemoveWhere(ivpc => ivpc.ChannelId == voiceChannel.Id); // removed = logSetting.IgnoredVoicePresenceChannelIds.RemoveWhere(ivpc => ivpc.ChannelId == voiceChannel.Id);
// if (removed == 0) // if (removed == 0)
// logSetting.IgnoredVoicePresenceChannelIds.Add(new IgnoredVoicePresenceChannel { ChannelId = voiceChannel.Id }); // logSetting.IgnoredVoicePresenceChannelIds.Add(new IgnoredVoicePresenceChannel { ChannelId = voiceChannel.Id });
@ -768,9 +768,9 @@ namespace NadekoBot.Modules.Administration
// } // }
// if (removed == 0) // 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 // 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);
//} //}
} }
} }

View File

@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Administration
await Task.Delay(Repeater.Interval, token).ConfigureAwait(false); await Task.Delay(Repeater.Interval, token).ConfigureAwait(false);
if (oldMsg != null) if (oldMsg != null)
try { await oldMsg.DeleteAsync(); } catch { } 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) { } catch (OperationCanceledException) { }
@ -84,16 +84,16 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageMessages)] [RequireUserPermission(GuildPermission.ManageMessages)]
public async Task RepeatInvoke() public async Task RepeatInvoke()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
RepeatRunner rep; RepeatRunner rep;
if (!repeaters.TryGetValue(channel.Id, out 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; return;
} }
rep.Reset(); rep.Reset();
await channel.SendMessageAsync("🔄 " + rep.Repeater.Message).ConfigureAwait(false); await Context.Channel.SendMessageAsync("🔄 " + rep.Repeater.Message).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -101,7 +101,7 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageMessages)] [RequireUserPermission(GuildPermission.ManageMessages)]
public async Task Repeat() public async Task Repeat()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
RepeatRunner rep; RepeatRunner rep;
if (repeaters.TryRemove(channel.Id, out rep)) if (repeaters.TryRemove(channel.Id, out rep))
{ {
@ -111,10 +111,10 @@ namespace NadekoBot.Modules.Administration
await uow.CompleteAsync(); await uow.CompleteAsync();
} }
rep.Stop(); rep.Stop();
await channel.SendConfirmAsync("✅ **Stopped repeating a message.**").ConfigureAwait(false); await Context.Channel.SendConfirmAsync("✅ **Stopped repeating a message.**").ConfigureAwait(false);
} }
else else
await channel.SendConfirmAsync(" **No message is repeating.**").ConfigureAwait(false); await Context.Channel.SendConfirmAsync(" **No message is repeating.**").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -122,7 +122,7 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageMessages)] [RequireUserPermission(GuildPermission.ManageMessages)]
public async Task Repeat(IUserMessage imsg, int minutes, [Remainder] string message) 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) if (minutes < 1 || minutes > 10080)
return; return;
@ -139,7 +139,7 @@ namespace NadekoBot.Modules.Administration
var localRep = new Repeater var localRep = new Repeater
{ {
ChannelId = channel.Id, ChannelId = channel.Id,
GuildId = channel.Guild.Id, GuildId = Context.Guild.Id,
Interval = TimeSpan.FromMinutes(minutes), Interval = TimeSpan.FromMinutes(minutes),
Message = message, Message = message,
}; };
@ -160,7 +160,7 @@ namespace NadekoBot.Modules.Administration
return old; 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);
} }
} }
} }

View File

@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Administration
[OwnerOnly] [OwnerOnly]
public async Task MigrateData() public async Task MigrateData()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
var version = 0; var version = 0;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())

View File

@ -141,19 +141,19 @@ namespace NadekoBot.Modules.Administration
[Priority(1)] [Priority(1)]
public async Task SetMuteRole(IUserMessage imsg, [Remainder] string name) public async Task SetMuteRole(IUserMessage imsg, [Remainder] string name)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
name = name.Trim(); name = name.Trim();
if (string.IsNullOrWhiteSpace(name)) if (string.IsNullOrWhiteSpace(name))
return; return;
using (var uow = DbHandler.UnitOfWork()) 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; 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 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] [NadekoCommand, Usage, Description, Aliases]
@ -169,16 +169,16 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.MuteMembers)] [RequireUserPermission(GuildPermission.MuteMembers)]
public async Task Mute(IUserMessage umsg, IGuildUser user) public async Task Mute(IUserMessage umsg, IGuildUser user)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
try try
{ {
await Mute(user).ConfigureAwait(false); 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 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)] [RequireUserPermission(GuildPermission.MuteMembers)]
public async Task Unmute(IUserMessage umsg, IGuildUser user) public async Task Unmute(IUserMessage umsg, IGuildUser user)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
try try
{ {
await Unmute(user).ConfigureAwait(false); 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 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)] [RequireUserPermission(GuildPermission.ManageRoles)]
public async Task ChatMute(IUserMessage umsg, IGuildUser user) public async Task ChatMute(IUserMessage umsg, IGuildUser user)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
try 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 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 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)] [RequireUserPermission(GuildPermission.ManageRoles)]
public async Task ChatUnmute(IUserMessage umsg, IGuildUser user) public async Task ChatUnmute(IUserMessage umsg, IGuildUser user)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
try 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 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 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)] [RequireUserPermission(GuildPermission.MuteMembers)]
public async Task VoiceMute(IUserMessage umsg, IGuildUser user) public async Task VoiceMute(IUserMessage umsg, IGuildUser user)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
try try
{ {
await user.ModifyAsync(usr => usr.Mute = true).ConfigureAwait(false); await user.ModifyAsync(usr => usr.Mute = true).ConfigureAwait(false);
await UserMuted(user, MuteType.Voice).ConfigureAwait(false); 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 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)] [RequireUserPermission(GuildPermission.MuteMembers)]
public async Task VoiceUnmute(IUserMessage umsg, IGuildUser user) public async Task VoiceUnmute(IUserMessage umsg, IGuildUser user)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
try try
{ {
await user.ModifyAsync(usr => usr.Mute = false).ConfigureAwait(false); await user.ModifyAsync(usr => usr.Mute = false).ConfigureAwait(false);
await UserUnmuted(user, MuteType.Voice).ConfigureAwait(false); 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 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);
} }
} }
} }

View File

@ -68,7 +68,7 @@ namespace NadekoBot.Modules.Administration
var t = Task.Run(async () => var t = Task.Run(async () =>
{ {
var usrMsg = umsg as IUserMessage; var usrMsg = umsg as IUserMessage;
var channel = usrContext.Channel as ITextChannel; //var channel = usrContext.Channel as ITextChannel;
if (channel == null || usrMsg.IsAuthor()) if (channel == null || usrMsg.IsAuthor())
return; return;
@ -88,13 +88,13 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageMessages)] [RequireUserPermission(GuildPermission.ManageMessages)]
public async Task Slowmode() public async Task Slowmode()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
Ratelimiter throwaway; Ratelimiter throwaway;
if (RatelimitingChannels.TryRemove(channel.Id, out throwaway)) if (RatelimitingChannels.TryRemove(channel.Id, out throwaway))
{ {
throwaway.cancelSource.Cancel(); throwaway.cancelSource.Cancel();
await channel.SendConfirmAsync(" Slow mode disabled.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync(" Slow mode disabled.").ConfigureAwait(false);
return; return;
} }
} }
@ -105,11 +105,11 @@ namespace NadekoBot.Modules.Administration
public async Task Slowmode(IUserMessage umsg, int msg, int perSec) public async Task Slowmode(IUserMessage umsg, int msg, int perSec)
{ {
await Slowmode(umsg).ConfigureAwait(false); // disable if exists 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) if (msg < 1 || perSec < 1 || msg > 100 || perSec > 3600)
{ {
await channel.SendErrorAsync("⚠️ Invalid parameters."); await Context.Channel.SendErrorAsync("⚠️ Invalid parameters.");
return; return;
} }
var toAdd = new Ratelimiter() var toAdd = new Ratelimiter()
@ -120,7 +120,7 @@ namespace NadekoBot.Modules.Administration
}; };
if(RatelimitingChannels.TryAdd(channel.Id, toAdd)) 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)`.") $"Users can't send more than `{toAdd.MaxMessages} message(s)` every `{toAdd.PerSeconds} second(s)`.")
.ConfigureAwait(false); .ConfigureAwait(false);
} }

View File

@ -24,16 +24,16 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageMessages)] [RequireUserPermission(GuildPermission.ManageMessages)]
public async Task AdSarm() public async Task AdSarm()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
bool newval; bool newval;
using (var uow = DbHandler.UnitOfWork()) 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; newval = config.AutoDeleteSelfAssignedRoleMessages = !config.AutoDeleteSelfAssignedRoleMessages;
await uow.CompleteAsync().ConfigureAwait(false); 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); .ConfigureAwait(false);
} }
@ -42,17 +42,17 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)]
public async Task Asar(IUserMessage umsg, [Remainder] IRole role) public async Task Asar(IUserMessage umsg, [Remainder] IRole role)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
IEnumerable<SelfAssignedRole> roles; IEnumerable<SelfAssignedRole> roles;
string msg; string msg;
using (var uow = DbHandler.UnitOfWork()) 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)) 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; return;
} }
else else
@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Administration
msg = $"🆗 Role **{role.Name}** added to the list."; 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] [NadekoCommand, Usage, Description, Aliases]
@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)]
public async Task Rsar(IUserMessage umsg, [Remainder] IRole role) public async Task Rsar(IUserMessage umsg, [Remainder] IRole role)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
bool success; bool success;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
@ -83,17 +83,17 @@ namespace NadekoBot.Modules.Administration
} }
if (!success) 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; 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Lsar() public async Task Lsar()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
var toRemove = new ConcurrentHashSet<SelfAssignedRole>(); var toRemove = new ConcurrentHashSet<SelfAssignedRole>();
var removeMsg = new StringBuilder(); var removeMsg = new StringBuilder();
@ -101,13 +101,13 @@ namespace NadekoBot.Modules.Administration
var roleCnt = 0; var roleCnt = 0;
using (var uow = DbHandler.UnitOfWork()) 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; roleCnt = roleModels.Count;
msg.AppendLine(); msg.AppendLine();
foreach (var roleModel in roleModels) 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) if (role == null)
{ {
uow.SelfAssignedRoles.Remove(roleModel); uow.SelfAssignedRoles.Remove(roleModel);
@ -123,7 +123,7 @@ namespace NadekoBot.Modules.Administration
} }
await uow.CompleteAsync(); 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] [NadekoCommand, Usage, Description, Aliases]
@ -131,25 +131,25 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)]
public async Task Tesar() public async Task Tesar()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
bool areExclusive; bool areExclusive;
using (var uow = DbHandler.UnitOfWork()) 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; areExclusive = config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles;
await uow.CompleteAsync(); await uow.CompleteAsync();
} }
string exl = areExclusive ? "**exclusive**." : "**not exclusive**."; 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Iam(IUserMessage umsg, [Remainder] IRole role) 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 guildUser = (IGuildUser)Context.User;
var usrMsg = (IUserMessage)umsg; var usrMsg = (IUserMessage)umsg;
@ -157,18 +157,18 @@ namespace NadekoBot.Modules.Administration
IEnumerable<SelfAssignedRole> roles; IEnumerable<SelfAssignedRole> roles;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
conf = uow.GuildConfigs.For(channel.Guild.Id, set => set); conf = uow.GuildConfigs.For(Context.Guild.Id, set => set);
roles = uow.SelfAssignedRoles.GetFromGuild(channel.Guild.Id); roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id);
} }
SelfAssignedRole roleModel; SelfAssignedRole roleModel;
if ((roleModel = roles.FirstOrDefault(r=>r.RoleId == role.Id)) == null) 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; return;
} }
if (guildUser.Roles.Contains(role)) 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; return;
} }
@ -177,7 +177,7 @@ namespace NadekoBot.Modules.Administration
var sameRoles = guildUser.Roles.Where(r => roles.Any(rm => rm.RoleId == r.Id)); var sameRoles = guildUser.Roles.Where(r => roles.Any(rm => rm.RoleId == r.Id));
if (sameRoles.Any()) 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; return;
} }
} }
@ -187,11 +187,11 @@ namespace NadekoBot.Modules.Administration
} }
catch (Exception ex) 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); Console.WriteLine(ex);
return; 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) if (conf.AutoDeleteSelfAssignedRoleMessages)
{ {
@ -208,25 +208,25 @@ namespace NadekoBot.Modules.Administration
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Iamnot(IUserMessage umsg, [Remainder] IRole role) public async Task Iamnot(IUserMessage umsg, [Remainder] IRole role)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
var guildUser = (IGuildUser)Context.User; var guildUser = (IGuildUser)Context.User;
bool autoDeleteSelfAssignedRoleMessages; bool autoDeleteSelfAssignedRoleMessages;
IEnumerable<SelfAssignedRole> roles; IEnumerable<SelfAssignedRole> roles;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
autoDeleteSelfAssignedRoleMessages = uow.GuildConfigs.For(channel.Guild.Id, set => set).AutoDeleteSelfAssignedRoleMessages; autoDeleteSelfAssignedRoleMessages = uow.GuildConfigs.For(Context.Guild.Id, set => set).AutoDeleteSelfAssignedRoleMessages;
roles = uow.SelfAssignedRoles.GetFromGuild(channel.Guild.Id); roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id);
} }
SelfAssignedRole roleModel; SelfAssignedRole roleModel;
if ((roleModel = roles.FirstOrDefault(r => r.RoleId == role.Id)) == null) 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; return;
} }
if (!guildUser.Roles.Contains(role)) 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; return;
} }
try try
@ -235,10 +235,10 @@ namespace NadekoBot.Modules.Administration
} }
catch (Exception) 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; 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) if (autoDeleteSelfAssignedRoleMessages)
{ {

View File

@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Administration
[OwnerOnly] [OwnerOnly]
public async Task Leave(IUserMessage umsg, [Remainder] string guildStr) public async Task Leave(IUserMessage umsg, [Remainder] string guildStr)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
guildStr = guildStr.Trim().ToUpperInvariant(); guildStr = guildStr.Trim().ToUpperInvariant();
var server = _client.GetGuilds().FirstOrDefault(g => g.Id.ToString().Trim().ToUpperInvariant() == guildStr) ?? var server = _client.GetGuilds().FirstOrDefault(g => g.Id.ToString().Trim().ToUpperInvariant() == guildStr) ??
@ -32,18 +32,18 @@ namespace NadekoBot.Modules.Administration
if (server == null) if (server == null)
{ {
await channel.SendErrorAsync("⚠️ Cannot find that server").ConfigureAwait(false); await Context.Channel.SendErrorAsync("⚠️ Cannot find that server").ConfigureAwait(false);
return; return;
} }
if (server.OwnerId != _client.CurrentUser().Id) if (server.OwnerId != _client.CurrentUser().Id)
{ {
await server.LeaveAsync().ConfigureAwait(false); 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 else
{ {
await server.DeleteAsync().ConfigureAwait(false); await server.DeleteAsync().ConfigureAwait(false);
await channel.SendConfirmAsync("Deleted server " + server.Name).ConfigureAwait(false); await Context.Channel.SendConfirmAsync("Deleted server " + server.Name).ConfigureAwait(false);
} }
} }
} }

View File

@ -39,7 +39,7 @@ namespace NadekoBot.Modules.Administration
} }
if (!conf.SendChannelByeMessage) return; if (!conf.SendChannelByeMessage) return;
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.ByeMessageChannelId); //var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.ByeMessageChannelId);
if (channel == null) //maybe warn the server owner that the channel is missing if (channel == null) //maybe warn the server owner that the channel is missing
return; return;
@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Administration
return; return;
try try
{ {
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false); var toDelete = await Context.Channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
if (conf.AutoDeleteByeMessagesTimer > 0) if (conf.AutoDeleteByeMessagesTimer > 0)
{ {
var t = Task.Run(async () => var t = Task.Run(async () =>
@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Administration
if (conf.SendChannelGreetMessage) 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 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); 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 try
{ {
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false); var toDelete = await Context.Channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
if (conf.AutoDeleteGreetMessagesTimer > 0) if (conf.AutoDeleteGreetMessagesTimer > 0)
{ {
var t = Task.Run(async () => var t = Task.Run(async () =>
@ -105,14 +105,14 @@ namespace NadekoBot.Modules.Administration
if (conf.SendDmGreetMessage) if (conf.SendDmGreetMessage)
{ {
var channel = await user.CreateDMChannelAsync(); //var channel = await user.CreateDMChannelAsync();
if (channel != null) if (channel != null)
{ {
var msg = conf.DmGreetMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name); var msg = conf.DmGreetMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name);
if (!string.IsNullOrWhiteSpace(msg)) 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)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task GreetDel(IUserMessage umsg, int timer = 30) public async Task GreetDel(IUserMessage umsg, int timer = 30)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (timer < 0 || timer > 600) if (timer < 0 || timer > 600)
return; return;
await ServerGreetCommands.SetGreetDel(channel.Guild.Id, timer).ConfigureAwait(false); await ServerGreetCommands.SetGreetDel(Context.Guild.Id, timer).ConfigureAwait(false);
if (timer > 0) 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 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) private static async Task SetGreetDel(ulong id, int timer)
@ -158,14 +158,14 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task Greet() 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) 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 else
await channel.SendConfirmAsync(" Greeting messages **disabled**.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync(" Greeting messages **disabled**.").ConfigureAwait(false);
} }
private static async Task<bool> SetGreet(ulong guildId, ulong channelId, bool? value = null) private static async Task<bool> SetGreet(ulong guildId, ulong channelId, bool? value = null)
@ -187,24 +187,24 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task GreetMsg(IUserMessage umsg, [Remainder] string text = null) public async Task GreetMsg(IUserMessage umsg, [Remainder] string text = null)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (string.IsNullOrWhiteSpace(text)) if (string.IsNullOrWhiteSpace(text))
{ {
string channelGreetMessageText; string channelGreetMessageText;
using (var uow = DbHandler.UnitOfWork()) 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; 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) 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) public static bool SetGreetMessage(ulong guildId, ref string message)
@ -231,14 +231,14 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task GreetDm() 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) if (enabled)
await channel.SendConfirmAsync("🆗 DM Greet announcements **enabled**.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync("🆗 DM Greet announcements **enabled**.").ConfigureAwait(false);
else else
await channel.SendConfirmAsync(" Greet announcements **disabled**.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync(" Greet announcements **disabled**.").ConfigureAwait(false);
} }
private static async Task<bool> SetGreetDm(ulong guildId, bool? value = null) private static async Task<bool> SetGreetDm(ulong guildId, bool? value = null)
@ -259,24 +259,24 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task GreetDmMsg(IUserMessage umsg, [Remainder] string text = null) public async Task GreetDmMsg(IUserMessage umsg, [Remainder] string text = null)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (string.IsNullOrWhiteSpace(text)) if (string.IsNullOrWhiteSpace(text))
{ {
GuildConfig config; GuildConfig config;
using (var uow = DbHandler.UnitOfWork()) 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; 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) 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) public static bool SetGreetDmMessage(ulong guildId, ref string message)
@ -303,14 +303,14 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task Bye() 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) 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 else
await channel.SendConfirmAsync(" Bye announcements **disabled**.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync(" Bye announcements **disabled**.").ConfigureAwait(false);
} }
private static async Task<bool> SetBye(ulong guildId, ulong channelId, bool? value = null) private static async Task<bool> SetBye(ulong guildId, ulong channelId, bool? value = null)
@ -332,24 +332,24 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task ByeMsg(IUserMessage umsg, [Remainder] string text = null) public async Task ByeMsg(IUserMessage umsg, [Remainder] string text = null)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (string.IsNullOrWhiteSpace(text)) if (string.IsNullOrWhiteSpace(text))
{ {
string byeMessageText; string byeMessageText;
using (var uow = DbHandler.UnitOfWork()) 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; 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) 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) public static bool SetByeMessage(ulong guildId, ref string message)
@ -376,14 +376,14 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task ByeDel(IUserMessage umsg, int timer = 30) 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) 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 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) private static async Task SetByeDel(ulong id, int timer)

View File

@ -110,13 +110,13 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageChannels)] [RequireUserPermission(GuildPermission.ManageChannels)]
public async Task VoicePlusText() public async Task VoicePlusText()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
var guild = channel.Guild; var guild = Context.Guild;
var botUser = await guild.GetCurrentUserAsync().ConfigureAwait(false); var botUser = await guild.GetCurrentUserAsync().ConfigureAwait(false);
if (!botUser.GuildPermissions.ManageRoles || !botUser.GuildPermissions.ManageChannels) 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; return;
} }
@ -124,7 +124,7 @@ namespace NadekoBot.Modules.Administration
{ {
try 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.`"); "`This may cause some issues, and you will have to clean up text channels yourself afterwards.`");
} }
catch { } catch { }
@ -145,16 +145,16 @@ namespace NadekoBot.Modules.Administration
{ {
try { await textChannel.DeleteAsync().ConfigureAwait(false); } catch { } 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; return;
} }
voicePlusTextCache.Add(guild.Id); 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) catch (Exception ex)
{ {
await channel.SendErrorAsync(ex.ToString()).ConfigureAwait(false); await Context.Channel.SendErrorAsync(ex.ToString()).ConfigureAwait(false);
} }
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -163,12 +163,12 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)]
public async Task CleanVPlusT() public async Task CleanVPlusT()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
var guild = channel.Guild; var guild = Context.Guild;
var botUser = await guild.GetCurrentUserAsync().ConfigureAwait(false); var botUser = await guild.GetCurrentUserAsync().ConfigureAwait(false);
if (!botUser.GuildPermissions.Administrator) 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; return;
} }
@ -183,7 +183,7 @@ namespace NadekoBot.Modules.Administration
await Task.Delay(500); await Task.Delay(500);
} }
await channel.SendConfirmAsync("Cleaned v+t.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync("Cleaned v+t.").ConfigureAwait(false);
} }
} }
} }

View File

@ -59,7 +59,7 @@ namespace NadekoBot.Modules.ClashOfClans
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task CreateWar(IUserMessage umsg, int size, [Remainder] string enemyClan = null) 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) if (!(Context.User as IGuildUser).GuildPermissions.ManageChannels)
return; return;
@ -69,29 +69,32 @@ namespace NadekoBot.Modules.ClashOfClans
if (size < 10 || size > 50 || size % 5 != 0) 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; return;
} }
List<ClashWar> wars; List<ClashWar> 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<ClashWar>(); wars = new List<ClashWar>();
if (!ClashWars.TryAdd(channel.Guild.Id, wars)) if (!ClashWars.TryAdd(Context.Guild.Id, wars))
//if (!ClashWars.TryAdd(channel.Guild.Id, wars))
return; 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); 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task StartWar(IUserMessage umsg, [Remainder] string number = null) public async Task StartWar(IUserMessage umsg, [Remainder] string number = null)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
int num = 0; int num = 0;
int.TryParse(number, out num); int.TryParse(number, out num);
@ -99,18 +102,18 @@ namespace NadekoBot.Modules.ClashOfClans
var warsInfo = GetWarInfo(umsg, num); var warsInfo = GetWarInfo(umsg, num);
if (warsInfo == null) 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; return;
} }
var war = warsInfo.Item1[warsInfo.Item2]; var war = warsInfo.Item1[warsInfo.Item2];
try try
{ {
war.Start(); war.Start();
await channel.SendConfirmAsync($"🔰**STARTED WAR AGAINST {war.ShortPrint()}**").ConfigureAwait(false); await Context.Channel.SendConfirmAsync($"🔰**STARTED WAR AGAINST {war.ShortPrint()}**").ConfigureAwait(false);
} }
catch 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); SaveWar(war);
} }
@ -119,17 +122,18 @@ namespace NadekoBot.Modules.ClashOfClans
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ListWar(IUserMessage umsg, [Remainder] string number = null) 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 number is null, print all wars in a short way
if (string.IsNullOrWhiteSpace(number)) if (string.IsNullOrWhiteSpace(number))
{ {
//check if there are any wars //check if there are any wars
List<ClashWar> wars = null; List<ClashWar> 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) if (wars == null || wars.Count == 0)
{ {
await channel.SendErrorAsync("🔰 **No active wars.**").ConfigureAwait(false); await Context.Channel.SendErrorAsync("🔰 **No active wars.**").ConfigureAwait(false);
return; return;
} }
@ -142,7 +146,7 @@ namespace NadekoBot.Modules.ClashOfClans
sb.AppendLine($"\t\t`Size:` **{wars[i].Size} v {wars[i].Size}**"); sb.AppendLine($"\t\t`Size:` **{wars[i].Size} v {wars[i].Size}**");
sb.AppendLine("**-------------------------**"); sb.AppendLine("**-------------------------**");
} }
await channel.SendConfirmAsync(sb.ToString()).ConfigureAwait(false); await Context.Channel.SendConfirmAsync(sb.ToString()).ConfigureAwait(false);
return; return;
} }
@ -152,21 +156,21 @@ namespace NadekoBot.Modules.ClashOfClans
var warsInfo = GetWarInfo(umsg, num); var warsInfo = GetWarInfo(umsg, num);
if (warsInfo == null) 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; 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Claim(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null) 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); var warsInfo = GetWarInfo(umsg, number);
if (warsInfo == null || warsInfo.Item1.Count == 0) 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; return;
} }
var usr = var usr =
@ -178,11 +182,11 @@ namespace NadekoBot.Modules.ClashOfClans
var war = warsInfo.Item1[warsInfo.Item2]; var war = warsInfo.Item1[warsInfo.Item2];
war.Call(usr, baseNumber - 1); war.Call(usr, baseNumber - 1);
SaveWar(war); 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) 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)] [RequireContext(ContextType.Guild)]
public async Task ClaimFinish1(IUserMessage umsg, int number, int baseNumber = 0) 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); await FinishClaim(umsg, number, baseNumber - 1, 1);
} }
@ -198,7 +202,7 @@ namespace NadekoBot.Modules.ClashOfClans
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ClaimFinish2(IUserMessage umsg, int number, int baseNumber = 0) 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); await FinishClaim(umsg, number, baseNumber - 1, 2);
} }
@ -206,7 +210,7 @@ namespace NadekoBot.Modules.ClashOfClans
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ClaimFinish(IUserMessage umsg, int number, int baseNumber = 0) 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); await FinishClaim(umsg, number, baseNumber - 1);
} }
@ -214,18 +218,18 @@ namespace NadekoBot.Modules.ClashOfClans
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task EndWar(IUserMessage umsg, int number) public async Task EndWar(IUserMessage umsg, int number)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
var warsInfo = GetWarInfo(umsg,number); var warsInfo = GetWarInfo(umsg,number);
if (warsInfo == null) 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; return;
} }
var war = warsInfo.Item1[warsInfo.Item2]; var war = warsInfo.Item1[warsInfo.Item2];
war.End(); war.End();
SaveWar(war); 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; var size = warsInfo.Item1[warsInfo.Item2].Size;
warsInfo.Item1.RemoveAt(warsInfo.Item2); warsInfo.Item1.RemoveAt(warsInfo.Item2);
@ -235,12 +239,12 @@ namespace NadekoBot.Modules.ClashOfClans
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Unclaim(IUserMessage umsg, int number, [Remainder] string otherName = null) 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); var warsInfo = GetWarInfo(umsg, number);
if (warsInfo == null || warsInfo.Item1.Count == 0) 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; return;
} }
var usr = var usr =
@ -252,21 +256,21 @@ namespace NadekoBot.Modules.ClashOfClans
var war = warsInfo.Item1[warsInfo.Item2]; var war = warsInfo.Item1[warsInfo.Item2];
var baseNumber = war.Uncall(usr); var baseNumber = war.Uncall(usr);
SaveWar(war); 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) 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) 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); var warInfo = GetWarInfo(umsg, number);
if (warInfo == null || warInfo.Item1.Count == 0) 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; return;
} }
var war = warInfo.Item1[warInfo.Item2]; var war = warInfo.Item1[warInfo.Item2];
@ -281,17 +285,17 @@ namespace NadekoBot.Modules.ClashOfClans
{ {
war.FinishClaim(baseNumber, stars); 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) catch (Exception ex)
{ {
await channel.SendErrorAsync($"🔰 {ex.Message}").ConfigureAwait(false); await Context.Channel.SendErrorAsync($"🔰 {ex.Message}").ConfigureAwait(false);
} }
} }
private static Tuple<List<ClashWar>, int> GetWarInfo(IUserMessage umsg, int num) private static Tuple<List<ClashWar>, int> GetWarInfo(IUserMessage umsg, int num)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
//check if there are any wars //check if there are any wars
List<ClashWar> wars = null; List<ClashWar> wars = null;
ClashWars.TryGetValue(Context.Guild.Id, out wars); ClashWars.TryGetValue(Context.Guild.Id, out wars);

View File

@ -35,13 +35,14 @@ namespace NadekoBot.Modules.CustomReactions
public static async Task<bool> TryExecuteCustomReaction() public static async Task<bool> TryExecuteCustomReaction()
{ {
var channel = Context.Channel as ITextChannel; //var channel = Context.Channel as ITextChannel;
if (channel == null) if (channel == null)
return false; return false;
var content = umsg.Content.Trim().ToLowerInvariant(); var content = umsg.Content.Trim().ToLowerInvariant();
ConcurrentHashSet<CustomReaction> reactions; ConcurrentHashSet<CustomReaction> 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()) if (reactions != null && reactions.Any())
{ {
var reaction = reactions.Where(cr => var reaction = reactions.Where(cr =>
@ -53,7 +54,7 @@ namespace NadekoBot.Modules.CustomReactions
if (reaction != null) if (reaction != null)
{ {
if (reaction.Response != "-") 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); ReactionStats.AddOrUpdate(reaction.Trigger, 1, (k, old) => ++old);
return true; return true;
@ -68,7 +69,7 @@ namespace NadekoBot.Modules.CustomReactions
if (greaction != null) 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); ReactionStats.AddOrUpdate(greaction.Trigger, 1, (k, old) => ++old);
return true; return true;
} }
@ -78,7 +79,7 @@ namespace NadekoBot.Modules.CustomReactions
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
public async Task AddCustReact(IUserMessage imsg, string key, [Remainder] string message) 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)) if (string.IsNullOrWhiteSpace(message) || string.IsNullOrWhiteSpace(key))
return; return;
@ -111,7 +112,8 @@ namespace NadekoBot.Modules.CustomReactions
} }
else else
{ {
var reactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>()); var reactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet<CustomReaction>());
//var reactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>());
reactions.Add(cr); reactions.Add(cr);
} }
@ -127,7 +129,7 @@ namespace NadekoBot.Modules.CustomReactions
[Priority(0)] [Priority(0)]
public async Task ListCustReact(IUserMessage imsg, int page = 1) 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) if (page < 1 || page > 1000)
return; return;
@ -135,7 +137,8 @@ namespace NadekoBot.Modules.CustomReactions
if (channel == null) if (channel == null)
customReactions = GlobalReactions; customReactions = GlobalReactions;
else else
customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>()); customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet<CustomReaction>());
//customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>());
if (customReactions == null || !customReactions.Any()) if (customReactions == null || !customReactions.Any())
await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false);
@ -158,13 +161,14 @@ namespace NadekoBot.Modules.CustomReactions
[Priority(1)] [Priority(1)]
public async Task ListCustReact(IUserMessage imsg, All x) public async Task ListCustReact(IUserMessage imsg, All x)
{ {
var channel = Context.Channel as ITextChannel; //var channel = Context.Channel as ITextChannel;
ConcurrentHashSet<CustomReaction> customReactions; ConcurrentHashSet<CustomReaction> customReactions;
if (channel == null) if (channel == null)
customReactions = GlobalReactions; customReactions = GlobalReactions;
else else
customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>()); customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet<CustomReaction>());
//customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>());
if (customReactions == null || !customReactions.Any()) if (customReactions == null || !customReactions.Any())
await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false);
@ -186,14 +190,15 @@ namespace NadekoBot.Modules.CustomReactions
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
public async Task ListCustReactG(IUserMessage imsg, int page = 1) 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) if (page < 1 || page > 10000)
return; return;
ConcurrentHashSet<CustomReaction> customReactions; ConcurrentHashSet<CustomReaction> customReactions;
if (channel == null) if (channel == null)
customReactions = GlobalReactions; customReactions = GlobalReactions;
else else
customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>()); customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet<CustomReaction>());
//customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>());
if (customReactions == null || !customReactions.Any()) if (customReactions == null || !customReactions.Any())
await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false); await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false);
@ -211,13 +216,14 @@ namespace NadekoBot.Modules.CustomReactions
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
public async Task ShowCustReact(IUserMessage imsg, int id) public async Task ShowCustReact(IUserMessage imsg, int id)
{ {
var channel = Context.Channel as ITextChannel; //var channel = Context.Channel as ITextChannel;
ConcurrentHashSet<CustomReaction> customReactions; ConcurrentHashSet<CustomReaction> customReactions;
if (channel == null) if (channel == null)
customReactions = GlobalReactions; customReactions = GlobalReactions;
else else
customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>()); customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet<CustomReaction>());
//customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>());
var found = customReactions.FirstOrDefault(cr => cr.Id == id); var found = customReactions.FirstOrDefault(cr => cr.Id == id);
@ -236,7 +242,7 @@ namespace NadekoBot.Modules.CustomReactions
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
public async Task DelCustReact(IUserMessage imsg, int id) 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)) 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) else if ((toDelete.GuildId != null && toDelete.GuildId != 0) && channel?.Guild.Id == toDelete.GuildId)
{ {
uow.CustomReactions.Remove(toDelete); uow.CustomReactions.Remove(toDelete);
GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>()).RemoveWhere(cr => cr.Id == toDelete.Id); GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet<CustomReaction>()).RemoveWhere(cr => cr.Id == toDelete.Id);
//GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>()).RemoveWhere(cr => cr.Id == toDelete.Id);
success = true; success = true;
} }
if (success) if (success)

View File

@ -24,28 +24,28 @@ namespace NadekoBot.Modules.Gambling
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Race() 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) 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task JoinRace(IUserMessage umsg, int amount = 0) public async Task JoinRace(IUserMessage umsg, int amount = 0)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (amount < 0) if (amount < 0)
amount = 0; amount = 0;
AnimalRace ar; 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; return;
} }
await ar.JoinRace(Context.User as IGuildUser, amount); await ar.JoinRace(Context.User as IGuildUser, amount);

View File

@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Gambling
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Roll() public async Task Roll()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (channel == null) if (channel == null)
return; return;
var rng = new NadekoRandom(); var rng = new NadekoRandom();
@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Gambling
catch { return new MemoryStream(); } 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 //todo merge into internallDndRoll and internalRoll
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -52,7 +52,7 @@ namespace NadekoBot.Modules.Gambling
[Priority(1)] [Priority(1)]
public async Task Roll(IUserMessage umsg, string arg) public async Task Roll(IUserMessage umsg, string arg)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (channel == null) if (channel == null)
return; return;
@ -78,7 +78,7 @@ namespace NadekoBot.Modules.Gambling
arr[i] = rng.Next(1, n2 + 1) + add - sub; arr[i] = rng.Next(1, n2 + 1) + add - sub;
} }
var elemCnt = 0; 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)] [Priority(0)]
public async Task Roll(IUserMessage umsg, int num) public async Task Roll(IUserMessage umsg, int num)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (channel == null) if (channel == null)
return; return;
@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Gambling
if (num < 1 || num > 30) 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; return;
} }
@ -134,14 +134,14 @@ namespace NadekoBot.Modules.Gambling
var ms = new MemoryStream(); var ms = new MemoryStream();
bitmap.SaveAsPng(ms); bitmap.SaveAsPng(ms);
ms.Position = 0; 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Rolluo(IUserMessage umsg, string arg) public async Task Rolluo(IUserMessage umsg, string arg)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (channel == null) if (channel == null)
return; return;
@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Gambling
arr[i] = rng.Next(1, n2 + 1) + add - sub; arr[i] = rng.Next(1, n2 + 1) + add - sub;
} }
var elemCnt = 0; 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)] [RequireContext(ContextType.Guild)]
public async Task Rolluo(IUserMessage umsg, int num) public async Task Rolluo(IUserMessage umsg, int num)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (channel == null) if (channel == null)
return; return;
@ -184,7 +184,7 @@ namespace NadekoBot.Modules.Gambling
if (num < 1 || num > 30) 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; return;
} }
@ -222,14 +222,14 @@ namespace NadekoBot.Modules.Gambling
var ms = new MemoryStream(); var ms = new MemoryStream();
bitmap.SaveAsPng(ms); bitmap.SaveAsPng(ms);
ms.Position = 0; 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task NRoll(IUserMessage umsg, [Remainder] string range) public async Task NRoll(IUserMessage umsg, [Remainder] string range)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
try try
{ {
@ -249,11 +249,11 @@ namespace NadekoBot.Modules.Gambling
rolled = new NadekoRandom().Next(0, int.Parse(range) + 1); 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) catch (Exception ex)
{ {
await channel.SendErrorAsync($":anger: {ex.Message}").ConfigureAwait(false); await Context.Channel.SendErrorAsync($":anger: {ex.Message}").ConfigureAwait(false);
} }
} }

View File

@ -33,8 +33,8 @@ namespace NadekoBot.Modules.Gambling
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Draw(int num = 1) public async Task Draw(int num = 1)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
var cards = AllDecks.GetOrAdd(channel.Guild, (s) => new Cards()); var cards = AllDecks.GetOrAdd(Context.Guild, (s) => new Cards());
var images = new List<Image>(); var images = new List<Image>();
var cardObjects = new List<Cards.Card>(); var cardObjects = new List<Cards.Card>();
if (num > 5) num = 5; if (num > 5) num = 5;
@ -42,7 +42,7 @@ namespace NadekoBot.Modules.Gambling
{ {
if (cards.CardPool.Count == 0 && i != 0) 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; break;
} }
var currentCard = cards.DrawACard(); var currentCard = cards.DrawACard();
@ -58,16 +58,16 @@ namespace NadekoBot.Modules.Gambling
if (cardObjects.Count == 5) if (cardObjects.Count == 5)
toSend += $" drew `{Cards.GetHandValue(cardObjects)}`"; 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ShuffleDeck() 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) => new Cards(),
(g, c) => (g, c) =>
{ {
@ -75,7 +75,7 @@ namespace NadekoBot.Modules.Gambling
return c; return c;
}); });
await channel.SendConfirmAsync("Deck reshuffled.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync("Deck reshuffled.").ConfigureAwait(false);
} }
} }
} }

View File

@ -23,18 +23,18 @@ namespace NadekoBot.Modules.Gambling
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Flip(IUserMessage imsg, int count = 1) public async Task Flip(IUserMessage imsg, int count = 1)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (count == 1) if (count == 1)
{ {
if (rng.Next(0, 2) == 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 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; return;
} }
if (count > 10 || count < 1) 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; return;
} }
var imgs = new Image[count]; var imgs = new Image[count];
@ -44,14 +44,14 @@ namespace NadekoBot.Modules.Gambling
new Image(File.OpenRead(headsPath)) : new Image(File.OpenRead(headsPath)) :
new Image(File.OpenRead(tailsPath)); 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Betflip(IUserMessage umsg, int amount, string guess) 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 guildUser = (IGuildUser)Context.User;
var guessStr = guess.Trim().ToUpperInvariant(); var guessStr = guess.Trim().ToUpperInvariant();
if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS") if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
@ -59,7 +59,7 @@ namespace NadekoBot.Modules.Gambling
if (amount < 3) 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); .ConfigureAwait(false);
return; return;
} }
@ -72,7 +72,7 @@ namespace NadekoBot.Modules.Gambling
if (userFlowers < amount) 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; return;
} }
@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Gambling
str = $"{Context.User.Mention}`Better luck next time.`"; str = $"{Context.User.Mention}`Better luck next time.`";
} }
await channel.SendFileAsync(imgPathToSend, str).ConfigureAwait(false); await Context.Channel.SendFileAsync(imgPathToSend, str).ConfigureAwait(false);
} }
} }
} }

View File

@ -44,51 +44,52 @@ namespace NadekoBot.Modules.Gambling
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Raffle(IUserMessage umsg, [Remainder] IRole role = null) 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 members = role.Members().Where(u => u.Status != UserStatus.Offline && u.Status != UserStatus.Unknown);
var membersArray = members as IUser[] ?? members.ToArray(); var membersArray = members as IUser[] ?? members.ToArray();
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)]; 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] [NadekoCommand, Usage, Description, Aliases]
[Priority(0)] [Priority(0)]
public async Task Cash(IUserMessage umsg, [Remainder] IUser user = null) public async Task Cash(IUserMessage umsg, [Remainder] IUser user = null)
{ {
var channel = Context.Channel; //var channel = Context.Channel;
user = user ?? Context.User; 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] [NadekoCommand, Usage, Description, Aliases]
[Priority(1)] [Priority(1)]
public async Task Cash(IUserMessage umsg, ulong userId) 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Give(IUserMessage umsg, long amount, [Remainder] IGuildUser receiver) 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) if (amount <= 0 || Context.User.Id == receiver.Id)
return; return;
var success = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)Context.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, true).ConfigureAwait(false); var success = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)Context.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, true).ConfigureAwait(false);
if (!success) 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; return;
} }
await CurrencyHandler.AddCurrencyAsync(receiver, $"Gift from {Context.User.Username} ({Context.User.Id}).", amount, true).ConfigureAwait(false); 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] [NadekoCommand, Usage, Description, Aliases]
@ -104,14 +105,14 @@ namespace NadekoBot.Modules.Gambling
[Priority(1)] [Priority(1)]
public async Task Award(IUserMessage umsg, int amount, ulong usrId) public async Task Award(IUserMessage umsg, int amount, ulong usrId)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (amount <= 0) if (amount <= 0)
return; return;
await CurrencyHandler.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false); 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] [NadekoCommand, Usage, Description, Aliases]
@ -121,7 +122,8 @@ namespace NadekoBot.Modules.Gambling
public async Task Award(IUserMessage umsg, int amount, [Remainder] IRole role) public async Task Award(IUserMessage umsg, int amount, [Remainder] IRole role)
{ {
var channel = (ITextChannel)Context.Channel; 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)) .Where(u => u.Roles.Contains(role))
.ToList(); .ToList();
await Task.WhenAll(users.Select(u => CurrencyHandler.AddCurrencyAsync(u.Id, await Task.WhenAll(users.Select(u => CurrencyHandler.AddCurrencyAsync(u.Id,
@ -129,7 +131,8 @@ namespace NadekoBot.Modules.Gambling
amount))) amount)))
.ConfigureAwait(false); .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); .ConfigureAwait(false);
} }
@ -139,14 +142,14 @@ namespace NadekoBot.Modules.Gambling
[OwnerOnly] [OwnerOnly]
public async Task Take(IUserMessage umsg, long amount, [Remainder] IGuildUser user) public async Task Take(IUserMessage umsg, long amount, [Remainder] IGuildUser user)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (amount <= 0) if (amount <= 0)
return; return;
if(await CurrencyHandler.RemoveCurrencyAsync(user, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount, true).ConfigureAwait(false)) 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 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] [OwnerOnly]
public async Task Take(IUserMessage umsg, long amount, [Remainder] ulong usrId) public async Task Take(IUserMessage umsg, long amount, [Remainder] ulong usrId)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (amount <= 0) if (amount <= 0)
return; return;
if(await CurrencyHandler.RemoveCurrencyAsync(usrId, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false)) 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 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task BetRoll(IUserMessage umsg, long amount) public async Task BetRoll(IUserMessage umsg, long amount)
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (amount < 1) if (amount < 1)
return; return;
@ -184,7 +187,7 @@ namespace NadekoBot.Modules.Gambling
if (userFlowers < amount) 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; return;
} }
@ -212,14 +215,14 @@ namespace NadekoBot.Modules.Gambling
await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 10, false).ConfigureAwait(false); 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Leaderboard() public async Task Leaderboard()
{ {
var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
IEnumerable<Currency> richest = new List<Currency>(); IEnumerable<Currency> richest = new List<Currency>();
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
@ -228,14 +231,14 @@ namespace NadekoBot.Modules.Gambling
} }
if (!richest.Any()) if (!richest.Any())
return; return;
await channel.SendMessageAsync( await Context.Channel.SendMessageAsync(
richest.Aggregate(new StringBuilder( richest.Aggregate(new StringBuilder(
$@"```xl $@"```xl
Id $$$ Id $$$
"), "),
(cur, cs) => cur.AppendLine($@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━┫ (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); ).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━┛```").ConfigureAwait(false);
} }
} }