/// <inheritdoc /> public async Task <UserWarnings> GetUser(ulong userId, ulong guildId, params Expression <Func <UserWarnings, object> >[] includes) { UserWarnings userData; using (var scope = _scopeFactory.CreateScope()) { var userWarningService = scope.ServiceProvider.GetRequiredService <IEntityService <UserWarnings> >(); var userDataDb = await userWarningService.GetFirst(u => u.UserId == userId, includes); // User isn't tracked yet, so create new entry for them. if (userDataDb == null) { userData = new UserWarnings { GuildId = guildId, UserId = userId }; await userWarningService.Create(userData); } else { userData = userDataDb; } } return(userData); }
/// <inheritdoc /> public bool IsPunishmentAlreadyActive(Punishment punishment, UserWarnings userData) { var currentlyActivePunishments = userData.ActivePunishments; // bool indicating whether user already has punishment. return(currentlyActivePunishments.Any(x => x.PunishmentId == punishment.Id)); }
private async Task <List <Punishment> > GetPunishmentsToApply(UserWarnings userData, FilterType warningType) { var moderationSettings = await _moderationModuleUtils.GetModerationSettings(userData.GuildId); // Get all warnings that haven't expired. var userWarnings = userData.Warnings.Where(x => x.WarningExpires > DateTimeOffset.Now); // Count warnings of violation type. var specificWarningCount = userWarnings.Count(x => x.WarningType == warningType); // Count total number of warnings. var allWarningsCount = userWarnings.Count(); var punishments = new List <Punishment>(); // Global punishments punishments.AddRange(moderationSettings.Punishments.Where(x => x.WarningType == FilterType.Global && x.WarningThreshold == allWarningsCount)); // Punishments for specific type. I.E. profanity violation. punishments.AddRange(moderationSettings.Punishments.Where(x => x.WarningType == warningType && x.WarningThreshold == specificWarningCount)); return(punishments); }
private async Task AddWarning(SocketGuildUser user, UserWarnings userData, FilterType warningType) { // Add warning to database. var newWarning = await _warningService.AddWarning(user, warningType); // Update cached version. userData.Warnings.Add(newWarning); }
public static Warning GetWarning(UserWarnings user, uint id) { var result = from w in user.Warnings where w.ID == id select w; Warning warning = result.FirstOrDefault(); return(warning); }
private static UserWarnings CreateUserWarnings(SocketUser user) { UserWarnings uw = new UserWarnings() { ID = user.Id, Warnings = new List <Warning>() }; _usersWarnings.Add(uw); Save(); return(uw); }
private static UserWarnings GetOrCreateUserWarnings(SocketUser user) { var result = from u in _usersWarnings where u.ID == user.Id select u; UserWarnings userWarnings = result.FirstOrDefault(); if (userWarnings == null) { return(CreateUserWarnings(user)); } return(userWarnings); }
public async Task Warn(SocketGuildUser user, [Remainder] string reason = "Naruszenie regulaminu serwera") { Random random = new Random(DateTime.Now.Millisecond); uint id = (uint)random.Next(0, 100000); GuildCfg guildCfg = GuildsCfgs.GetGuildCfg(Context.Guild); IDMChannel dmChannel = await user.GetOrCreateDMChannelAsync(); ISocketMessageChannel modChannel = (ISocketMessageChannel)Methods.GetTextChannelByID(Context.Guild, guildCfg.ModeratorChannelID); UserWarnings account = UsersWarnings.GetUserWarnings(user); SocketRole role = Methods.GetRoleByID(Context.Guild, guildCfg.PunishmentRoleID); Methods.DeleteExpiredWarnings(account); Warning warning = Warnings.CreateWarning(id, reason, guildCfg.WarnDuration); account.Warnings.Add(warning); UsersWarnings.Save(); string msg = ""; string message = ""; if (account.Warnings.Count >= 5) { await user.BanAsync(0, "Przekroczenie limitu ostrzeżeń."); } else if (account.Warnings.Count > 2) { await user.AddRoleAsync(role); msg = $"{user.Mention} przekroczyłeś limit dopuszczalnych ostrzeżeń, co spowodowało Twój pobyt w {role.Name}.\nPowód ostatniego ostrzeżenia: {reason}\nPolecam przeczytać regulamin dostępny na <#{guildCfg.StatuteChannelID}>."; message = $"KarcNaN: Przekroczono limit ostrzeżeń, co skutkuje pobytem {user.Mention} w Karcerze.\nDokładna treść wysłanej wiadomości:\n{msg}"; } else { msg = $"{user.Mention} otrzymałeś ostrzeżenie, powód: {reason}\nMasz {account.Warnings.Count} ostrzeżeń (maksymalnie możesz mieć 2, każdy kolejny, to {role.Name}).\nPolecam przeczytać regulamin dostępny na <#{guildCfg.StatuteChannelID}>."; message = $"Ostrz101: Dokładna treść wysłanej wiadomości:\n{msg}"; } await dmChannel.SendMessageAsync(msg); await modChannel.SendMessageAsync(message); }
public static void DeleteExpiredWarnings(UserWarnings account) { try { for (int i = account.Warnings.Count - 1; i >= 0; i--) { if (DateTime.Compare(DateTime.Now, account.Warnings[i].ExpireDate) >= 0) { account.Warnings.RemoveAt(i); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } UsersWarnings.Save(); }
public async Task CheckWarnings(SocketUser user = null) { if (user == null) { user = Context.User; } UserWarnings account = UsersWarnings.GetUserWarnings(user); Methods.DeleteExpiredWarnings(account); string warns = $"Ostrzeżenia {user.Username}:\n"; foreach (Warning warn in account.Warnings) { warns += $"{warn.ID} - {warn.Reason} ({warn.ExpireDate})\n"; } await Context.Channel.SendMessageAsync(warns); }
public async Task RemoveWarning(SocketGuildUser user, uint id) { GuildCfg guildCfg = GuildsCfgs.GetGuildCfg(Context.Guild); ISocketMessageChannel modChannel = (ISocketMessageChannel)Methods.GetTextChannelByID(Context.Guild, guildCfg.ModeratorChannelID); UserWarnings account = UsersWarnings.GetUserWarnings(user); Warning warning = Warnings.GetWarning(account, id); if (warning != null) { account.Warnings.Remove(warning); UsersWarnings.Save(); await modChannel.SendMessageAsync($"Pomyślnie usunięto ostrzeżenie {warning.ID} z konta {user.Mention}."); } else { await modChannel.SendMessageAsync($"Coś poszło nie tak... Czy na pewno użyłeś dobrego ID? 🤔"); } }
public async Task CheckStatus(SocketUser user = null) { if (user == null) { user = Context.User; } UserExpMute userExp = UsersExpMute.GetExpMute(user.Id); UserPraises uPraises = UsersPraises.GetUserPraises(user.Id); UserArchievements uArchievements = UsersArchievements.GetUserArchievements(user.Id); UserWarnings accountWarns = UsersWarnings.GetUserWarnings(user); Methods.DeleteExpiredWarnings(accountWarns); string archievements = "Osiągnięcia:\n"; foreach (string item in uArchievements.Archievements) { archievements += $"{item}\n"; } await Context.Channel.SendMessageAsync($"{user.Username} ma {userExp.LevelNumber} lvl, {userExp.XP} xp. Został pochwalony {uPraises.Praises.Count} razy oraz otrzymał {accountWarns.Warnings.Count} ostrzeżeń.\n{archievements}"); }
private async Task ApplyPunishments(SocketGuildUser user, UserWarnings userData, FilterType warningType) { var punishments = await GetPunishmentsToApply(userData, warningType); await _punishmentService.ApplyPunishments(punishments, user); }