public async Task <IActionResult> EditMessage(ulong guildId, ulong messageId, [Bind(nameof(ApiManagedMessage.Content), nameof(ApiManagedMessage.ModeratorRoleId))] ApiManagedMessage message) { if (message.ModeratorRoleId != null && !await _client.ValidateGuildAdminAsync(User.GetId(), guildId)) { throw new UserNotGuildAdminException(); } var dbMsg = await _msgManager.GetMessageAsync(guildId, messageId); if (dbMsg == null) { throw new MessageNotFoundException(); } if (!await _client.ValidateResourceModeratorAsync(User.GetId(), guildId, dbMsg.ModeratorRoleId)) { throw new UserNotGuildModeratorException(); } await _msgManager.EditMessageAsync(guildId, messageId, message.Content, message.ModeratorRoleId); return(Ok()); }
public async Task <IActionResult> CreateMessage(ulong guildId, [Bind(nameof(ApiManagedMessage.Content), nameof(ApiManagedMessage.ChannelId), nameof(ApiManagedMessage.Id), nameof(ApiManagedMessage.ModeratorRoleId))] ApiManagedMessage message) { if (!await _client.ValidateGuildAdminAsync(User.GetId(), guildId)) { throw new UserNotGuildAdminException(); } // If create new message if (message.Content != null) { var msg = await _msgManager.PostMessageAsync(guildId, message.ChannelId, message.Content, message.ModeratorRoleId); return(Content(new ApiManagedMessage(msg))); } // If import a message if (message.Id != 0) { var msg = await _msgManager.ImportMessageAsync(guildId, message.ChannelId, message.Id, message.ModeratorRoleId); return(Content(new ApiManagedMessage(msg))); } throw new ContentNotProvidedException(); }