public SupervisorMessage Get(string content) { var msg = Messages.FirstOrDefault(x => x.Content == content); if (msg == null) { msg = new SupervisorMessage(content, 0); Messages.Add(msg); } return(msg); }
private async Task Analize(SocketGuildUser user, SocketUserMessage message) { using (var db = new Database.GuildConfigContext(_config)) { var gConfig = await db.GetCachedGuildFullConfigAsync(user.Guild.Id); if (gConfig == null) { return; } if (!gConfig.Supervision) { return; } if (!_guilds.Any(x => x.Key == user.Guild.Id)) { _guilds.Add(user.Guild.Id, new Dictionary <ulong, SupervisorEntity>()); return; } var guild = _guilds[user.Guild.Id]; var messageContent = GetMessageContent(message); if (!guild.Any(x => x.Key == user.Id)) { guild.Add(user.Id, new SupervisorEntity(messageContent)); return; } var susspect = guild[user.Id]; if (!susspect.IsValid()) { susspect = new SupervisorEntity(messageContent); return; } var thisMessage = susspect.Get(messageContent); if (!thisMessage.IsValid()) { thisMessage = new SupervisorMessage(messageContent); } if (gConfig.AdminRole != 0) { if (user.Roles.Any(x => x.Id == gConfig.AdminRole)) { return; } } if (gConfig.ChannelsWithoutSupervision.Any(x => x.Channel == message.Channel.Id)) { return; } var muteRole = user.Guild.GetRole(gConfig.MuteRole); var userRole = user.Guild.GetRole(gConfig.UserRole); var notifChannel = user.Guild.GetTextChannel(gConfig.NotificationChannel); bool hasRole = user.Roles.Any(x => x.Id == gConfig.UserRole || x.Id == gConfig.MuteRole) || gConfig.UserRole == 0; var action = MakeDecision(messageContent, susspect.Inc(), thisMessage.Inc(), hasRole); await MakeActionAsync(action, user, message, userRole, muteRole, notifChannel); } }
public void Add(SupervisorMessage message) => Messages.Add(message);