public async Task <IActionResult> Get([FromBody] BlockedUserModel model) { var blockingUser = await GetCurrentUserAsync(); if (blockingUser is null || blockingUser is default(User)) { return(Unauthorized("No authorized user found.\nPlease log in by using your credentials.")); } if (model is null) { return(BadRequest("Model cannot be null.")); } if (string.IsNullOrEmpty(model.BlockedUserName)) { return(BadRequest("BlockedUserName cannot be null.")); } if (string.Equals(model.BlockedUserName, blockingUser.Username)) { return(BadRequest("Your username cannot be same with BlockedUsername.")); } var blockedUser = await _userService.GetUserByUsernameAsync(model.BlockedUserName); if (blockedUser is null) { return(NotFound("Blocked user not found.")); } // Get blockedUser. BlockedUser result; try { result = await _blockedUserService.GetBlockedUserByBlockingUserIdAsync(blockedUser.Id, blockingUser.Id); if (result is null || result is default(BlockedUser)) { return(NotFound("No blockedUser found.")); } } catch (Exception ex) { await _logService.LogErrorAsync(new CreateLogModel() { UserId = blockingUser.Id, Title = "Get Error", Message = "Error happened in BlockedUser Controller, Get function", Exception = ex }); return(NotFound("No blockedUser found.")); } return(Ok(result)); }
private async Task HandleMessageReceived(SocketMessage incoming) { var message = incoming as SocketUserMessage; if (message is null) { return; } int argPos = 0; var borkContext = new DoggoCommandContext(borkClient, message); if (!message.HasStringPrefix(borkConfig.LoadedSecrets.BotPrefix, ref argPos) || message.HasMentionPrefix(borkClient.CurrentUser, ref argPos)) { return; } if (borkConfig.BlockedUsers.ContainsKey(message.Author.Id)) { string ifBlockIsPerm = ""; BlockedUserModel blockedUser = borkConfig.BlockedUsers[message.Author.Id]; if (blockedUser.Permanent) { ifBlockIsPerm = $"Your block is permanent, please DM {(await borkClient.GetApplicationInfoAsync()).Owner} if you wish to appeal."; } else { ifBlockIsPerm = $"Your block is not permanent, it will be repealed eventually."; } await borkContext.Channel.SendMessageAsync("", false, new EmbedBuilder() .WithColor(new Color(0, 0, 0)) .WithDescription($"**Error: You have been blocked from using commands.**\n`Blocked On:` *{blockedUser.BlockedTime.Date:MM/dd/yyyy}*\n\n`Reason:` *{blockedUser.Reason}*") .WithFooter(x => { x.Text = ifBlockIsPerm; }).Build()); return; } using (IDisposable enterTyping = borkContext.Channel.EnterTypingState()) { var res = await borkCommands.ExecuteAsync(borkContext, argPos, borkServices); if (!res.IsSuccess) { if (res.Error == CommandError.UnknownCommand) { await borkContext.Channel.SendMessageAsync("Sorry! I didn't understand that command, please try again! :triangular_flag_on_post:"); } else if (res.Error == CommandError.BadArgCount) { await borkContext.Channel.SendMessageAsync("Oh no! You didn't put enough parameters, check help if you need to! :scales:"); } else { await borkContext.Channel.SendMessageAsync(res.ErrorReason); } } enterTyping.Dispose(); } }