private async Task ExileUserAsync(ulong userID) { try { SocketGuildUser user = Context.Guild.GetUser(userID); if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } ulong peasantRoleID = ConfigManager.GetUlongProperty(PropertyItem.Role_Peasant); var roleToApply = Context.Guild.GetRole(peasantRoleID); var rolesToRemove = user.Roles.Where(x => x.IsEveryone == false); var embed = new EmbedBuilder(); embed.WithTitle($"{user.Username} has been stripped of their lands and titles, and banished to the gate {DiscordContextSeymour.GetEmoteReee()}"); embed.WithColor(new Color(255, 0, 0)); await Context.Channel.SendMessageAsync("", false, embed.Build()); await user.RemoveRolesAsync(rolesToRemove); await user.AddRoleAsync(roleToApply); await DiscordContextOverseer.LogModerationAction(userID, "Exiled", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.ExileException, ex); } }
private async Task UnblacklistUserAsync(ulong userID) { try { SocketGuildUser user = await Context.Channel.GetUserAsync(userID) as SocketGuildUser; if (user == null) { await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}"); return; } bool existing = await StorageManager.RemoveBlacklist(user.Id); if (existing) { var embed = Utilities.BuildRemoveDisciplinaryEmbed("Successfully unblacklisted", user.Username); await Context.Channel.SendMessageAsync("", false, embed); } else { await Context.Channel.SendMessageAsync("Could not find that user within the blacklist"); } await DiscordContextOverseer.LogModerationAction(user.Id, "Unblacklisted", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.UnblacklistException, ex); } }
private async Task UnmuteUserAsync(SocketGuildUser user) { try { var role = user.Roles.FirstOrDefault(x => x.Id == ConfigManager.GetUlongProperty(PropertyItem.Role_Muted)); if (role == null) { await Context.Channel.SendMessageAsync("Cannot see muted role on that user"); return; } await user.RemoveRoleAsync(role); var embed = Utilities.BuildRemoveDisciplinaryEmbed($"Successfully unmuted", user.Username); await Context.Channel.SendMessageAsync("", false, embed); await StorageManager.RemoveDisciplinaryEventAsync(user.Id, DisciplinaryEventEnum.MuteEvent); await DiscordContextOverseer.LogModerationAction(user.Id, "Unmuted", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.UnmuteException, ex); } }
private async Task UnrestrictUserAsync(ulong userID) { try { SocketGuildUser user = Context.Guild.GetUser(userID); if (user == null) { await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}"); return; } var role = user.Roles.FirstOrDefault(x => x.Id == ConfigManager.GetUlongProperty(PropertyItem.Role_Restricted)); if (role != null) { await Context.Channel.SendMessageAsync("Cannot see restricted role on that user"); return; } await user.RemoveRoleAsync(role); var embed = Utilities.BuildRemoveDisciplinaryEmbed($"Successfully unrestricted", user.Username); await Context.Channel.SendMessageAsync("", false, embed); await StorageManager.RemoveDisciplinaryEventAsync(userID, DisciplinaryEventEnum.RestrictedUserEvent); await DiscordContextOverseer.LogModerationAction(userID, "Unrestricted", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.UnlimitException, ex); } }
private async Task BlacklistUserAsync(SocketGuildUser user, TimeSpan timeSpan) { try { if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } bool existing = await StorageManager.StoreBlacklistReturnIfExisting(new BlacklistUserStorage() { Username = user.Username, DateInserted = DateTime.UtcNow, ModeratorID = Context.Message.Author.Id, DateToRemove = (DateTimeOffset.UtcNow + timeSpan).DateTime, UserID = user.Id }, new UserStorage() { UserID = user.Id, UserName = user.Username, }); var embed = Utilities.BuildBlacklistEmbed(timeSpan, user.Username, existing, Context.Message.Author.Username); await Context.Channel.SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(user.Id, "Blacklisted", Context.Message.Author.Id, "", timeSpan.ToString()); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.BlacklistException, ex); } }
public static async Task MassMentionCheck(SocketCommandContext context) { try { if (context.Message.MentionedUsers.Count > 8) { SocketUser target = context.Message.Author; await context.Message.DeleteAsync(); await DiscordContextSeymour.AddRole(DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted), target.Id); await DiscordContextOverseer.LogModerationAction(target.Id, "Muted", "excessive pinging", Utilities.ShortTimeSpanFormatting(new TimeSpan(3, 0, 0, 0))); await TimedEventManager.CreateEvent(DisciplinaryEventEnum.MuteEvent, context.Client.CurrentUser.Id, "excessive pinging", target.Id, target.Username, (DateTimeOffset.UtcNow + new TimeSpan(0, 30, 0)).DateTime); await TimedEventManager.CreateEvent(DisciplinaryEventEnum.WarnEvent, context.Client.CurrentUser.Id, "AutoWarn : excessive pinging", target.Id, target.Username, DateTime.UtcNow.AddDays(ConfigManager.GetIntegerProperty(PropertyItem.WarnDuration))); if (context.Channel != null) { await DiscordContextOverseer.GetChannel(context.Channel.Id).SendMessageAsync($"{context.Message.Author.Mention}, Thou shall not say thy noble's names in vain. {DiscordContextSeymour.GetEmoteAyySeymour()}"); } } } catch (Exception ex) { ExceptionManager.HandleException($"{typeof(AutoModeratorManager).GetType().FullName}: {ExceptionManager.GetAsyncMethodName()}", ex); } }
public static async Task CheckForWarnThreshold(SocketGuildUser target, SocketCommandContext context, int warnCount, ITextChannel chnl = null) { try { if (warnCount >= (ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns))) //more or equal the warn thresold { await DiscordContextSeymour.AddRole(DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted), target.Id); await DiscordContextOverseer.LogModerationAction(target.Id, "Muted", $"User has been warned {warnCount} times, exceeding the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", Utilities.ShortTimeSpanFormatting(new TimeSpan(1, 0, 0, 0))); await TimedEventManager.CreateEvent(DisciplinaryEventEnum.MuteEvent, context.Client.CurrentUser.Id, $"User has been warned {warnCount} times, exceeding the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", target.Id, target.Username, (DateTimeOffset.UtcNow + new TimeSpan(1, 0, 0, 0)).DateTime); if (chnl == null) { await DiscordContextOverseer.GetChannel(context.Channel.Id).SendMessageAsync($"Silence. {target.Mention}"); } else { await DiscordContextOverseer.GetChannel(chnl.Id).SendMessageAsync($"Silence. {target.Mention}"); } } else if (warnCount > (ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns) / 2)) //more than half the warn thresold { await DiscordContextSeymour.AddRole(DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted), target.Id); await DiscordContextOverseer.LogModerationAction(target.Id, "Muted", $"User has been warned {warnCount} times, exceeding half of the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", Utilities.ShortTimeSpanFormatting(new TimeSpan(0, 30, 0))); await TimedEventManager.CreateEvent(DisciplinaryEventEnum.MuteEvent, context.Client.CurrentUser.Id, $"User has been warned {warnCount} times, exceeding half of the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", target.Id, target.Username, (DateTimeOffset.UtcNow + new TimeSpan(0, 30, 0)).DateTime); if (chnl == null) //channel specified check { await DiscordContextOverseer.GetChannel(context.Channel.Id).SendMessageAsync($"{target.Mention}, enough."); } else { await DiscordContextOverseer.GetChannel(chnl.Id).SendMessageAsync($"{target.Mention}, enough."); } } } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.CheckForWarnThresholdException, ex); } }
private static async Task HandleEventElapsed(ActiveTimedEvent activeEvent) { try { switch (activeEvent.DisciplinaryEvent) { case DisciplinaryEventEnum.MuteEvent: ActiveEvents.Remove(activeEvent); await DiscordContextSeymour.RemoveRoleAsync(activeEvent.UserId, ConfigManager.GetUlongProperty(PropertyItem.Role_Muted)); await DiscordContextOverseer.LogModerationAction(activeEvent.UserId, "Unmuted", activeEvent.Reason, ""); await StorageManager.ArchiveTimedEventAsync(activeEvent.DisciplinaryEventId); break; case DisciplinaryEventEnum.WarnEvent: ActiveEvents.Remove(activeEvent); await StorageManager.ArchiveTimedEventAsync(activeEvent.DisciplinaryEventId); break; case DisciplinaryEventEnum.LimitedUserEvent: ActiveEvents.Remove(activeEvent); await DiscordContextSeymour.RemoveRoleAsync(activeEvent.UserId, ConfigManager.GetUlongProperty(PropertyItem.Role_LimitedUser)); await DiscordContextOverseer.LogModerationAction(activeEvent.UserId, "Unlimited", activeEvent.Reason, ""); await StorageManager.ArchiveTimedEventAsync(activeEvent.DisciplinaryEventId); break; case DisciplinaryEventEnum.RestrictedUserEvent: ActiveEvents.Remove(activeEvent); await DiscordContextSeymour.RemoveRoleAsync(activeEvent.UserId, ConfigManager.GetUlongProperty(PropertyItem.Role_Restricted)); await DiscordContextOverseer.LogModerationAction(activeEvent.UserId, "Unrestricted", activeEvent.Reason, ""); await StorageManager.ArchiveTimedEventAsync(activeEvent.DisciplinaryEventId); break; default: ActiveEvents.Remove(activeEvent); await DiscordContextOverseer.LogModerationAction(activeEvent.UserId, $"Err : {activeEvent.DisciplinaryEvent.ToString()}", activeEvent.Reason, ""); break; } } catch (Exception ex) { await ExceptionManager.LogExceptionAsync(ex); } }
public static async Task EnforceRestricted(SocketCommandContext context) { try { if (new Regex(@"(http(s)?:\/\/)?([a-z][-\w]+(?:\.\w+)+(?:\S+)?)", RegexOptions.IgnoreCase | RegexOptions.Compiled).IsMatch(context.Message.Content)) { await context.Message.DeleteAsync(); await DiscordContextOverseer.LogModerationAction(context.Message.Author.Id, "Blocked from posting a link", $"posting links while restricted in message id : {context.Message.Id}", ""); } } catch (Exception ex) { ExceptionManager.HandleException($"{typeof(AutoModeratorManager).GetType().FullName}: {ExceptionManager.GetAsyncMethodName()}", ex); } }
private async Task MuteUserAsync(ulong userID, TimeSpan timeSpan, [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 mutedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted); await user.AddRoleAsync(mutedRole); UserDisciplinaryEventStorage newEvent = new UserDisciplinaryEventStorage() { DateInserted = DateTime.UtcNow, DateToRemove = (DateTimeOffset.UtcNow + timeSpan).DateTime, 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 TimedEventManager.CreateEvent(newEvent, newUser); await DiscordContextOverseer.LogModerationAction(userID, "Muted", Context.Message.Author.Id, reason, Utilities.ShortTimeSpanFormatting(timeSpan)); var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.MuteEvent, timeSpan, reason, user.Username, existing); await DiscordContextSeymour.GetMainChannel().SendMessageAsync("", false, embed); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.MuteException, ex); } }
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 PardonUserAsync(ulong userID) { try { var user = Context.Guild.GetUser(userID); if (user != null) { bool existing = await StorageManager.RemoveActiveDisciplinaries(userID); if (existing) { ulong mutedRoleID = ConfigManager.GetUlongProperty(PropertyItem.Role_Muted); ulong limitedRoleID = ConfigManager.GetUlongProperty(PropertyItem.Role_LimitedUser); var rolesToRemove = new List <IRole>(); foreach (var role in user.Roles) { if (role.Id == limitedRoleID || role.Id == mutedRoleID) { rolesToRemove.Add(role); } } if (rolesToRemove.Count() > 0) { await user.RemoveRolesAsync(rolesToRemove); } await DiscordContextOverseer.LogModerationAction(userID, "Pardonned", Context.Message.Author.Id, "", ""); await Context.Channel.SendMessageAsync($"{user.Mention} has been pardoned for their crimes"); } else { await Context.Channel.SendMessageAsync($"Could not find active punishments for {user.Mention}"); } } else { await Context.Channel.SendMessageAsync($"Unable to locate user"); } } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.PardonException, ex); } }
private async Task MonthBlacklistUserAsync(ulong userID) { try { SocketGuildUser user = await Context.Channel.GetUserAsync(userID) as SocketGuildUser; if (user == null) { await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}"); return; } if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } bool existing = await StorageManager.StoreBlacklistReturnIfExisting(new BlacklistUserStorage() { Username = user.Username, DateInserted = DateTime.UtcNow, ModeratorID = Context.Message.Author.Id, DateToRemove = DateTime.UtcNow.AddMonths(1), UserID = user.Id }, new UserStorage() { UserID = user.Id, UserName = user.Username, }); var embed = Utilities.BuildBlacklistEmbed(new TimeSpan(), user.Username, existing); await DiscordContextSeymour.GetMainChannel().SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(user.Id, "Blacklisted", Context.Message.Author.Id, "", DateTime.UtcNow.AddMonths(1).Subtract(DateTime.UtcNow).ToString()); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.BlacklistException, ex); } }
private async Task RestrictUserAsync(SocketGuildUser user, TimeSpan timeSpan, [Remainder] string reason = "no reason specified") { try { if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser)) { return; } var limitedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Restricted); await user.AddRoleAsync(limitedRole); UserDisciplinaryEventStorage newEvent = new UserDisciplinaryEventStorage() { DateInserted = DateTime.UtcNow, DateToRemove = (DateTimeOffset.UtcNow + timeSpan).DateTime, 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 TimedEventManager.CreateEvent(newEvent, newUser); var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.RestrictedUserEvent, timeSpan, reason, user.Username, existing, Context.Message.Author.Username); await Context.Channel.SendMessageAsync("", false, embed); await DiscordContextOverseer.LogModerationAction(user.Id, "Restricted", Context.Message.Author.Id, reason, Utilities.ShortTimeSpanFormatting(timeSpan)); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.LimitException, ex); } }
private async Task UnblacklistUserAsync(SocketGuildUser user) { try { bool existing = await StorageManager.RemoveBlacklist(user.Id); if (existing) { var embed = Utilities.BuildRemoveDisciplinaryEmbed("Successfully unblacklisted", user.Username); await Context.Channel.SendMessageAsync("", false, embed); } else { await Context.Channel.SendMessageAsync("Could not find that user within the blacklist"); } await DiscordContextOverseer.LogModerationAction(user.Id, "Unblacklisted", Context.Message.Author.Id, "", ""); } catch (Exception ex) { ExceptionManager.HandleException(ErrMessages.UnblacklistException, 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); } }