PluralKit/PluralKit.Bot/Commands/ModCommands.cs

56 lines
2.0 KiB
C#
Raw Normal View History

2019-10-05 05:41:00 +00:00
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Discord;
2019-10-05 05:41:00 +00:00
using PluralKit.Bot.CommandSystem;
namespace PluralKit.Bot.Commands
{
2019-10-05 05:41:00 +00:00
public class ModCommands
{
2019-10-05 05:41:00 +00:00
private LogChannelService _logChannels;
private IDataStore _data;
2019-10-05 05:41:00 +00:00
private EmbedService _embeds;
public ModCommands(LogChannelService logChannels, IDataStore data, EmbedService embeds)
{
2019-10-05 05:41:00 +00:00
_logChannels = logChannels;
_data = data;
2019-10-05 05:41:00 +00:00
_embeds = embeds;
}
public async Task SetLogChannel(Context ctx)
{
ctx.CheckAuthorPermission(GuildPermission.ManageGuild, "Manage Server").CheckGuildContext();
ITextChannel channel = null;
if (ctx.HasNext())
channel = ctx.MatchChannel() ?? throw new PKSyntaxError("You must pass a #channel to set.");
await _logChannels.SetLogChannel(ctx.Guild, channel);
if (channel != null)
2019-10-18 11:14:36 +00:00
await ctx.Reply($"{Emojis.Success} Proxy logging channel set to #{channel.Name.SanitizeMentions()}.");
else
2019-10-05 05:41:00 +00:00
await ctx.Reply($"{Emojis.Success} Proxy logging channel cleared.");
}
2019-10-05 05:41:00 +00:00
public async Task GetMessage(Context ctx)
{
2019-10-05 05:41:00 +00:00
var word = ctx.PopArgument() ?? throw new PKSyntaxError("You must pass a message ID or link.");
ulong messageId;
if (ulong.TryParse(word, out var id))
messageId = id;
else if (Regex.Match(word, "https://discordapp.com/channels/\\d+/(\\d+)") is Match match && match.Success)
messageId = ulong.Parse(match.Groups[1].Value);
else throw new PKSyntaxError($"Could not parse `{word}` as a message ID or link.");
var message = await _data.GetMessage(messageId);
if (message == null) throw Errors.MessageNotFound(messageId);
2019-10-05 05:41:00 +00:00
await ctx.Reply(embed: await _embeds.CreateMessageInfoEmbed(message));
}
}
}