public async Task <bool> AddCustomCommandAsync(string guildId, CustomCommandDto customCommandDto, User user) { try { var guild = await _guildService.GetByGuildIdAsync(guildId); var discordGuild = await _botService.GetGuildAsync(guildId); var member = await discordGuild.GetMemberAsync(ulong.Parse(user.UserId)); var hasPermission = await CheckIfHasPermissionAsync(member, discordGuild, guild); if (!hasPermission) { return(false); } var initiator = await _userService.GetByUsernameAndDiscriminatorAsync(user.UserName, user.Discriminator); guild.CustomCommandPlugin.Commands.Add(new Command { Description = customCommandDto.Description, Prefix = customCommandDto.Prefix, CommandCall = customCommandDto.CommandCall, IsEnabled = true, }); await _logService.AddAsync( $"ADDED_A_CUSTOM_COMMAND", ActionType.Update, initiator, guildId ); await _pluginRepository.SaveAllAsync(); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }
public async Task <IActionResult> AddCustomCommand([FromRoute] string guildId, CustomCommandDto customCommandDto) { var user = await _userManager.GetUserAsync(User); var result = await _pluginService.AddCustomCommandAsync(guildId, customCommandDto, user); if (!result) { return(BadRequest()); } return(Ok()); }