private async Task PermaRestrictUserAsync(ulong userID, [Remainder] string reason = "no reason specified") { try { SocketGuildUser user = Context.Guild.GetUser(userID); if (user == null) { await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}"); return; } if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } var limitedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Restricted); await user.AddRoleAsync(limitedRole); UserDisciplinaryPermanentStorage newEvent = new UserDisciplinaryPermanentStorage() { DateInserted = DateTime.UtcNow, DiscipinaryEventType = DisciplinaryEventEnum.RestrictedUserEvent, ModeratorID = Context.Message.Author.Id, Reason = reason, UserID = user.Id }; UserStorage newUser = new UserStorage() { UserID = user.Id, UserName = user.Username }; bool existing = await StorageManager.StoreDisciplinaryPermanentEventAsync(newEvent, newUser); var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.RestrictedUserEvent, new TimeSpan(), reason, user.Username, existing); await DiscordContextSeymour.GetMainChannel().SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(userID, "Restricted", Context.Message.Author.Id, reason, ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.LimitException, ex); } }
private async Task PermaMuteUserAsync(SocketGuildUser user, [Remainder] string reason = "no reason specified") { try { if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } var mutedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted); await user.AddRoleAsync(mutedRole); UserDisciplinaryPermanentStorage newEvent = new UserDisciplinaryPermanentStorage() { DateInserted = DateTime.UtcNow, DiscipinaryEventType = DisciplinaryEventEnum.MuteEvent, ModeratorID = Context.Message.Author.Id, Reason = reason, UserID = user.Id }; UserStorage newUser = new UserStorage() { UserID = user.Id, UserName = user.Username }; bool existing = await StorageManager.StoreDisciplinaryPermanentEventAsync(newEvent, newUser); var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.MuteEvent, new TimeSpan(), reason, user.Username, existing, Context.Message.Author.Username); await Context.Channel.SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(user.Id, "Muted", Context.Message.Author.Id, reason, ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.MuteException, ex); } }
public static async Task <bool> StoreDisciplinaryPermanentEventAsync(UserDisciplinaryPermanentStorage obj, UserStorage user) { try { using (UserContext db = new UserContext()) { if (!await db.UserStorageTable.AsQueryable().AnyAsync(x => x.UserID == user.UserID)) { await db.AddAsync(user); } var existingEvent = await db.UserDisciplinaryPermanentStorageTable.AsQueryable().FirstOrDefaultAsync(x => x.UserID == user.UserID); if (existingEvent != null) { existingEvent = obj; await db.SaveChangesAsync(); return(true); } else { await db.AddAsync(obj); await db.SaveChangesAsync(); return(false); } } } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.StorageException, ex); throw; } }