private void HookUserEvents() { bot.UserJoined += async(SocketGuildUser socketGuildUser) => { var guild = await Guilds.GetAsync(socketGuildUser.Guild); if (guild is null) { return; } if (guild.General.Announce.IsAllowed(guild.General.Announce.Welcomes.Enabled)) { await Announce.AnnounceUserJoin(socketGuildUser); } if (guild.General.Enabled && guild.General.NewMemberRoles.Length > 0) { var socketGuild = socketGuildUser.Guild; var roles = guild.General.NewMemberRoles.Where(id => socketGuild.GetRole(id) != null); var foundRoles = roles.Select(id => socketGuild.GetRole(id)); foreach (var role in foundRoles) { try { await socketGuildUser.AddRolesAsync(foundRoles); } catch {} } } }; bot.UserLeft += async(SocketGuildUser socketGuildUser) => { var guild = await Guilds.GetAsync(socketGuildUser.Guild); if (guild is null) { return; } if (guild.General.Announce.IsAllowed(guild.General.Announce.Goodbyes.Enabled)) { await Announce.AnnounceUserLeft(socketGuildUser); } if (guild.Admin.Rulebox.Enabled) { await Rulebox.RemoveUserReaction(socketGuildUser); } if (ShouldLog(LogEvent.Kick, guild)) { await StaffLogs.LogKick(socketGuildUser); } }; bot.GuildMemberUpdated += async(SocketGuildUser socketGuildUser, SocketGuildUser instigator) => { var guild = await Guilds.GetAsync(socketGuildUser.Guild); if (guild is null) { return; } if (guild.Moderation.Auto.Enabled && guild.Moderation.Auto.ExplicitUsernamePunishment != PunishmentType.None) { await Auto.ValidateUsername(guild, socketGuildUser); } }; bot.UserBanned += async(SocketUser socketUser, SocketGuild socketGuild) => { var guild = await Guilds.GetAsync(socketGuild); if (guild is null) { return; } if (ShouldLog(LogEvent.Ban, guild)) { await StaffLogs.LogBan(socketUser, socketGuild); } }; bot.UserUnbanned += async(SocketUser socketUser, SocketGuild socketGuild) => { var guild = await Guilds.GetAsync(socketGuild); if (guild is null) { return; } if (ShouldLog(LogEvent.Unban, guild)) { await StaffLogs.LogUnban(socketUser, socketGuild); } }; GuildUser.Muted += async(GuildUser guildUser, Punishment punishment) => { var socketGuild = bot.GetGuild(guildUser.GuildID); var guild = await Guilds.GetAsync(socketGuild); if (guild is null) { return; } if (ShouldLog(LogEvent.Mute, guild)) { await StaffLogs.LogMute(guildUser, punishment); } }; GuildUser.Unmuted += async(GuildUser guildUser, Punishment punishment) => { var socketGuild = bot.GetGuild(guildUser.GuildID); var guild = await Guilds.GetAsync(socketGuild); if (guild is null) { return; } if (ShouldLog(LogEvent.Unmute, guild)) { await StaffLogs.LogUnmute(guildUser, punishment); } }; GuildUser.Warned += async(GuildUser guildUser, Punishment punishment) => { var socketGuild = bot.GetGuild(guildUser.GuildID); var guild = await Guilds.GetAsync(socketGuild); if (guild is null) { return; } if (ShouldLog(LogEvent.Warn, guild)) { await StaffLogs.LogWarn(guildUser, punishment); } }; }
private void HookMessageEvents() { bot.ReactionAdded += async(Cacheable <IUserMessage, ulong> before, ISocketMessageChannel channel, SocketReaction reaction) => { var socketGuildUser = reaction.User.Value as SocketGuildUser; var guild = await Guilds.GetAsync(socketGuildUser?.Guild); if (guild is null) { return; } if (guild.Admin.Rulebox.Enabled) { await Rulebox.CheckRuleAgreement(guild, socketGuildUser, reaction); } if (reaction.Message.IsSpecified && reaction.Message.Value != null) { await Users.CheckReputationAdded(reaction.Message.Value, reaction); } }; bot.ReactionRemoved += async(Cacheable <IUserMessage, ulong> before, ISocketMessageChannel channel, SocketReaction reaction) => { var socketGuild = (channel as SocketTextChannel)?.Guild; var guild = await Guilds.GetAsync(socketGuild); if (guild is null) { return; } if (guild.Admin.Rulebox.Enabled) { await Rulebox.OnReactionRemoved(before, channel, reaction); } if (reaction.Message.IsSpecified && reaction.Message.Value != null) { await Users.CheckReputationRemoved(reaction.Message.Value, reaction); } }; bot.MessageReceived += async(SocketMessage message) => { var textChannel = (message as SocketMessage)?.Channel as SocketTextChannel; if (textChannel is null) { return; } var socketGuild = textChannel.Guild; var guild = await Guilds.GetAsync(socketGuild); if (guild is null) { return; } await Auto.ValidateMessage(message); await services.GetRequiredService <CommandHandler>().HandleCommandAsync(message); await Users.GetAsync(message.Author); }; bot.MessageUpdated += async(Cacheable <IMessage, ulong> before, SocketMessage message, ISocketMessageChannel channel) => { var socketGuildUser = before.Value?.Author as SocketGuildUser; if (socketGuildUser is null) { return; } var guild = await Guilds.GetAsync(socketGuildUser.Guild); if (guild is null) { return; } if (guild.Moderation.StaffLogs.Enabled) { await Auto.ValidateMessage(message); } }; bot.MessagesBulkDeleted += async(IReadOnlyCollection <Cacheable <IMessage, ulong> > messages, ISocketMessageChannel channel) => { var socketGuild = (channel as SocketTextChannel)?.Guild; if (socketGuild is null) { return; } var guild = await Guilds.GetAsync(socketGuild); if (guild is null) { return; } if (guild.Moderation.StaffLogs.Enabled && ShouldLog(LogEvent.MessageBulkDeleted, guild)) { await StaffLogs.LogBulkMessageDeletion(messages, channel); } }; bot.MessageDeleted += async(Cacheable <IMessage, ulong> message, ISocketMessageChannel channel) => { var socketGuild = (message.Value?.Author as SocketGuildUser)?.Guild; if (socketGuild is null) { return; } var guild = await Guilds.GetAsync(socketGuild); if (guild is null) { return; } if (guild.Moderation.StaffLogs.Enabled && ShouldLog(LogEvent.MessageDeleted, guild)) { await StaffLogs.LogMessageDeletion(message, channel); } }; }