A few more commands can be ran in DMs now - Rotate playing commands, .die, .setstream/game/avatar, .announce, .send

This commit is contained in:
Kwoth 2016-12-10 21:36:36 +01:00
parent 813b0e0ecc
commit d88aa3d4c1
2 changed files with 17 additions and 54 deletions

View File

@ -677,38 +677,30 @@ namespace NadekoBot.Modules.Administration
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task Die(IUserMessage umsg) public async Task Die(IUserMessage umsg)
{ {
var channel = (ITextChannel)umsg.Channel; try { await umsg.Channel.SendMessageAsync(" **Shutting down.**").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
try { await channel.SendMessageAsync(" **Shutting down.**").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
await Task.Delay(2000).ConfigureAwait(false); await Task.Delay(2000).ConfigureAwait(false);
Environment.Exit(0); Environment.Exit(0);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task Setname(IUserMessage umsg, [Remainder] string newName) public async Task SetName(IUserMessage umsg, [Remainder] string newName)
{ {
var channel = (ITextChannel)umsg.Channel;
if (string.IsNullOrWhiteSpace(newName)) if (string.IsNullOrWhiteSpace(newName))
return; return;
await (await NadekoBot.Client.GetCurrentUserAsync()).ModifyAsync(u => u.Username = newName).ConfigureAwait(false); await (await NadekoBot.Client.GetCurrentUserAsync()).ModifyAsync(u => u.Username = newName).ConfigureAwait(false);
await channel.SendMessageAsync($" Successfully changed name to **{newName}**").ConfigureAwait(false); await umsg.Channel.SendMessageAsync($" Successfully changed name to **{newName}**").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task SetAvatar(IUserMessage umsg, [Remainder] string img = null) public async Task SetAvatar(IUserMessage umsg, [Remainder] string img = null)
{ {
var channel = (ITextChannel)umsg.Channel;
if (string.IsNullOrWhiteSpace(img)) if (string.IsNullOrWhiteSpace(img))
return; return;
@ -724,44 +716,35 @@ namespace NadekoBot.Modules.Administration
} }
} }
await channel.SendMessageAsync("🆒 **New avatar set.**").ConfigureAwait(false); await umsg.Channel.SendMessageAsync("🆒 **New avatar set.**").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task SetGame(IUserMessage umsg, [Remainder] string game = null) public async Task SetGame(IUserMessage umsg, [Remainder] string game = null)
{ {
var channel = (ITextChannel)umsg.Channel;
game = game ?? ""; game = game ?? "";
await NadekoBot.Client.SetGame(game).ConfigureAwait(false); await NadekoBot.Client.SetGame(game).ConfigureAwait(false);
await channel.SendMessageAsync("👾 **New game set.**").ConfigureAwait(false); await umsg.Channel.SendMessageAsync("👾 **New game set.**").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task SetStream(IUserMessage umsg, string url, [Remainder] string name = null) public async Task SetStream(IUserMessage umsg, string url, [Remainder] string name = null)
{ {
var channel = (ITextChannel)umsg.Channel;
name = name ?? ""; name = name ?? "";
await NadekoBot.Client.SetStream(name, url).ConfigureAwait(false); await NadekoBot.Client.SetStream(name, url).ConfigureAwait(false);
await channel.SendMessageAsync(" **New stream set.**").ConfigureAwait(false); await umsg.Channel.SendMessageAsync(" **New stream set.**").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task Send(IUserMessage umsg, string where, [Remainder] string msg = null) public async Task Send(IUserMessage umsg, string where, [Remainder] string msg = null)
{ {
var channel = (ITextChannel)umsg.Channel;
if (string.IsNullOrWhiteSpace(msg)) if (string.IsNullOrWhiteSpace(msg))
return; return;
@ -796,17 +779,14 @@ namespace NadekoBot.Modules.Administration
} }
else else
{ {
await channel.SendMessageAsync("⚠️ Invalid format.").ConfigureAwait(false); await umsg.Channel.SendMessageAsync("⚠️ Invalid format.").ConfigureAwait(false);
} }
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task Announce(IUserMessage umsg, [Remainder] string message) public async Task Announce(IUserMessage umsg, [Remainder] string message)
{ {
var channel = (ITextChannel)umsg.Channel;
var channels = await Task.WhenAll(NadekoBot.Client.GetGuilds().Select(g => var channels = await Task.WhenAll(NadekoBot.Client.GetGuilds().Select(g =>
g.GetDefaultChannelAsync() g.GetDefaultChannelAsync()
)).ConfigureAwait(false); )).ConfigureAwait(false);
@ -814,7 +794,7 @@ namespace NadekoBot.Modules.Administration
await Task.WhenAll(channels.Select(c => c.SendMessageAsync($"🆕 **Message from {umsg.Author} `(Bot Owner)`:** " + message))) await Task.WhenAll(channels.Select(c => c.SendMessageAsync($"🆕 **Message from {umsg.Author} `(Bot Owner)`:** " + message)))
.ConfigureAwait(false); .ConfigureAwait(false);
await channel.SendMessageAsync("🆗").ConfigureAwait(false); await umsg.Channel.SendMessageAsync("🆗").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -877,10 +857,8 @@ namespace NadekoBot.Modules.Administration
IGuild nadekoSupportServer; IGuild nadekoSupportServer;
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Donators(IUserMessage umsg) public async Task Donators(IUserMessage umsg)
{ {
var channel = (ITextChannel)umsg.Channel;
IEnumerable<Donator> donatorsOrdered; IEnumerable<Donator> donatorsOrdered;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
@ -889,7 +867,7 @@ namespace NadekoBot.Modules.Administration
} }
string str = $"**Thanks to the people listed below for making this project happen!**\n"; string str = $"**Thanks to the people listed below for making this project happen!**\n";
await channel.SendMessageAsync(str + string.Join("⭐", donatorsOrdered.Select(d => d.Name))).ConfigureAwait(false); await umsg.Channel.SendMessageAsync(str + string.Join("⭐", donatorsOrdered.Select(d => d.Name))).ConfigureAwait(false);
nadekoSupportServer = nadekoSupportServer ?? NadekoBot.Client.GetGuild(117523346618318850); nadekoSupportServer = nadekoSupportServer ?? NadekoBot.Client.GetGuild(117523346618318850);
@ -901,17 +879,14 @@ namespace NadekoBot.Modules.Administration
return; return;
var usrs = nadekoSupportServer.GetUsers().Where(u => u.Roles.Contains(patreonRole)); var usrs = nadekoSupportServer.GetUsers().Where(u => u.Roles.Contains(patreonRole));
await channel.SendMessageAsync("\n`Patreon supporters:`\n" + string.Join("⭐", usrs.Select(d => d.Username))).ConfigureAwait(false); await umsg.Channel.SendMessageAsync("\n`Patreon supporters:`\n" + string.Join("⭐", usrs.Select(d => d.Username))).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task Donadd(IUserMessage umsg, IUser donator, int amount) public async Task Donadd(IUserMessage umsg, IUser donator, int amount)
{ {
var channel = (ITextChannel)umsg.Channel;
Donator don; Donator don;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -919,7 +894,7 @@ namespace NadekoBot.Modules.Administration
await uow.CompleteAsync(); await uow.CompleteAsync();
} }
await channel.SendMessageAsync($"Successfuly added a new donator. Total donated amount from this user: {don.Amount} 👑").ConfigureAwait(false); await umsg.Channel.SendMessageAsync($"Successfuly added a new donator. Total donated amount from this user: {don.Amount} 👑").ConfigureAwait(false);
} }
} }
} }

View File

@ -87,12 +87,9 @@ namespace NadekoBot.Modules.Administration
}; };
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task RotatePlaying(IUserMessage umsg) public async Task RotatePlaying(IUserMessage umsg)
{ {
var channel = (ITextChannel)umsg.Channel;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
var config = uow.BotConfig.GetOrCreate(); var config = uow.BotConfig.GetOrCreate();
@ -101,18 +98,15 @@ namespace NadekoBot.Modules.Administration
await uow.CompleteAsync(); await uow.CompleteAsync();
} }
if (RotatingStatuses) if (RotatingStatuses)
await channel.SendMessageAsync("🆗 **Rotating playing status enabled.**"); await umsg.Channel.SendMessageAsync("🆗 **Rotating playing status enabled.**").ConfigureAwait(false);
else else
await channel.SendMessageAsync(" **Rotating playing status disabled.**"); await umsg.Channel.SendMessageAsync(" **Rotating playing status disabled.**").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task AddPlaying(IUserMessage umsg, [Remainder] string status) public async Task AddPlaying(IUserMessage umsg, [Remainder] string status)
{ {
var channel = (ITextChannel)umsg.Channel;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
var config = uow.BotConfig.GetOrCreate(); var config = uow.BotConfig.GetOrCreate();
@ -122,33 +116,27 @@ namespace NadekoBot.Modules.Administration
await uow.CompleteAsync(); await uow.CompleteAsync();
} }
await channel.SendMessageAsync("✅ **Added.**").ConfigureAwait(false); await umsg.Channel.SendMessageAsync("✅ **Added.**").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task ListPlaying(IUserMessage umsg) public async Task ListPlaying(IUserMessage umsg)
{ {
var channel = (ITextChannel)umsg.Channel;
if (!RotatingStatusMessages.Any()) if (!RotatingStatusMessages.Any())
await channel.SendMessageAsync("❎ **No rotating playing statuses set.**"); await umsg.Channel.SendMessageAsync("❎ **No rotating playing statuses set.**");
else else
{ {
var i = 1; var i = 1;
await channel.SendMessageAsync($" {umsg.Author.Mention} `Here is a list of rotating statuses:`\n\n\t" + string.Join("\n\t", RotatingStatusMessages.Select(rs => $"`{i++}.` {rs.Status}"))); await umsg.Channel.SendMessageAsync($" {umsg.Author.Mention} `Here is a list of rotating statuses:`\n\n\t" + string.Join("\n\t", RotatingStatusMessages.Select(rs => $"`{i++}.` {rs.Status}")));
} }
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task RemovePlaying(IUserMessage umsg, int index) public async Task RemovePlaying(IUserMessage umsg, int index)
{ {
var channel = (ITextChannel)umsg.Channel;
index -= 1; index -= 1;
string msg = ""; string msg = "";
@ -163,7 +151,7 @@ namespace NadekoBot.Modules.Administration
RotatingStatusMessages.RemoveAt(index); RotatingStatusMessages.RemoveAt(index);
await uow.CompleteAsync(); await uow.CompleteAsync();
} }
await channel.SendMessageAsync($"🗑 **Removed the the playing message:** {msg}").ConfigureAwait(false); await umsg.Channel.SendMessageAsync($"🗑 **Removed the the playing message:** {msg}").ConfigureAwait(false);
} }
} }
} }