public static async Task GuildMemberRemoved(GuildMemberRemoveEventArgs e, DiscordClient client) { var log = await client.Guilds.FirstOrDefault().Value.GetAuditLogsAsync(1, null); AuditLogActionType actionType = log.FirstOrDefault().ActionType; switch (actionType) { case AuditLogActionType.Ban: { await client.SendMessageAsync(e.Guild.Channels.Where(x => x.Name == "general").FirstOrDefault(), e.Member.Username + " kapott egy banhammert!", false); break; } case AuditLogActionType.Kick: { await client.SendMessageAsync(e.Guild.Channels.Where(x => x.Name == "general").FirstOrDefault(), e.Member.Username + " ki lett rúgva innen!", false); break; } } DiscordMessage msg = await client.SendMessageAsync(e.Guild.Channels.Where(x => x.Name == "general").FirstOrDefault(), e.Member.Username + ", bukás!", false); }
public static async Task <DiscordAuditLogEntry> GetLatestAuditLogEntryAsync(this DiscordGuild guild, AuditLogActionType type) { try { var entry = (await guild.GetAuditLogsAsync(1, action_type: type))?.FirstOrDefault(); if (entry is null || DateTime.UtcNow - entry.CreationTimestamp.ToUniversalTime() > TimeSpan.FromSeconds(5)) { return(null); } return(entry); } catch { // swallow } return(null); }
private async Task UpdateAuditLogs(AuditLogActionType type, DiscordGuild guild) { DiscordAuditLogEntry entryLatest = (await guild.GetAuditLogsAsync(limit: 1, action_type: type))[0]; DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); DiscordUser responsible = entryLatest.UserResponsible; builder.WithAuthor(responsible.Username, null, responsible.AvatarUrl); switch (entryLatest.ActionCategory) { case AuditLogActionCategory.Create: builder.Color = DiscordColor.Green; break; case AuditLogActionCategory.Update: builder.Color = DiscordColor.Yellow; break; case AuditLogActionCategory.Delete: builder.Color = DiscordColor.Red; break; case AuditLogActionCategory.Other: builder.Color = DiscordColor.White; break; default: break; } switch (entryLatest.ActionType) { case AuditLogActionType.GuildUpdate: builder.WithTitle("Guild updated"); break; case AuditLogActionType.ChannelCreate: builder.WithTitle("Channel created"); break; case AuditLogActionType.ChannelUpdate: builder.WithTitle("Channel updated"); break; case AuditLogActionType.ChannelDelete: builder.WithTitle("Channel deleted"); break; case AuditLogActionType.OverwriteCreate: builder.WithTitle("Permission override for channel created"); break; case AuditLogActionType.OverwriteUpdate: builder.WithTitle("Permission override for channel updated"); break; case AuditLogActionType.OverwriteDelete: builder.WithTitle("Permission override for channel deleted"); break; case AuditLogActionType.Kick: builder.WithTitle("User kicked"); break; case AuditLogActionType.Prune: builder.WithTitle("Users pruned"); break; case AuditLogActionType.Ban: builder.WithTitle("User banned"); break; case AuditLogActionType.Unban: builder.WithTitle("User unbanned"); break; case AuditLogActionType.MemberUpdate: builder.WithTitle("Member updated"); break; case AuditLogActionType.MemberRoleUpdate: builder.WithTitle("Member role updated"); break; case AuditLogActionType.RoleCreate: builder.WithTitle("Role created"); break; case AuditLogActionType.RoleUpdate: builder.WithTitle("Role updated"); break; case AuditLogActionType.RoleDelete: builder.WithTitle("Role deleted"); break; case AuditLogActionType.InviteCreate: builder.WithTitle("Invite created"); break; case AuditLogActionType.InviteUpdate: builder.WithTitle("Invite updated"); break; case AuditLogActionType.InviteDelete: builder.WithTitle("Invite deleted"); break; case AuditLogActionType.WebhookCreate: builder.WithTitle("Webhook created"); break; case AuditLogActionType.WebhookUpdate: builder.WithTitle("Webhook updated"); break; case AuditLogActionType.WebhookDelete: builder.WithTitle("Webhook deleted"); break; case AuditLogActionType.EmojiCreate: builder.WithTitle("Emoji created"); break; case AuditLogActionType.EmojiUpdate: builder.WithTitle("Emoji updated"); break; case AuditLogActionType.EmojiDelete: builder.WithTitle("Emoji deleted"); break; case AuditLogActionType.MessageDelete: builder.WithTitle("Message deleted (See logs channel for more info)"); break; default: builder.WithTitle("Unknown event"); break; } Type entryType = entryLatest.GetType(); PropertyInfo[] properties = entryType.GetProperties(); foreach (PropertyInfo prop in properties) { if (typeof(PropertyChange <>).IsAssignableFrom(prop.PropertyType)) { Type changeType = prop.PropertyType.GetGenericArguments()[0]; } else { } } }
public AuditLogAction(AuditLogActionType type, string guildId, string targetid, Dictionary <string, AuditLogUser> users, Dictionary <string, Webhook> webhooks, Change[] changes, Options options, string banreason) { switch (type) { case AuditLogActionType.ChannelCreate: { SubactionFromChanges(changes, ref SubAction, options, users, guildId); Glyph = ""; Color = "online"; Text = App.GetString("/Dialogs/AuditLogChannelCreate").ReplaceChannel(guildId, targetid); break; } case AuditLogActionType.ChannelUpdate: { Glyph = ""; Color = "idle"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); if (LocalState.Guilds[guildId].channels.ContainsKey(targetid)) { Text = App.GetString("/Dialogs/AuditLogChannelUpdateValid").ReplaceChannel(guildId, targetid); } else { Text = App.GetString("/Dialogs/AuditLogChannelUpdateInvalid").TryReplace("<channelid>", targetid); } break; } case AuditLogActionType.ChannelDelete: { Glyph = ""; Color = "dnd"; Text = App.GetString("/Dialogs/AuditLogChannelDelete").TryReplace("<channel>", GetValue(changes, "name", ValueType.OldValue)?.ToString().Bold()); break; } case AuditLogActionType.ChannelOverwriteCreate: { Glyph = ""; Color = "online"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); if (LocalState.Guilds[guildId].channels.ContainsKey(targetid)) { Text = App.GetString("/Dialogs/AuditLogChannelPermissionCreateValid").ReplaceChannel(guildId, targetid); } else { Text = App.GetString("/Dialogs/AuditLogChannelPermissionCreateInvalid"); } break; } case AuditLogActionType.ChannelOverwriteUpdate: { Glyph = ""; Color = "idle"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); if (LocalState.Guilds[guildId].channels.ContainsKey(targetid)) { Text = App.GetString("/Dialogs/AuditLogChannelPermissionUpdateValid").ReplaceChannel(guildId, targetid); } else { Text = App.GetString("/Dialogs/AuditLogChannelPermissionUpdateInvalid"); } break; } case AuditLogActionType.ChannelOverwriteDelete: { Glyph = ""; Color = "dnd"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); if (LocalState.Guilds[guildId].channels.ContainsKey(targetid)) { Text = App.GetString("/Dialogs/AuditLogChannelPermissionRemoveValid").ReplaceChannel(guildId, targetid); } else { Text = App.GetString("/Dialogs/AuditLogChannelPermissionRemoveInvalid"); } break; } case AuditLogActionType.EmojiCreate: { Glyph = ""; Color = "online"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogEmojiCreate").TryReplace("<emojiname>", GetValue(changes, "name", ValueType.NewValue)?.ToString()); break; } case AuditLogActionType.EmojiUpdate: { Glyph = ""; Color = "idle"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogEmojiUpdate").TryReplace("<emojiname>", GetValue(changes, "name", ValueType.NewValue)?.ToString()); break; } case AuditLogActionType.EmojiDelete: { Glyph = ""; Color = "dnd"; Text = App.GetString("/Dialogs/AuditLogEmojiDelete").TryReplace("<emojiname>", GetValue(changes, "name", ValueType.OldValue)?.ToString()); break; } case AuditLogActionType.GuildUpdate: { Glyph = ""; Color = "idle"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogGuildUpdate"); break; } case AuditLogActionType.InviteCreate: { Glyph = ""; Color = "online"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogInviteCreate").TryReplace("<code>", GetValue(changes, "code", ValueType.NewValue)?.ToString().Bold()); break; } case AuditLogActionType.InviteUpdate: { Glyph = ""; Color = "idle"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogInviteUpdate").TryReplace("<code>", GetValue(changes, "code", ValueType.NewValue)?.ToString().Bold()); break; } case AuditLogActionType.InviteDelete: { Glyph = ""; Color = "dnd"; Text = App.GetString("/Dialogs/AuditLogInviteDelete").TryReplace("<code>", GetValue(changes, "code", ValueType.OldValue)?.ToString().Bold()); break; } case AuditLogActionType.MemberBanAdd: { Glyph = ""; Color = "dnd"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); if (!string.IsNullOrWhiteSpace(banreason)) { SubAction.Add(App.GetString("/Dialogs/AuditLogBanReason").TryReplace("<reason>", "**" + banreason + "**")); } Text = App.GetString("/Dialogs/AuditLogMemberBanAdd").TryReplace("<banneduser>", "<@" + targetid + ">"); break; } case AuditLogActionType.MemberBanRemove: { Glyph = ""; Color = "online"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogMemberBanRemove").TryReplace("<banneduser>", "<@" + targetid + ">"); break; } case AuditLogActionType.MemberKick: { Glyph = ""; Color = "idle"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogMemberKick").TryReplace("<kickeduser>", "<@" + targetid + ">"); break; } case AuditLogActionType.MemberPrune: { Glyph = ""; Color = "dnd"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogMemberPrune"); break; } case AuditLogActionType.MemberRoleUpdate: { Glyph = ""; Color = "idle"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogMemberRoleUpdate").TryReplace("<user2>", "<@" + targetid + ">"); break; } case AuditLogActionType.MemberUpdate: { Glyph = ""; Color = "idle"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogMemberUpdate").TryReplace("<user2>", "<@" + targetid + ">"); break; } case AuditLogActionType.MessageDelete: { Glyph = ""; Color = "dnd"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); if (!options.Count.HasValue || options.Count == 1) { Text = App.GetString("/Dialogs/AuditLogMessageDelete").TryReplace("<user2>", "<@" + targetid + ">").ReplaceChannel(guildId, options.ChannelId); } else { Text = App.GetString("/Dialogs/AuditLogMessageDeletePlural").TryReplace("<user2>", "<@" + targetid + ">").ReplaceChannel(guildId, options.ChannelId).TryReplace("<x>", options.Count.ToString().Bold()); } break; } case AuditLogActionType.RoleCreate: { Glyph = ""; Color = "online"; string rolename = ""; SubactionFromChanges(changes, ref SubAction, options, users, guildId); if (LocalState.Guilds[guildId].roles.ContainsKey(targetid)) { rolename = "<@&" + targetid + ">"; } else { object val = GetValue(changes, "name", ValueType.NewValue); if (val != null) { rolename = val.ToString().Bold(); } else { rolename = "<deleted role>"; } } Text = App.GetString("/Dialogs/AuditLogRoleCreate").TryReplace("<role>", rolename); break; } case AuditLogActionType.RoleUpdate: { Glyph = ""; Color = "idle"; string rolename = ""; SubactionFromChanges(changes, ref SubAction, options, users, guildId); if (LocalState.Guilds[guildId].roles.ContainsKey(targetid)) { rolename = "<@&" + targetid + ">"; } else { object val = GetValue(changes, "name", ValueType.NewValue); if (val != null) { rolename = val.ToString().Bold(); } else { rolename = "<deleted role>"; } } Text = App.GetString("/Dialogs/AuditLogRoleUpdate").TryReplace("<role>", rolename); break; } case AuditLogActionType.RoleDelete: { Glyph = ""; Color = "dnd"; Text = App.GetString("/Dialogs/AuditLogRoleDelete").TryReplace("<role>", GetValue(changes, "name", ValueType.OldValue)?.ToString().Bold()); break; } case AuditLogActionType.WebhookCreate: { Glyph = ""; Color = "online"; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogWebhookCreate").TryReplace("<webhook>", GetValue(changes, "name", ValueType.NewValue)?.ToString().Bold()); break; } case AuditLogActionType.WebhookUpdate: { Glyph = ""; Color = "idle"; var webhookname = ""; SubactionFromChanges(changes, ref SubAction, options, users, guildId); foreach (var webhook in webhooks) { if (webhook.Key == targetid) { webhookname = webhook.Value.Name; } } Text = App.GetString("/Dialogs/AuditLogWebhookUpdate").TryReplace("<webhook>", webhookname.Bold()); break; } case AuditLogActionType.WebhookDelete: { Glyph = ""; Color = "dnd"; Text = App.GetString("/Dialogs/AuditLogWebhookDelete").TryReplace("<webhook>", GetValue(changes, "name", ValueType.OldValue)?.ToString().Bold()); break; } default: { Glyph = ""; SubactionFromChanges(changes, ref SubAction, options, users, guildId); Text = App.GetString("/Dialogs/AuditLogUnknown"); break; } } }