private string TestStaffLogs(string details, GuildUser user) { Punishment createPunishment(PunishmentType punishment) => new Punishment(punishment, "Test", Context.User, DateTime.Now, DateTime.Now); details += "`Staff Logs`\n"; details += Test("Log ban, successful", StaffLogs.LogBan(Context.User, Context.Guild, createPunishment(PunishmentType.Ban))); details += Test("Log unban, successful", StaffLogs.LogUnban(Context.User, Context.Guild)); details += Test("Log mute, successful", StaffLogs.LogMute(user, createPunishment(PunishmentType.Mute))); details += Test("Log unmute, successful", StaffLogs.LogUnmute(user, createPunishment(PunishmentType.Mute))); details += Test("Log kick, successful", StaffLogs.LogKick(Context.User as SocketGuildUser, createPunishment(PunishmentType.Kick))); details += Test("Log messages deleted, null message, successful", StaffLogs.LogMessageDeletion(default, Context.Channel));
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); } }; }