2021-08-27 15:03:47 +00:00
|
|
|
#nullable enable
|
2021-10-29 20:42:10 +00:00
|
|
|
using System.Text;
|
|
|
|
using System.Text.RegularExpressions;
|
2021-05-03 10:33:30 +00:00
|
|
|
|
2022-06-20 00:28:55 +00:00
|
|
|
using Autofac;
|
|
|
|
|
2021-08-25 18:36:13 +00:00
|
|
|
using Myriad.Builders;
|
2021-07-28 06:23:01 +00:00
|
|
|
using Myriad.Cache;
|
|
|
|
using Myriad.Extensions;
|
2021-05-03 10:33:30 +00:00
|
|
|
using Myriad.Rest;
|
2021-11-27 02:10:56 +00:00
|
|
|
using Myriad.Rest.Exceptions;
|
2021-10-29 20:42:10 +00:00
|
|
|
using Myriad.Rest.Types;
|
|
|
|
using Myriad.Rest.Types.Requests;
|
2021-05-03 10:33:30 +00:00
|
|
|
using Myriad.Types;
|
|
|
|
|
|
|
|
using NodaTime;
|
|
|
|
|
2022-05-08 21:10:07 +00:00
|
|
|
using App.Metrics;
|
|
|
|
|
2021-05-03 10:33:30 +00:00
|
|
|
using PluralKit.Core;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Bot;
|
|
|
|
|
|
|
|
public class ProxiedMessage
|
2021-05-03 10:33:30 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
private static readonly Duration EditTimeout = Duration.FromMinutes(10);
|
2022-05-08 21:10:07 +00:00
|
|
|
private static readonly Duration ReproxyTimeout = Duration.FromMinutes(1);
|
2022-03-30 08:36:22 +00:00
|
|
|
|
2022-03-10 01:06:53 +00:00
|
|
|
// private readonly IDiscordCache _cache;
|
2022-05-08 21:10:07 +00:00
|
|
|
private readonly ModelRepository _repo;
|
|
|
|
private readonly IMetrics _metrics;
|
2021-11-27 02:10:56 +00:00
|
|
|
|
|
|
|
private readonly EmbedService _embeds;
|
|
|
|
private readonly LogChannelService _logChannel;
|
|
|
|
private readonly DiscordApiClient _rest;
|
|
|
|
private readonly WebhookExecutorService _webhookExecutor;
|
2022-05-08 21:10:07 +00:00
|
|
|
private readonly ProxyService _proxy;
|
2022-08-27 06:57:57 +00:00
|
|
|
private readonly LastMessageCacheService _lastMessageCache;
|
2021-11-27 02:10:56 +00:00
|
|
|
|
2022-05-08 21:10:07 +00:00
|
|
|
public ProxiedMessage(EmbedService embeds,
|
|
|
|
DiscordApiClient rest, IMetrics metrics, ModelRepository repo, ProxyService proxy,
|
2022-08-27 06:57:57 +00:00
|
|
|
WebhookExecutorService webhookExecutor, LogChannelService logChannel, IDiscordCache cache,
|
|
|
|
LastMessageCacheService lastMessageCache)
|
2021-05-03 10:33:30 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
_embeds = embeds;
|
|
|
|
_rest = rest;
|
|
|
|
_webhookExecutor = webhookExecutor;
|
2022-05-08 21:10:07 +00:00
|
|
|
_repo = repo;
|
2021-11-27 02:10:56 +00:00
|
|
|
_logChannel = logChannel;
|
2022-03-10 01:06:53 +00:00
|
|
|
// _cache = cache;
|
2022-05-08 21:10:07 +00:00
|
|
|
_metrics = metrics;
|
2022-06-10 22:49:36 +00:00
|
|
|
_proxy = proxy;
|
2022-08-27 06:57:57 +00:00
|
|
|
_lastMessageCache = lastMessageCache;
|
2022-05-08 21:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task ReproxyMessage(Context ctx)
|
|
|
|
{
|
2022-11-23 09:17:19 +00:00
|
|
|
var (msg, systemId) = await GetMessageToEdit(ctx, ReproxyTimeout, true);
|
2022-05-08 21:10:07 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
if (ctx.System.Id != systemId)
|
2022-05-08 21:10:07 +00:00
|
|
|
throw new PKError("Can't reproxy a message sent by a different system.");
|
|
|
|
|
|
|
|
// Get target member ID
|
|
|
|
var target = await ctx.MatchMember(restrictToSystem: ctx.System.Id);
|
|
|
|
if (target == null)
|
|
|
|
throw new PKError("Could not find a member to reproxy the message with.");
|
|
|
|
|
|
|
|
// Fetch members and get the ProxyMember for `target`
|
2022-06-10 22:49:36 +00:00
|
|
|
List<ProxyMember> members;
|
2022-05-08 21:10:07 +00:00
|
|
|
using (_metrics.Measure.Timer.Time(BotMetrics.ProxyMembersQueryTime))
|
2022-11-23 09:17:19 +00:00
|
|
|
members = (await _repo.GetProxyMembers(ctx.Author.Id, msg.Guild!.Value)).ToList();
|
2022-05-08 21:10:07 +00:00
|
|
|
var match = members.Find(x => x.Id == target.Id);
|
|
|
|
if (match == null)
|
|
|
|
throw new PKError("Could not find a member to reproxy the message with.");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2022-11-23 09:17:19 +00:00
|
|
|
await _proxy.ExecuteReproxy(ctx.Message, msg, members, match);
|
2022-05-08 21:10:07 +00:00
|
|
|
|
|
|
|
if (ctx.Guild == null)
|
|
|
|
await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new Emoji { Name = Emojis.Success });
|
|
|
|
if ((await ctx.BotPermissions).HasFlag(PermissionSet.ManageMessages))
|
|
|
|
await _rest.DeleteMessage(ctx.Channel.Id, ctx.Message.Id);
|
|
|
|
}
|
|
|
|
catch (NotFoundException)
|
|
|
|
{
|
|
|
|
throw new PKError("Could not reproxy message.");
|
|
|
|
}
|
2021-11-27 02:10:56 +00:00
|
|
|
}
|
2021-05-03 10:33:30 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public async Task EditMessage(Context ctx)
|
|
|
|
{
|
2022-11-23 09:17:19 +00:00
|
|
|
var (msg, systemId) = await GetMessageToEdit(ctx, EditTimeout, false);
|
2022-01-07 19:06:37 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
if (ctx.System.Id != systemId)
|
2021-11-27 02:10:56 +00:00
|
|
|
throw new PKError("Can't edit a message sent by a different system.");
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
var originalMsg = await _rest.GetMessageOrNull(msg.Channel, msg.Mid);
|
2022-04-07 07:43:46 +00:00
|
|
|
if (originalMsg == null)
|
|
|
|
throw new PKError("Could not edit message.");
|
|
|
|
|
|
|
|
// Check if we should append or prepend
|
2022-08-27 11:25:11 +00:00
|
|
|
var mutateSpace = ctx.MatchFlag("nospace", "ns") ? "" : " ";
|
|
|
|
var append = ctx.MatchFlag("append", "a");
|
|
|
|
var prepend = ctx.MatchFlag("prepend", "p");
|
2022-04-07 07:47:38 +00:00
|
|
|
|
2022-04-07 07:43:46 +00:00
|
|
|
// Grab the original message content and new message content
|
|
|
|
var originalContent = originalMsg.Content;
|
2022-12-31 06:24:19 +00:00
|
|
|
var newContent = ctx.RemainderOrNull()?.NormalizeLineEndSpacing();
|
|
|
|
|
|
|
|
// Should we clear embeds?
|
|
|
|
var clearEmbeds = ctx.MatchFlag("clear-embed", "ce");
|
|
|
|
if (clearEmbeds && newContent == null)
|
|
|
|
newContent = originalMsg.Content!;
|
|
|
|
|
|
|
|
if (newContent == null)
|
|
|
|
throw new PKSyntaxError("You need to include the message to edit in.");
|
2022-04-07 07:47:38 +00:00
|
|
|
|
2022-04-07 07:43:46 +00:00
|
|
|
// Append or prepend the new content to the original message content if needed.
|
|
|
|
// If no flag is supplied, the new contents will completly overwrite the old contents
|
|
|
|
// If both flags are specified. the message will be prepended AND appended
|
2022-08-27 11:25:11 +00:00
|
|
|
if (append && prepend) newContent = $"{newContent}{mutateSpace}{originalContent}{mutateSpace}{newContent}";
|
|
|
|
else if (append) newContent = $"{originalContent}{mutateSpace}{newContent}";
|
|
|
|
else if (prepend) newContent = $"{newContent}{mutateSpace}{originalContent}";
|
2021-05-03 10:33:30 +00:00
|
|
|
|
2022-01-21 23:23:58 +00:00
|
|
|
if (newContent.Length > 2000)
|
|
|
|
throw new PKError("PluralKit cannot proxy messages over 2000 characters in length.");
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
var editedMsg =
|
2022-12-31 06:24:19 +00:00
|
|
|
await _webhookExecutor.EditWebhookMessage(msg.Channel, msg.Mid, newContent, clearEmbeds);
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (ctx.Guild == null)
|
|
|
|
await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new Emoji { Name = Emojis.Success });
|
2021-07-18 00:39:12 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if ((await ctx.BotPermissions).HasFlag(PermissionSet.ManageMessages))
|
|
|
|
await _rest.DeleteMessage(ctx.Channel.Id, ctx.Message.Id);
|
2021-05-07 16:35:09 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
await _logChannel.LogMessage(msg, ctx.Message, editedMsg, originalMsg!.Content!);
|
2021-05-03 10:33:30 +00:00
|
|
|
}
|
2021-11-27 02:10:56 +00:00
|
|
|
catch (NotFoundException)
|
2021-05-03 10:33:30 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
throw new PKError("Could not edit message.");
|
|
|
|
}
|
|
|
|
}
|
2021-07-27 15:39:37 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
private async Task<(PKMessage, SystemId)> GetMessageToEdit(Context ctx, Duration timeout, bool isReproxy)
|
2021-11-27 02:10:56 +00:00
|
|
|
{
|
2022-05-08 21:10:07 +00:00
|
|
|
var editType = isReproxy ? "reproxy" : "edit";
|
|
|
|
var editTypeAction = isReproxy ? "reproxied" : "edited";
|
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
PKMessage? msg = null;
|
2021-05-03 10:33:30 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
var (referencedMessage, _) = ctx.MatchMessage(false);
|
|
|
|
if (referencedMessage != null)
|
|
|
|
{
|
2022-06-05 22:59:53 +00:00
|
|
|
await using var conn = await ctx.Database.Obtain();
|
2022-11-23 09:17:19 +00:00
|
|
|
msg = await ctx.Repository.GetMessage(referencedMessage.Value);
|
2021-07-27 15:39:37 +00:00
|
|
|
if (msg == null)
|
2021-11-27 02:10:56 +00:00
|
|
|
throw new PKError("This is not a message proxied by PluralKit.");
|
|
|
|
}
|
2021-05-07 21:31:43 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (msg == null)
|
|
|
|
{
|
|
|
|
if (ctx.Guild == null)
|
2022-05-08 21:10:07 +00:00
|
|
|
throw new PKSyntaxError($"You must use a message link to {editType} messages in DMs.");
|
2021-07-27 15:39:37 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
ulong? recent = null;
|
2022-08-27 05:02:50 +00:00
|
|
|
|
|
|
|
if (isReproxy)
|
2022-11-24 06:32:55 +00:00
|
|
|
recent = await ctx.Redis.GetLastMessage(ctx.Author.Id, ctx.Channel.Id);
|
2022-08-27 05:02:50 +00:00
|
|
|
else
|
|
|
|
recent = await FindRecentMessage(ctx, timeout);
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (recent == null)
|
2022-05-08 21:10:07 +00:00
|
|
|
throw new PKSyntaxError($"Could not find a recent message to {editType}.");
|
2021-07-27 15:39:37 +00:00
|
|
|
|
2022-06-05 22:59:53 +00:00
|
|
|
await using var conn = await ctx.Database.Obtain();
|
2022-11-23 09:17:19 +00:00
|
|
|
msg = await ctx.Repository.GetMessage(recent.Value);
|
2021-11-27 02:10:56 +00:00
|
|
|
if (msg == null)
|
2022-05-08 21:10:07 +00:00
|
|
|
throw new PKSyntaxError($"Could not find a recent message to {editType}.");
|
2021-11-27 02:10:56 +00:00
|
|
|
}
|
2021-11-11 04:46:16 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
var member = await ctx.Repository.GetMember(msg.Member!.Value);
|
|
|
|
if (member == null)
|
|
|
|
throw new PKSyntaxError($"Could not find a recent message to {editType}.");
|
|
|
|
|
|
|
|
if (msg.Channel != ctx.Channel.Id)
|
2021-11-27 02:10:56 +00:00
|
|
|
{
|
|
|
|
var error =
|
|
|
|
"The channel where the message was sent does not exist anymore, or you are missing permissions to access it.";
|
2021-11-11 04:46:16 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
var channel = await _rest.GetChannelOrNull(msg.Channel);
|
2021-11-27 02:10:56 +00:00
|
|
|
if (channel == null)
|
|
|
|
throw new PKError(error);
|
|
|
|
|
|
|
|
if (!await ctx.CheckPermissionsInGuildChannel(channel,
|
2021-11-11 04:46:16 +00:00
|
|
|
PermissionSet.ViewChannel | PermissionSet.SendMessages
|
|
|
|
))
|
2021-11-27 02:10:56 +00:00
|
|
|
throw new PKError(error);
|
2021-05-03 10:33:30 +00:00
|
|
|
}
|
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
var lastMessage = _lastMessageCache.GetLastMessage(ctx.Message.ChannelId);
|
|
|
|
|
|
|
|
var isLatestMessage = lastMessage?.Current.Id == ctx.Message.Id
|
|
|
|
? lastMessage?.Previous?.Id == msg.Mid
|
|
|
|
: lastMessage?.Current.Id == msg.Mid;
|
2022-08-27 05:02:50 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
var msgTimestamp = DiscordUtils.SnowflakeToInstant(msg.Mid);
|
2022-08-27 05:02:50 +00:00
|
|
|
if (isReproxy && !isLatestMessage)
|
|
|
|
if (SystemClock.Instance.GetCurrentInstant() - msgTimestamp > timeout)
|
|
|
|
throw new PKError($"The message is too old to be {editTypeAction}.");
|
2022-05-08 21:10:07 +00:00
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
return (msg, member.System);
|
2021-11-27 02:10:56 +00:00
|
|
|
}
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2022-11-24 06:32:55 +00:00
|
|
|
private async Task<ulong?> FindRecentMessage(Context ctx, Duration timeout)
|
2021-11-27 02:10:56 +00:00
|
|
|
{
|
2022-11-24 06:32:55 +00:00
|
|
|
var lastMessage = await ctx.Redis.GetLastMessage(ctx.Author.Id, ctx.Channel.Id);
|
2021-11-27 02:10:56 +00:00
|
|
|
if (lastMessage == null)
|
|
|
|
return null;
|
2021-05-03 10:33:30 +00:00
|
|
|
|
2022-11-24 06:32:55 +00:00
|
|
|
var timestamp = DiscordUtils.SnowflakeToInstant(lastMessage.Value);
|
2022-05-08 21:10:07 +00:00
|
|
|
if (SystemClock.Instance.GetCurrentInstant() - timestamp > timeout)
|
2021-11-27 02:10:56 +00:00
|
|
|
return null;
|
|
|
|
|
|
|
|
return lastMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task GetMessage(Context ctx)
|
|
|
|
{
|
|
|
|
var (messageId, _) = ctx.MatchMessage(true);
|
|
|
|
if (messageId == null)
|
|
|
|
{
|
|
|
|
if (!ctx.HasNext())
|
|
|
|
throw new PKSyntaxError("You must pass a message ID or link.");
|
|
|
|
throw new PKSyntaxError($"Could not parse {ctx.PeekArgument().AsCode()} as a message ID or link.");
|
2021-05-03 10:33:30 +00:00
|
|
|
}
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
var isDelete = ctx.Match("delete") || ctx.MatchFlag("delete");
|
|
|
|
|
2022-11-23 09:17:19 +00:00
|
|
|
var message = await ctx.Repository.GetFullMessage(messageId.Value);
|
2021-11-27 02:10:56 +00:00
|
|
|
if (message == null)
|
2021-08-25 18:36:13 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
if (isDelete)
|
2021-08-25 18:36:13 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
await DeleteCommandMessage(ctx, messageId.Value);
|
|
|
|
return;
|
2021-08-25 18:36:13 +00:00
|
|
|
}
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
throw Errors.MessageNotFound(messageId.Value);
|
|
|
|
}
|
2021-09-27 02:49:43 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
var showContent = true;
|
|
|
|
var noShowContentError = "Message deleted or inaccessible.";
|
2021-08-25 18:36:13 +00:00
|
|
|
|
2022-03-10 01:06:53 +00:00
|
|
|
var channel = await _rest.GetChannelOrNull(message.Message.Channel);
|
2021-11-27 02:10:56 +00:00
|
|
|
if (channel == null)
|
|
|
|
showContent = false;
|
|
|
|
else if (!await ctx.CheckPermissionsInGuildChannel(channel, PermissionSet.ViewChannel))
|
|
|
|
showContent = false;
|
2021-11-11 04:46:16 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (ctx.MatchRaw())
|
|
|
|
{
|
|
|
|
var discordMessage = await _rest.GetMessageOrNull(message.Message.Channel, message.Message.Mid);
|
|
|
|
if (discordMessage == null || !showContent)
|
|
|
|
throw new PKError(noShowContentError);
|
2021-11-11 04:46:16 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
var content = discordMessage.Content;
|
|
|
|
if (content == null || content == "")
|
2021-10-29 20:42:10 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
await ctx.Reply("No message content found in that message.");
|
2021-10-29 20:42:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
await ctx.Reply($"```{content}```");
|
2021-09-22 17:48:34 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (Regex.IsMatch(content, "```.*```", RegexOptions.Singleline))
|
2021-08-25 18:36:13 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
var stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
|
|
|
|
await ctx.Rest.CreateMessage(
|
|
|
|
ctx.Channel.Id,
|
|
|
|
new MessageRequest
|
|
|
|
{
|
|
|
|
Content = $"{Emojis.Warn} Message contains codeblocks, raw source sent as an attachment."
|
|
|
|
},
|
2023-04-15 16:10:04 +00:00
|
|
|
new[] { new MultipartFile("message.txt", stream, null, null, null) });
|
2021-08-25 18:36:13 +00:00
|
|
|
}
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
return;
|
2021-08-25 18:36:13 +00:00
|
|
|
}
|
2021-09-27 02:49:43 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (isDelete)
|
2021-09-27 02:49:43 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
if (!showContent)
|
|
|
|
throw new PKError(noShowContentError);
|
2021-09-27 02:49:43 +00:00
|
|
|
|
2022-01-11 14:43:55 +00:00
|
|
|
if (message.System?.Id != ctx.System.Id && message.Message.Sender != ctx.Author.Id)
|
2021-11-27 02:10:56 +00:00
|
|
|
throw new PKError("You can only delete your own messages.");
|
2021-09-27 02:49:43 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
await ctx.Rest.DeleteMessage(message.Message.Channel, message.Message.Mid);
|
2021-09-27 02:49:43 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
if (ctx.Channel.Id == message.Message.Channel)
|
2021-09-27 02:49:43 +00:00
|
|
|
await ctx.Rest.DeleteMessage(ctx.Message);
|
|
|
|
else
|
2021-11-27 02:10:56 +00:00
|
|
|
await ctx.Rest.CreateReaction(ctx.Message.ChannelId, ctx.Message.Id,
|
|
|
|
new Emoji { Name = Emojis.Success });
|
|
|
|
|
|
|
|
return;
|
2021-09-27 02:49:43 +00:00
|
|
|
}
|
2021-11-27 02:10:56 +00:00
|
|
|
|
|
|
|
if (ctx.Match("author") || ctx.MatchFlag("author"))
|
|
|
|
{
|
2022-03-10 01:06:53 +00:00
|
|
|
var user = await _rest.GetUser(message.Message.Sender);
|
2021-11-27 02:10:56 +00:00
|
|
|
var eb = new EmbedBuilder()
|
|
|
|
.Author(new Embed.EmbedAuthor(
|
|
|
|
user != null
|
|
|
|
? $"{user.Username}#{user.Discriminator}"
|
|
|
|
: $"Deleted user ${message.Message.Sender}",
|
|
|
|
IconUrl: user != null ? user.AvatarUrl() : null))
|
|
|
|
.Description(message.Message.Sender.ToString());
|
|
|
|
|
|
|
|
await ctx.Reply(
|
|
|
|
user != null ? $"{user.Mention()} ({user.Id})" : $"*(deleted user {message.Message.Sender})*",
|
|
|
|
eb.Build());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await ctx.Reply(embed: await _embeds.CreateMessageInfoEmbed(message, showContent));
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task DeleteCommandMessage(Context ctx, ulong messageId)
|
|
|
|
{
|
2022-06-20 00:28:55 +00:00
|
|
|
var (authorId, channelId) = await ctx.Services.Resolve<CommandMessageService>().GetCommandMessage(messageId);
|
|
|
|
if (authorId == null)
|
2021-11-27 02:10:56 +00:00
|
|
|
throw Errors.MessageNotFound(messageId);
|
|
|
|
|
2022-06-20 00:28:55 +00:00
|
|
|
if (authorId != ctx.Author.Id)
|
2021-11-27 02:10:56 +00:00
|
|
|
throw new PKError("You can only delete command messages queried by this account.");
|
|
|
|
|
2022-06-20 00:28:55 +00:00
|
|
|
await ctx.Rest.DeleteMessage(channelId!.Value, messageId);
|
2021-11-27 02:10:56 +00:00
|
|
|
|
|
|
|
if (ctx.Guild != null)
|
|
|
|
await ctx.Rest.DeleteMessage(ctx.Message);
|
|
|
|
else
|
|
|
|
await ctx.Rest.CreateReaction(ctx.Message.ChannelId, ctx.Message.Id, new Emoji { Name = Emojis.Success });
|
2021-05-03 10:33:30 +00:00
|
|
|
}
|
2021-08-27 15:03:47 +00:00
|
|
|
}
|