Example #1
0
        public async Task <IActionResult> DeleteMessage([FromRoute] ulong guildId, [FromRoute] int id)
        {
            await RequirePermission(guildId, DiscordPermission.Moderator);
            await GetRegisteredGuild(guildId);

            Identity identity = await GetIdentity();

            ScheduledMessageRepository repo = ScheduledMessageRepository.CreateDefault(_serviceProvider, identity);

            ScheduledMessage message = await repo.GetMessage(id);

            if (message.GuildId != guildId)
            {
                throw new UnauthorizedException();
            }

            // handled messages should only be deletable by an admin to prevent abuse
            if (message.Status != ScheduledMessageStatus.Pending && !(await identity.HasAdminRoleOnGuild(guildId)))
            {
                throw new ProtectedScheduledMessageException();
            }

            await repo.DeleteMessage(message.Id);

            return(Ok());
        }