public async Task NotifyAboutPenaltyAsync(SocketGuildUser user, ITextChannel channel, PenaltyInfo info, string byWho = "automat") { var embed = new EmbedBuilder { Color = (info.Type == PenaltyType.Mute) ? EMType.Warning.Color() : EMType.Error.Color(), Footer = new EmbedFooterBuilder().WithText($"Przez: {byWho}"), Description = $"Powód: {info.Reason}".TrimToLength(1800), Author = new EmbedAuthorBuilder().WithUser(user), Fields = new List <EmbedFieldBuilder> { new EmbedFieldBuilder { IsInline = true, Name = "UserId:", Value = $"{user.Id}", }, new EmbedFieldBuilder { IsInline = true, Name = "Typ:", Value = info.Type, }, new EmbedFieldBuilder { IsInline = true, Name = "Kiedy:", Value = $"{info.StartDate.ToShortDateString()} {info.StartDate.ToShortTimeString()}" }, new EmbedFieldBuilder { IsInline = true, Name = "Na ile:", Value = $"{info.DurationInHours/24} dni {info.DurationInHours%24} godzin", } } }; if (channel != null) { await channel.SendMessageAsync("", embed : embed.Build()); } try { var dm = await user.GetOrCreateDMChannelAsync(); if (dm != null) { await dm.SendMessageAsync($"Elo! Zostałeś ukarany mutem na {info.DurationInHours/24} dni {info.DurationInHours%24} godzin. Pozdrawiam serdecznie!"); await dm.CloseAsync(); } } catch (Exception ex) { _logger.Log($"in mute: {ex}"); } }
public void AddSpeedPenalty(Type key, int penaltyPercent) { if (speedPenalties.ContainsKey(key)) { speedPenalties[key].count += 1; } else { speedPenalties[key] = new PenaltyInfo(1, penaltyPercent); } }
private async Task RemovePenaltyFromDb(Database.ManagmentContext db, PenaltyInfo penalty) { if (penalty == null) { return; } db.OwnedRoles.RemoveRange(penalty.Roles); db.Penalties.Remove(penalty); await db.SaveChangesAsync(); QueryCacheManager.ExpireTag(new string[] { $"mute" }); }
public async Task <PenaltyInfo> BanUserAysnc(SocketGuildUser user, Database.ManagmentContext db, long duration, string reason = "nie podano") { var info = new PenaltyInfo { User = user.Id, Reason = reason, Guild = user.Guild.Id, Type = PenaltyType.Ban, StartDate = DateTime.Now, DurationInHours = duration, Roles = new List <OwnedRole>(), }; await db.Penalties.AddAsync(info); await db.SaveChangesAsync(); QueryCacheManager.ExpireTag(new string[] { $"mute" }); await user.Guild.AddBanAsync(user, 0, reason); return(info); }
public async Task <PenaltyInfo> MuteUserAysnc(SocketGuildUser user, SocketRole muteRole, SocketRole muteModRole, SocketRole userRole, Database.ManagmentContext db, long duration, string reason = "nie podano", IEnumerable <ModeratorRoles> modRoles = null) { var info = new PenaltyInfo { User = user.Id, Reason = reason, Guild = user.Guild.Id, Type = PenaltyType.Mute, StartDate = DateTime.Now, DurationInHours = duration, Roles = new List <OwnedRole>(), }; await db.Penalties.AddAsync(info); if (userRole != null) { if (user.Roles.Contains(userRole)) { await user.RemoveRoleAsync(userRole); info.Roles.Add(new OwnedRole { Role = userRole.Id }); } } if (modRoles != null) { foreach (var r in modRoles) { var role = user.Roles.FirstOrDefault(x => x.Id == r.Role); if (role == null) { continue; } await user.RemoveRoleAsync(role); info.Roles.Add(new OwnedRole { Role = role.Id }); } } if (!user.Roles.Contains(muteRole)) { await user.AddRoleAsync(muteRole); } if (muteModRole != null) { if (!user.Roles.Contains(muteModRole)) { await user.AddRoleAsync(muteModRole); } } await db.SaveChangesAsync(); QueryCacheManager.ExpireTag(new string[] { $"mute" }); return(info); }