Added some cute owner functionality

This commit is contained in:
Deukhoofd 2018-05-18 13:36:20 +02:00
parent f225d226a2
commit 32fa37b633
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,64 @@
using System;
using System.Threading.Tasks;
using DeukBot4.MessageHandlers.CommandHandler.RequestStructure;
using DeukBot4.MessageHandlers.Permissions;
using DeukBot4.Utilities;
using Discord;
namespace DeukBot4.MessageHandlers.CommandHandler
{
public class OwnerCommands : CommandContainerBase
{
public override string Name => "Owner";
[Command("send", PermissionLevel.BotCreator)]
[CommandParameters(ParameterMatcher.ParameterType.Number, ParameterMatcher.ParameterType.Remainder)]
public async Task SendMessage(CommandRequest request)
{
if (request.Parameters.Length < 2)
return;
var channelId = request.Parameters[0].AsUlong();
if (!channelId.HasValue)
{
await request.SendMessageAsync($"Invalid channel ID: {request.Parameters[0].AsString()}");
return;
}
if (!(Program.Client.GetChannel(channelId.Value) is IMessageChannel channelFind))
{
await request.SendMessageAsync($"Can't find channel: {channelId.Value}");
return;
}
await channelFind.SendMessageAsync(request.Parameters[1].AsString());
}
[Command("dm", PermissionLevel.BotCreator)]
[CommandParameters(ParameterMatcher.ParameterType.Number, ParameterMatcher.ParameterType.Remainder)]
public async Task DMMessage(CommandRequest request)
{
if (request.Parameters.Length < 2)
return;
var channelId = request.Parameters[0].AsUlong();
if (!channelId.HasValue)
{
await request.SendMessageAsync($"Invalid channel ID: {request.Parameters[0].AsString()}");
return;
}
var user = Program.Client.GetUser(channelId.Value);
if (user == null)
{
await request.SendMessageAsync($"Can't find user: {channelId.Value}");
return;
}
var channel = await user.GetOrCreateDMChannelAsync();
if (channel == null)
{
await request.SendMessageAsync($"Can't create channel");
return;
}
await channel.SendMessageAsync(request.Parameters[1].AsString());
}
}
}