toowake

AUDIT LOG (UPDATED!).js

Aug 15th, 2023
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const path = require('path');
  3. //AUDIT LOG
  4. const Audit_Log = require("./Schemas.js/auditlog");
  5. client.on('guildBanAdd', async (guild, user) => {
  6.     const auditLogs = await guild.fetchAuditLogs({ type: 'MEMBER_BAN_ADD', limit: 1 });
  7.     const banLog = auditLogs.entries.first();
  8.     const executor = banLog.executor;
  9.     const reason = banLog.reason || 'No reason given';
  10.     const timestamp = banLog.createdAt;
  11.     const data = await Audit_Log.findOne({
  12.         Guild: guild.id
  13.     })
  14.     let logID;
  15.     if (data) {
  16.         logID = data.Channel
  17.     } else {
  18.         return;
  19.     }
  20.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  21.     const auditChannel = client.channels.cache.get(logID);
  22.     auditEmbed
  23.     .setTitle('Ban added')
  24.     .addFields(
  25.         {name: "Banned Member:", value: `Name: ${user.tag}\nID: ${user.id}`, inline: false},
  26.         {name: "Executor:", value: `${executor.tag}\nID: ${executor.id}`, inline: false},
  27.         {name: "Time:", value: timestamp, inline: false},
  28.         {name: "Reason:", value: reason, inline: false}
  29.     )
  30.     await auditChannel.send({ embeds: [auditEmbed] });
  31. });
  32.  
  33. client.on('guildBanRemove', async (guild, user) => {
  34.     const auditLogs = await guild.fetchAuditLogs({ type: 'MEMBER_BAN_REMOVE', limit: 1 });
  35.     const unbanLog = auditLogs.entries.first();
  36.     const executor = unbanLog.executor;
  37.     const timestamp = unbanLog.createdAt;
  38.     const data = await Audit_Log.findOne({
  39.         Guild: guild.id
  40.     })
  41.     let logID;
  42.     if (data) {
  43.         logID = data.Channel
  44.     } else {
  45.         return;
  46.     }
  47.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  48.     const auditChannel = client.channels.cache.get(logID);
  49.     auditEmbed
  50.     .setTitle('Ban removed')
  51.     .setDescription(`Name: ${user.tag}\nID: ${user.id}`)
  52.     .addFields(
  53.         {name: "Banned Member:", value: `${user.tag}\nID: ${user.id}`, inline: false},
  54.         {name: "Executor:", value: `${executor.tag}\nID: ${executor.id}`, inline: false},
  55.         {name: "Time:", value: `${timestamp}`}
  56.     )
  57.     await auditChannel.send({ embeds: [auditEmbed] });
  58. });
  59. client.on(Events.ChannelCreate, async (channel) => {
  60.     const data = await Audit_Log.findOne({
  61.         Guild: channel.guild.id
  62.     })
  63.     let logID;
  64.     if (data) {
  65.         logID = data.Channel
  66.     } else {
  67.         return;
  68.     }
  69.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  70.     const auditChannel = client.channels.cache.get(logID);
  71.     auditEmbed.setTitle("Channel Created").addFields(
  72.         {name: "Channel Name:", value: channel.name, inline: false},
  73.         {name: "Channel ID:", value: channel.id, inline: false}
  74.     )
  75.     await auditChannel.send({ embeds: [auditEmbed]});
  76. })
  77. client.on(Events.ChannelDelete, async (channel) => {
  78.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  79.     const data = await Audit_Log.findOne({
  80.         Guild: channel.guild.id,
  81.     })
  82.     let logID;
  83.     if (data) {
  84.         logID = data.Channel
  85.     } else {
  86.         return;
  87.     }
  88.     const auditChannel = client.channels.cache.get(logID);
  89.     auditEmbed.setTitle("Channel Deleted").addFields(
  90.         {name: "Channel Name:", value: channel.name, inline: false},
  91.         {name: "Channel ID:", value: channel.id, inline: false}
  92.     )
  93.     await auditChannel.send({ embeds: [auditEmbed]});
  94. })
  95. client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
  96.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  97.     const data = await Audit_Log.findOne({
  98.         Guild: oldChannel.guild.id,
  99.     })
  100.     let logID;
  101.     if (data) {
  102.         logID = data.Channel
  103.     } else {
  104.         return;
  105.     }
  106.     const auditChannel = client.channels.cache.get(logID);
  107.     const changes = [];
  108.     if (oldChannel.name !== newChannel.name) {
  109.         changes.push(`Name: \`${oldChannel.name}\` → \`${newChannel.name}\``);
  110.       }
  111.       if (oldChannel.topic !== newChannel.topic) {
  112.         changes.push(`Topic: \`${oldChannel.topic || 'None'}\` → \`${newChannel.topic || 'None'}\``);
  113.       }
  114.       if (changes.length === 0) return;
  115.       const changesText = changes.join('\n');
  116.     auditEmbed.setTitle("Channel Updated").addFields({ name: "Changes:", value: changesText})
  117.     await auditChannel.send({ embeds: [auditEmbed]});
  118. })
  119. client.on(Events.GuildRoleCreate, async (role) => {
  120.     const data = await Audit_Log.findOne({
  121.         Guild: role.guild.id
  122.     })
  123.     let logID;
  124.     if (data) {
  125.         logID = data.Channel
  126.     } else {
  127.         return;
  128.     }
  129.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  130.     const auditChannel = client.channels.cache.get(logID);
  131.     auditEmbed.setTitle("Role Created").addFields(
  132.         {name: "Role Name:", value: role.name, inline: false},
  133.         {name: "Role ID:", value: role.id, inline: false}
  134.     )
  135.     await auditChannel.send({ embeds: [auditEmbed]});
  136. })
  137. client.on(Events.GuildRoleDelete, async (role) => {
  138.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  139.     const data = await Audit_Log.findOne({
  140.         Guild: role.guild.id,
  141.     })
  142.     let logID;
  143.     if (data) {
  144.         logID = data.Channel
  145.     } else {
  146.         return;
  147.     }
  148.     const auditChannel = client.channels.cache.get(logID);
  149.     auditEmbed.setTitle("Role Removed").addFields(
  150.         {name: "Role Name:", value: role.name, inline: false},
  151.         {name: "Role ID:", value: role.id, inline: false}
  152.     )
  153.     await auditChannel.send({ embeds: [auditEmbed]});
  154. })
  155. client.on(Events.MessageDelete, async (message) => {
  156.     const data = await Audit_Log.findOne({
  157.         Guild: message.guild.id,
  158.     })
  159.     let logID;
  160.     if (data) {
  161.         logID = data.Channel
  162.     } else {
  163.         return;
  164.     }
  165.     try {
  166.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  167.     const auditChannel = client.channels.cache.get(logID);
  168.     auditEmbed.setTitle("Message Deleted").addFields(
  169.         {name: "Author:", value: `${message.author}`, inline: false},
  170.         {name: "Message:", value: `${message.content}`, inline: false},
  171.         {name: "Message ID:", value: `${message.id}`}
  172.     )
  173.     await auditChannel.send({ embeds: [auditEmbed]});
  174.     } catch (err) {
  175.         return;
  176.     }
  177. })
  178. client.on(Events.AutoModerationRuleCreate, async (autoModerationRule) => {
  179.     const data = await Audit_Log.findOne({
  180.         Guild: autoModerationRule.guild.id,
  181.     })
  182.     let logID;
  183.     if (data) {
  184.         logID = data.Channel
  185.     } else {
  186.         return;
  187.     }
  188.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  189.     const auditChannel = client.channels.cache.get(logID);
  190.     auditEmbed.setTitle("Automod Rule Created").addFields(
  191.         {name: "Rulecreator:", value: `<@${autoModerationRule.creatorId}>`, inline: false},
  192.         {name: "Rulename:", value: autoModerationRule.name},
  193.         {name: "Actions:", value: `${autoModerationRule.actions}`, inline: false},
  194.     )
  195.     await auditChannel.send({ embeds: [auditEmbed]});
  196. })
  197. client.on(Events.AutoModerationRuleDelete, async (autoModerationRule) => {
  198.     const data = await Audit_Log.findOne({
  199.         Guild: autoModerationRule.guild.id,
  200.     })
  201.     let logID;
  202.     if (data) {
  203.         logID = data.Channel
  204.     } else {
  205.         return;
  206.     }
  207.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  208.     const auditChannel = client.channels.cache.get(logID);
  209.     auditEmbed.setTitle("Automod Rule Created").addFields(
  210.         {name: "Rulecreator:", value: `<@${autoModerationRule.creatorId}>`, inline: false},
  211.         {name: "Rulename:", value: autoModerationRule.name},
  212.         {name: "Actions:", value: `${autoModerationRule.actions}`, inline: false},
  213.     )
  214.     await auditChannel.send({ embeds: [auditEmbed]});
  215. })
  216. client.on(Events.AutoModerationRuleUpdate, async (newAutoModerationRule, oldAutoModerationRule) => {
  217.     const data = await Audit_Log.findOne({
  218.         Guild: newAutoModerationRule.guild.id,
  219.     })
  220.     let logID;
  221.     if (data) {
  222.         logID = data.Channel
  223.     } else {
  224.         return;
  225.     }
  226.     const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  227.     const auditChannel = client.channels.cache.get(logID);
  228.     auditEmbed.setTitle("Automod Rule Updated").addFields(
  229.         {name: "Old Rulename:", value: `${oldAutoModerationRule.name}`, inline: false},
  230.         {name: "Old Actions:", value: `${oldAutoModerationRule.actions}`, inline: false},
  231.         {name: "New Rulename:", value: newAutoModerationRule.name, inline: false},
  232.         {name: "New Actions:", value: newAutoModerationRule.actions}
  233.     )
  234.     await auditChannel.send({ embeds: [auditEmbed]});
  235. })
  236. client.on(Events.ThreadCreate, async (thread) => {
  237.   const data = await Audit_Log.findOne({
  238.       Guild: thread.guild.id,
  239.   })
  240.   let logID;
  241.   if (data) {
  242.       logID = data.Channel
  243.   } else {
  244.       return;
  245.   }
  246.   const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  247.   const auditChannel = client.channels.cache.get(logID);
  248.   auditEmbed.setTitle("Thread Created").addFields(
  249.       {name: "Name:", value: thread.name, inline: false},
  250.       {name: "Tag:", value: `<#${thread.id}>`, inline: false},
  251.       {name: "ID:", value: thread.id, inline: false},
  252.   )
  253.   await auditChannel.send({ embeds: [auditEmbed]});
  254. })
  255. client.on(Events.ThreadDelete, async (thread) => {
  256.   const data = await Audit_Log.findOne({
  257.       Guild: thread.guild.id,
  258.   })
  259.   let logID;
  260.   if (data) {
  261.       logID = data.Channel
  262.   } else {
  263.       return;
  264.   }
  265.   const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  266.   const auditChannel = client.channels.cache.get(logID);
  267.  
  268.   auditEmbed.setTitle("Thread Deleted").addFields(
  269.       {name: "Name:", value: thread.name, inline: false},
  270.       {name: "Tag:", value: `<#${thread.id}>`, inline: false},
  271.       {name: "ID:", value: thread.id, inline: false},
  272.   )
  273.   await auditChannel.send({ embeds: [auditEmbed]});
  274. })
  275. client.on(Events.InviteCreate, async (invite) => {
  276.  
  277.   const data = await Audit_Log.findOne({
  278.       Guild: invite.guild.id,
  279.   })
  280.   let logID;
  281.   if (data) {
  282.       logID = data.Channel
  283.   } else {
  284.       return;
  285.   }
  286.   const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  287.   const auditChannel = client.channels.cache.get(logID);
  288.  
  289.   auditEmbed.setTitle("Invite Created").addFields(
  290.       {name: "User:", value: `<@${invite.inviterId}>`, inline: false},
  291.       {name: "Invite Code:", value: `${invite.code}`, inline: false},
  292.       {name: "Expires at:", value: `${invite.expiresAt}`, inline: false},
  293.       {name: "Created at:", value: `${invite.createdAt}`, inline: false},
  294.       {name: "Channel:", value: `<#${invite.channelId}>`, inline: false},
  295.       {name: "Max Uses:", value: `${invite.maxUses}`, inline: false},
  296.       {name: "URL", value: `${invite.url}`}
  297.   )
  298.   await auditChannel.send({ embeds: [auditEmbed]});
  299. })
  300. client.on(Events.InviteDelete, async (invite) => {
  301.  
  302.   const data = await Audit_Log.findOne({
  303.       Guild: invite.guild.id
  304.   })
  305.   let logID;
  306.   if (data) {
  307.       logID = data.Channel
  308.   } else {
  309.       return;
  310.   }
  311.   const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  312.   const auditChannel = client.channels.cache.get(logID);
  313.  
  314.   auditEmbed.setTitle("Invite Deleted").addFields(
  315.       {name: "User:", value: `<@${invite.inviter.id}>`, inline: false},
  316.       {name: "Invite Code:", value: `${invite.code}`, inline: false},
  317.       {name: "Expires at:", value: `${invite.expiresAt}`, inline: false},
  318.       {name: "Created at:", value: `${invite.createdAt}`, inline: false},
  319.       {name: "Channel:", value: `<#${invite.channelId}>`, inline: false},
  320.       {name: "Max Uses:", value: `${invite.maxUses}`, inline: false},
  321.       {name: "URL", value: `${invite.url}`}
  322.   )
  323.   await auditChannel.send({ embeds: [auditEmbed]});
  324. })
  325. client.on(Events.MessageBulkDelete, async (messages) => {
  326.   const firstMessage = messages.first();
  327.   const channel = firstMessage.channel;
  328.   const guildId = channel.guild.id;
  329.   const data = await Audit_Log.findOne({
  330.     Guild: guildId
  331.   })
  332.   let logID;
  333.   if (data) {
  334.       logID = data.Channel
  335.   } else {
  336.       return;
  337.   }
  338.   const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  339.   const auditChannel = client.channels.cache.get(logID);
  340.  
  341.   const htmlContent = generateHtmlTranscript(messages, channel, guildId);
  342.  
  343.   const transcriptFilePath = path.join(__dirname, 'transcripts', `transcript_${Date.now()}.html`);
  344.   fs.writeFileSync(transcriptFilePath, htmlContent);
  345.  
  346.   function generateHtmlTranscript(messages, channel, guildId) {
  347.       let html = `
  348.           <!DOCTYPE html>
  349.           <html>
  350.           <head>
  351.               <meta charset="UTF-8">
  352.               <title>Bulk Delete</title>
  353.           </head>
  354.           <body>
  355.               <h1>Transscript - Deleted Messages</h1>
  356.               <p>Kanal: ${channel.name} (ID: ${channel.id})</p>
  357.               <p>Server ID: ${guildId}</p>
  358.               <p>Anzahl der gelöschten Nachrichten: ${messages.size}</p>
  359.               <ul>
  360.       `;
  361.  
  362.       messages.forEach(message => {
  363.           const content = message.content || '[Picture/File]';
  364.           html += `<li><strong>${message.author.tag}</strong>: ${content}</li>`;
  365.       });
  366.  
  367.       html += `
  368.               </ul>
  369.           </body>
  370.           </html>
  371.       `;
  372.  
  373.       return html;
  374.   }
  375.  
  376.   auditEmbed.setTitle("Messae Bulk Delete").addFields(
  377.       {name: "Messages Deleted:", value: `${messages.size}`, inline: false},
  378.       {name: "Channel:", value: `${messages.channel}`, inline: false},
  379.   )
  380.   await auditChannel.send({
  381.     embeds: [auditEmbed],
  382.     files: [transcriptFilePath],});
  383. })
  384. /*const { id, channel_id, guild_id, author, timestamp, type } = data;*/
  385. client.on(Events.MessageUpdate, async (oldMessage, newMessage) => {
  386.  
  387.   const data = await Audit_Log.findOne({
  388.       Guild: oldMessage.guild.id
  389.   })
  390.   let logID;
  391.   if (data) {
  392.       logID = data.Channel
  393.   } else {
  394.       return;
  395.   }
  396.   const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
  397.   const auditChannel = client.channels.cache.get(logID);
  398.  
  399.   auditEmbed.setTitle("Message Edited")
  400.   .addFields({ name: 'Author:', value: `${newMessage.author.tag}`, inline: false})
  401.   .addFields({ name: 'Channel:', value: `${newMessage.channel}`, inline: false})
  402.   .addFields({ name: 'Old Message:', value: `${oldMessage.content}`, inline: false})
  403.   .addFields({ name: 'New Message:', value: `${newMessage.content}`, inline: false})
  404.  
  405.   await auditChannel.send({ embeds: [auditEmbed]});
  406. })
  407. client.on(Events.GuildMemberAdd, async (member) => {
  408.  
  409. })
  410. client.on(Events.GuildMemberRemove, async (member) => {
  411.    
  412. })
Advertisement
Add Comment
Please, Sign In to add comment