示例#1
0
        public async Task EditMessage(Context ctx)
        {
            var msg = await GetMessageToEdit(ctx);

            if (!ctx.HasNext())
            {
                throw new PKSyntaxError("You need to include the message to edit in.");
            }

            if (ctx.Author.Id != msg.Sender)
            {
                throw new PKError("Can't edit a message sent from a different account.");
            }

            var newContent = ctx.RemainderOrNull();

            var originalMsg = await _rest.GetMessage(msg.Channel, msg.Mid);

            try
            {
                await _webhookExecutor.EditWebhookMessage(msg.Channel, msg.Mid, newContent);

                if (ctx.Guild == null)
                {
                    await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new() { Name = Emojis.Success });
                }

                if (ctx.BotPermissions.HasFlag(PermissionSet.ManageMessages))
                {
                    await _rest.DeleteMessage(ctx.Channel.Id, ctx.Message.Id);
                }

                await _logChannel.LogEditedMessage(ctx.MessageContext, msg, ctx.Message, originalMsg !, newContent);
            }
            catch (NotFoundException)
            {
                throw new PKError("Could not edit message.");
            }
        }