2019-10-05 05:41:00 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2019-06-21 11:49:58 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Discord;
|
2019-10-05 05:41:00 +00:00
|
|
|
|
|
|
|
using PluralKit.Bot.CommandSystem;
|
2019-06-21 11:49:58 +00:00
|
|
|
|
|
|
|
namespace PluralKit.Bot.Commands
|
|
|
|
{
|
2019-10-05 05:41:00 +00:00
|
|
|
public class ModCommands
|
2019-06-21 11:49:58 +00:00
|
|
|
{
|
2019-10-05 05:41:00 +00:00
|
|
|
private LogChannelService _logChannels;
|
2019-10-26 17:45:30 +00:00
|
|
|
private IDataStore _data;
|
2019-10-05 05:41:00 +00:00
|
|
|
|
|
|
|
private EmbedService _embeds;
|
|
|
|
|
2019-10-26 17:45:30 +00:00
|
|
|
public ModCommands(LogChannelService logChannels, IDataStore data, EmbedService embeds)
|
2019-06-21 11:49:58 +00:00
|
|
|
{
|
2019-10-05 05:41:00 +00:00
|
|
|
_logChannels = logChannels;
|
2019-10-26 17:45:30 +00:00
|
|
|
_data = data;
|
2019-10-05 05:41:00 +00:00
|
|
|
_embeds = embeds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task SetLogChannel(Context ctx)
|
|
|
|
{
|
2019-10-27 22:01:20 +00:00
|
|
|
ctx.CheckGuildContext().CheckAuthorPermission(GuildPermission.ManageGuild, "Manage Server");
|
2019-10-05 05:41:00 +00:00
|
|
|
|
|
|
|
ITextChannel channel = null;
|
|
|
|
if (ctx.HasNext())
|
|
|
|
channel = ctx.MatchChannel() ?? throw new PKSyntaxError("You must pass a #channel to set.");
|
2019-06-21 11:49:58 +00:00
|
|
|
|
2019-10-27 22:01:20 +00:00
|
|
|
var cfg = await _data.GetGuildConfig(ctx.Guild.Id);
|
|
|
|
cfg.LogChannel = channel?.Id;
|
|
|
|
await _data.SaveGuildConfig(cfg);
|
|
|
|
|
2019-06-21 11:49:58 +00:00
|
|
|
if (channel != null)
|
2019-10-18 11:14:36 +00:00
|
|
|
await ctx.Reply($"{Emojis.Success} Proxy logging channel set to #{channel.Name.SanitizeMentions()}.");
|
2019-06-21 11:49:58 +00:00
|
|
|
else
|
2019-10-05 05:41:00 +00:00
|
|
|
await ctx.Reply($"{Emojis.Success} Proxy logging channel cleared.");
|
2019-06-21 11:49:58 +00:00
|
|
|
}
|
2019-10-05 05:41:00 +00:00
|
|
|
|
|
|
|
public async Task GetMessage(Context ctx)
|
2019-06-21 11:49:58 +00:00
|
|
|
{
|
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.");
|
|
|
|
|
2019-10-26 17:45:30 +00:00
|
|
|
var message = await _data.GetMessage(messageId);
|
2019-06-21 11:49:58 +00:00
|
|
|
if (message == null) throw Errors.MessageNotFound(messageId);
|
|
|
|
|
2019-10-05 05:41:00 +00:00
|
|
|
await ctx.Reply(embed: await _embeds.CreateMessageInfoEmbed(message));
|
2019-06-21 11:49:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|