Example #1
0
        public async Task <ActionResult> BanChatUser(ChatBanUserModel model)
        {
            model.UserId = User.Identity.GetUserId();
            await ChatHub.BanUser(model);

            return(CloseModalSuccess());
        }
        public async Task <ActionResult> SubmitChatBan(ChatBanUserModel model)
        {
            model.UserId = User.Identity.GetUserId();
            await ChatHub.BanUser(model);

            return(JsonSuccess());
        }
Example #3
0
        public static async Task BanUser(ChatBanUserModel model)
        {
            try
            {
                using (var context = new ApplicationDbContext())
                {
                    var banner = await context.Users.FirstOrDefaultNoLockAsync(x => x.Id == model.UserId);

                    var user = await context.Users.FirstOrDefaultNoLockAsync(x => x.Id == model.BanUserId);

                    if (user != null && banner != null)
                    {
                        if (model.Seconds == 0 && model.BanType != ChatBanType.Warning)
                        {
                            user.ChatBanEndTime    = DateTime.UtcNow;
                            user.ChatTipBanEndTime = DateTime.UtcNow;
                            await SendChatbotMessage(banner.UserName, "Ban Hammer", $"{user.ChatHandle} has been unbanned. {model.Message}");
                        }
                        else
                        {
                            string message = string.Empty;
                            switch (model.BanType)
                            {
                            case ChatBanType.Warning:
                                await SendChatbotMessage(banner.UserName, "Ban Hammer", $"{user.ChatHandle} {model.Message}");

                                return;

                            case ChatBanType.ChatOnly:
                                user.ChatBanEndTime = DateTime.UtcNow.AddSeconds(model.Seconds);
                                message             = $"{banner.ChatHandle} has banned {user.ChatHandle} from chat for {model.Seconds} seconds.";
                                break;

                            case ChatBanType.TipOnly:
                                user.ChatTipBanEndTime = DateTime.UtcNow.AddSeconds(model.Seconds);
                                message = $"{banner.ChatHandle} has banned {user.ChatHandle} from tips for {model.Seconds} seconds.";
                                break;

                            case ChatBanType.All:
                                user.ChatBanEndTime    = DateTime.UtcNow.AddSeconds(model.Seconds);
                                user.ChatTipBanEndTime = DateTime.UtcNow.AddSeconds(model.Seconds);
                                message = $"{banner.ChatHandle} has banned {user.ChatHandle} from chat & tips for {model.Seconds} seconds.";
                                break;

                            default:
                                break;
                            }

                            if (!string.IsNullOrEmpty(message))
                            {
                                if (!string.IsNullOrEmpty(model.Message))
                                {
                                    message = $"{message} Reason: {model.Message}";
                                }
                                await SendChatbotMessage(banner.UserName, "Ban Hammer", message);
                            }
                        }

                        await _cache.RemoveOnlineUser(user.Id);

                        await context.SaveChangesAsync();
                    }
                }
            }
            catch (Exception)
            {
            }
        }