logging: more cleanup, kick and ban events
This commit is contained in:
		
							parent
							
								
									ae53e37204
								
							
						
					
					
						commit
						0ea9264ae3
					
				
					 1 changed files with 221 additions and 58 deletions
				
			
		| 
						 | 
					@ -81,6 +81,9 @@ const WHITELISTED_EVENTS = new Set([
 | 
				
			||||||
  "GUILD_PROFILE_UPDATE",
 | 
					  "GUILD_PROFILE_UPDATE",
 | 
				
			||||||
]);
 | 
					]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const cacheBanTimeout = {};
 | 
				
			||||||
 | 
					const leaveTimeout = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
					events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
  const channel = await getLoggingChannel(entry.guild);
 | 
					  const channel = await getLoggingChannel(entry.guild);
 | 
				
			||||||
  if (!channel) return;
 | 
					  if (!channel) return;
 | 
				
			||||||
| 
						 | 
					@ -94,9 +97,6 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
      case AuditLogActions.CHANNEL_OVERWRITE_CREATE:
 | 
					      case AuditLogActions.CHANNEL_OVERWRITE_CREATE:
 | 
				
			||||||
      case AuditLogActions.CHANNEL_OVERWRITE_UPDATE:
 | 
					      case AuditLogActions.CHANNEL_OVERWRITE_UPDATE:
 | 
				
			||||||
      case AuditLogActions.CHANNEL_OVERWRITE_DELETE:
 | 
					      case AuditLogActions.CHANNEL_OVERWRITE_DELETE:
 | 
				
			||||||
      case AuditLogActions.MEMBER_KICK:
 | 
					 | 
				
			||||||
      case AuditLogActions.MEMBER_BAN_ADD:
 | 
					 | 
				
			||||||
      case AuditLogActions.MEMBER_BAN_REMOVE:
 | 
					 | 
				
			||||||
      case AuditLogActions.BOT_ADD:
 | 
					      case AuditLogActions.BOT_ADD:
 | 
				
			||||||
      case AuditLogActions.ROLE_CREATE:
 | 
					      case AuditLogActions.ROLE_CREATE:
 | 
				
			||||||
      case AuditLogActions.ROLE_UPDATE:
 | 
					      case AuditLogActions.ROLE_UPDATE:
 | 
				
			||||||
| 
						 | 
					@ -185,7 +185,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
              footer: {
 | 
					              footer: {
 | 
				
			||||||
                text: `Channel ID: ${entry.targetID}`,
 | 
					                text: `Channel ID: ${entry.targetID}`,
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              timestamp: new Date().toISOString(),
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
          ],
 | 
					          ],
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
| 
						 | 
					@ -297,7 +297,8 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
          embeds: [
 | 
					          embeds: [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
              color: COLOR_CHANGED,
 | 
					              color: COLOR_CHANGED,
 | 
				
			||||||
              title: `Server updated`,
 | 
					              title: `Server Updated`,
 | 
				
			||||||
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
              fields,
 | 
					              fields,
 | 
				
			||||||
              thumbnail:
 | 
					              thumbnail:
 | 
				
			||||||
                thumbnail != null
 | 
					                thumbnail != null
 | 
				
			||||||
| 
						 | 
					@ -311,10 +312,6 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
                      url: image,
 | 
					                      url: image,
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                  : null,
 | 
					                  : null,
 | 
				
			||||||
              footer: {
 | 
					 | 
				
			||||||
                text: `Guild ID: ${entry.targetID}`,
 | 
					 | 
				
			||||||
              },
 | 
					 | 
				
			||||||
              timestamp: new Date().toISOString(),
 | 
					 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
          ],
 | 
					          ],
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
| 
						 | 
					@ -340,6 +337,22 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
                value: formatChange(oldVisibility, newVisibility),
 | 
					                value: formatChange(oldVisibility, newVisibility),
 | 
				
			||||||
                inline: true,
 | 
					                inline: true,
 | 
				
			||||||
              });
 | 
					              });
 | 
				
			||||||
 | 
					              break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            case "server_tag": {
 | 
				
			||||||
 | 
					              fields.push({
 | 
				
			||||||
 | 
					                name: "Server Tag",
 | 
				
			||||||
 | 
					                value: formatChange(oldValue, newValue),
 | 
				
			||||||
 | 
					                inline: true,
 | 
				
			||||||
 | 
					              });
 | 
				
			||||||
 | 
					              break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            default: {
 | 
				
			||||||
 | 
					              fields.push({
 | 
				
			||||||
 | 
					                name: `\`${key}\``,
 | 
				
			||||||
 | 
					                value: formatChange(oldValue, newValue),
 | 
				
			||||||
 | 
					                inline: true,
 | 
				
			||||||
 | 
					              });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -361,11 +374,8 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
              color: COLOR_CHANGED,
 | 
					              color: COLOR_CHANGED,
 | 
				
			||||||
              title: `Server Profile Updated`,
 | 
					              title: `Server Profile Updated`,
 | 
				
			||||||
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
              fields,
 | 
					              fields,
 | 
				
			||||||
              footer: {
 | 
					 | 
				
			||||||
                text: `Guild ID: ${entry.targetID}`,
 | 
					 | 
				
			||||||
              },
 | 
					 | 
				
			||||||
              timestamp: new Date().toISOString(),
 | 
					 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
          ],
 | 
					          ],
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
| 
						 | 
					@ -420,11 +430,11 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
                  ? "themselves"
 | 
					                  ? "themselves"
 | 
				
			||||||
                  : `member <@${entry.targetID}> (${formatUsername(target)})`
 | 
					                  : `member <@${entry.targetID}> (${formatUsername(target)})`
 | 
				
			||||||
              }`,
 | 
					              }`,
 | 
				
			||||||
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
              fields,
 | 
					              fields,
 | 
				
			||||||
              footer: {
 | 
					              footer: {
 | 
				
			||||||
                text: `User ID: ${entry.targetID}`,
 | 
					                text: `User ID: ${entry.targetID}`,
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              timestamp: new Date().toISOString(),
 | 
					 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
          ],
 | 
					          ],
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
| 
						 | 
					@ -453,7 +463,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
              } ${roles.length > 1 ? `${roles.length} ` : ""}role${plural} ${added ? "to" : "from"} ${
 | 
					              } ${roles.length > 1 ? `${roles.length} ` : ""}role${plural} ${added ? "to" : "from"} ${
 | 
				
			||||||
                isSelf ? "self" : `<@${entry.targetID}> (${formatUsername(entry.target.user)})`
 | 
					                isSelf ? "self" : `<@${entry.targetID}> (${formatUsername(entry.target.user)})`
 | 
				
			||||||
              }`,
 | 
					              }`,
 | 
				
			||||||
              timestamp: new Date().toISOString(),
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
              fields: [
 | 
					              fields: [
 | 
				
			||||||
                !addAndRemove && {
 | 
					                !addAndRemove && {
 | 
				
			||||||
                  name: `Role${plural}`,
 | 
					                  name: `Role${plural}`,
 | 
				
			||||||
| 
						 | 
					@ -493,6 +503,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
              )}) created webhook \`${after.name.replaceAll("`", "\u02cb")}\` in <#${entry.after.channel_id}> (${
 | 
					              )}) created webhook \`${after.name.replaceAll("`", "\u02cb")}\` in <#${entry.after.channel_id}> (${
 | 
				
			||||||
                entry.guild.channels.get(after.channel_id)?.name ?? "<uncached>"
 | 
					                entry.guild.channels.get(after.channel_id)?.name ?? "<uncached>"
 | 
				
			||||||
              })`,
 | 
					              })`,
 | 
				
			||||||
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
              fields: [
 | 
					              fields: [
 | 
				
			||||||
                after.application_id != null && {
 | 
					                after.application_id != null && {
 | 
				
			||||||
                  name: "Application ID",
 | 
					                  name: "Application ID",
 | 
				
			||||||
| 
						 | 
					@ -525,7 +536,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
              color: COLOR_ADDED,
 | 
					              color: COLOR_ADDED,
 | 
				
			||||||
              title: `${after.invitable != null ? "Private " : ""}Thread Created`,
 | 
					              title: `${after.invitable != null ? "Private " : ""}Thread Created`,
 | 
				
			||||||
              description: `<#${entry.targetID}> (${after.name})`,
 | 
					              description: `<#${entry.targetID}> (${after.name})`,
 | 
				
			||||||
              timestamp: new Date().toISOString(),
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
              fields: [
 | 
					              fields: [
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                  name: "Created by",
 | 
					                  name: "Created by",
 | 
				
			||||||
| 
						 | 
					@ -616,7 +627,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
              description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${verb} <#${entry.targetID}>${
 | 
					              description: `<@${entry.user.id}> (${formatUsername(entry.user)}) ${verb} <#${entry.targetID}>${
 | 
				
			||||||
                entry.target?.name != null ? ` (${entry.target.name})` : ""
 | 
					                entry.target?.name != null ? ` (${entry.target.name})` : ""
 | 
				
			||||||
              }`,
 | 
					              }`,
 | 
				
			||||||
              timestamp: new Date().toISOString(),
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
              fields: [
 | 
					              fields: [
 | 
				
			||||||
                after.name != null && {
 | 
					                after.name != null && {
 | 
				
			||||||
                  name: "Name",
 | 
					                  name: "Name",
 | 
				
			||||||
| 
						 | 
					@ -663,7 +674,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
              color: COLOR_REMOVED,
 | 
					              color: COLOR_REMOVED,
 | 
				
			||||||
              title: `${entry.before.invitable != null ? "Private " : ""}Thread Deleted`,
 | 
					              title: `${entry.before.invitable != null ? "Private " : ""}Thread Deleted`,
 | 
				
			||||||
              description: `<#${entry.targetID}> (${entry.before.name})`,
 | 
					              description: `<#${entry.targetID}> (${entry.before.name})`,
 | 
				
			||||||
              timestamp: new Date().toISOString(),
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
              fields: [
 | 
					              fields: [
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                  name: "Deleted by",
 | 
					                  name: "Deleted by",
 | 
				
			||||||
| 
						 | 
					@ -690,6 +701,150 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      case AuditLogActions.MEMBER_KICK: {
 | 
				
			||||||
 | 
					        const leaveData = leaveTimeout[entry.guild.id];
 | 
				
			||||||
 | 
					        let member;
 | 
				
			||||||
 | 
					        if (leaveData.user === entry.targetID) {
 | 
				
			||||||
 | 
					          clearTimeout(leaveData.timeout);
 | 
				
			||||||
 | 
					          member = leaveData.member;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(entry.targetID), true);
 | 
				
			||||||
 | 
					        const defaultAvatar = getDefaultAvatar(user.id, user.discriminator ?? 0);
 | 
				
			||||||
 | 
					        const avatar = user.avatar ? CDNEndpoints.USER_AVATAR(user.id, user.avatar) : defaultAvatar;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        channel.createMessage({
 | 
				
			||||||
 | 
					          embeds: [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              color: COLOR_REMOVED,
 | 
				
			||||||
 | 
					              title: "User Kicked",
 | 
				
			||||||
 | 
					              description: `<@${entry.user.id}> (${formatUsername(entry.user)}) kicked <@${user.id}> (${formatUsername(
 | 
				
			||||||
 | 
					                user
 | 
				
			||||||
 | 
					              )})`,
 | 
				
			||||||
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
 | 
					              fields: [
 | 
				
			||||||
 | 
					                member?.joinedAt && {
 | 
				
			||||||
 | 
					                  name: "Joined",
 | 
				
			||||||
 | 
					                  value: `<t:${Math.floor(member.joinedAt / 1000)}:R>`,
 | 
				
			||||||
 | 
					                  inline: true,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                member?.nick && {
 | 
				
			||||||
 | 
					                  name: "Nickname",
 | 
				
			||||||
 | 
					                  value: member.nick,
 | 
				
			||||||
 | 
					                  inline: true,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                entry.integrationType != null && {
 | 
				
			||||||
 | 
					                  name: "Integration Type",
 | 
				
			||||||
 | 
					                  value: `\`${entry.integrationType}\``,
 | 
				
			||||||
 | 
					                  inline: true,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                member?.roles?.length > 0 && {
 | 
				
			||||||
 | 
					                  name: "Roles",
 | 
				
			||||||
 | 
					                  value: member.roles
 | 
				
			||||||
 | 
					                    .sort((a, b) => entry.guild.roles.get(b).position - entry.guild.roles.get(a).position)
 | 
				
			||||||
 | 
					                    .map((role) => `<@&${role}>`)
 | 
				
			||||||
 | 
					                    .join(", "),
 | 
				
			||||||
 | 
					                  inline: false,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                entry.reason != null && {
 | 
				
			||||||
 | 
					                  name: "Reason",
 | 
				
			||||||
 | 
					                  value: `\`${entry.reason.replaceAll("`", "\u02cb")}\``,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					              ].filter((x) => !!x),
 | 
				
			||||||
 | 
					              footer: {
 | 
				
			||||||
 | 
					                text: `User ID: ${entry.targetID}`,
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					              thumbnail: {
 | 
				
			||||||
 | 
					                url: avatar,
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          ],
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      case AuditLogActions.MEMBER_BAN_ADD: {
 | 
				
			||||||
 | 
					        const callback = async () => {
 | 
				
			||||||
 | 
					          const user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(entry.targetID), true);
 | 
				
			||||||
 | 
					          const defaultAvatar = getDefaultAvatar(user.id, user.discriminator ?? 0);
 | 
				
			||||||
 | 
					          const avatar = user.avatar ? CDNEndpoints.USER_AVATAR(user.id, user.avatar) : defaultAvatar;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          channel.createMessage({
 | 
				
			||||||
 | 
					            embeds: [
 | 
				
			||||||
 | 
					              {
 | 
				
			||||||
 | 
					                color: COLOR_REMOVED,
 | 
				
			||||||
 | 
					                title: "User Banned",
 | 
				
			||||||
 | 
					                description: `<@${entry.user.id}> (${formatUsername(entry.user)}) banned <@${
 | 
				
			||||||
 | 
					                  user.id
 | 
				
			||||||
 | 
					                }> (${formatUsername(user)})`,
 | 
				
			||||||
 | 
					                timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
 | 
					                fields: [
 | 
				
			||||||
 | 
					                  entry.reason != null && {
 | 
				
			||||||
 | 
					                    name: "Reason",
 | 
				
			||||||
 | 
					                    value: `\`${entry.reason.replaceAll("`", "\u02cb")}\``,
 | 
				
			||||||
 | 
					                  },
 | 
				
			||||||
 | 
					                ].filter((x) => !!x),
 | 
				
			||||||
 | 
					                footer: {
 | 
				
			||||||
 | 
					                  text: `User ID: ${entry.targetID}`,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                thumbnail: {
 | 
				
			||||||
 | 
					                  url: avatar,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (entry.user.bot) {
 | 
				
			||||||
 | 
					          cacheBanTimeout[entry.guild.id] = {
 | 
				
			||||||
 | 
					            user: entry.user.id,
 | 
				
			||||||
 | 
					            timeout: setTimeout(callback, 1500),
 | 
				
			||||||
 | 
					          };
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          await callback();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      case AuditLogActions.MEMBER_BAN_REMOVE: {
 | 
				
			||||||
 | 
					        const cacheBan = cacheBanTimeout[entry.guild.id];
 | 
				
			||||||
 | 
					        if (cacheBan?.user === entry.user.id) {
 | 
				
			||||||
 | 
					          clearTimeout(cacheBan.timeout);
 | 
				
			||||||
 | 
					          delete cacheBanTimeout[entry.guild.id];
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(entry.targetID), true);
 | 
				
			||||||
 | 
					        const defaultAvatar = getDefaultAvatar(user.id, user.discriminator ?? 0);
 | 
				
			||||||
 | 
					        const avatar = user.avatar ? CDNEndpoints.USER_AVATAR(user.id, user.avatar) : defaultAvatar;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        channel.createMessage({
 | 
				
			||||||
 | 
					          embeds: [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              color: COLOR_ADDED,
 | 
				
			||||||
 | 
					              title: "User Unbanned",
 | 
				
			||||||
 | 
					              description: `<@${entry.user.id}> (${formatUsername(entry.user)}) unbanned <@${
 | 
				
			||||||
 | 
					                user.id
 | 
				
			||||||
 | 
					              }> (${formatUsername(user)})`,
 | 
				
			||||||
 | 
					              timestamp: new Date(snowflakeToTimestamp(entry.id)).toISOString(),
 | 
				
			||||||
 | 
					              fields: [
 | 
				
			||||||
 | 
					                entry.reason != null && {
 | 
				
			||||||
 | 
					                  name: "Reason",
 | 
				
			||||||
 | 
					                  value: `\`${entry.reason.replaceAll("`", "\u02cb")}\``,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					              ].filter((x) => !!x),
 | 
				
			||||||
 | 
					              footer: {
 | 
				
			||||||
 | 
					                text: `User ID: ${entry.targetID}`,
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					              thumbnail: {
 | 
				
			||||||
 | 
					                url: avatar,
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          ],
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } catch (err) {
 | 
					  } catch (err) {
 | 
				
			||||||
    const eventName = Object.entries(AuditLogActions).find(([name, val]) => val === entry.actionType)[0];
 | 
					    const eventName = Object.entries(AuditLogActions).find(([name, val]) => val === entry.actionType)[0];
 | 
				
			||||||
| 
						 | 
					@ -823,48 +978,56 @@ events.add("guildMemberRemove", "logging", async function (guild, member) {
 | 
				
			||||||
  const timestamp = new Date().toISOString();
 | 
					  const timestamp = new Date().toISOString();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (member instanceof Member) {
 | 
					  if (member instanceof Member) {
 | 
				
			||||||
    const user = member.user;
 | 
					    const callback = async () => {
 | 
				
			||||||
    const defaultAvatar = getDefaultAvatar(user.id, user.discriminator ?? 0);
 | 
					      const user = member.user;
 | 
				
			||||||
    const avatar = user.avatar ? CDNEndpoints.USER_AVATAR(user.id, user.avatar) : defaultAvatar;
 | 
					      const defaultAvatar = getDefaultAvatar(user.id, user.discriminator ?? 0);
 | 
				
			||||||
 | 
					      const avatar = user.avatar ? CDNEndpoints.USER_AVATAR(user.id, user.avatar) : defaultAvatar;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    channel
 | 
					      channel
 | 
				
			||||||
      .createMessage({
 | 
					        .createMessage({
 | 
				
			||||||
        embeds: [
 | 
					          embeds: [
 | 
				
			||||||
          {
 | 
					            {
 | 
				
			||||||
            color: COLOR_REMOVED,
 | 
					              color: COLOR_REMOVED,
 | 
				
			||||||
            title: "Member Left",
 | 
					              title: "Member Left",
 | 
				
			||||||
            description: `<@${user.id}> (${formatUsername(user)})`,
 | 
					              description: `<@${user.id}> (${formatUsername(user)})`,
 | 
				
			||||||
            timestamp,
 | 
					              timestamp,
 | 
				
			||||||
            thumbnail: {
 | 
					              thumbnail: {
 | 
				
			||||||
              url: avatar,
 | 
					                url: avatar,
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					              fields: [
 | 
				
			||||||
 | 
					                member?.joinedAt && {
 | 
				
			||||||
 | 
					                  name: "Joined",
 | 
				
			||||||
 | 
					                  value: `<t:${Math.floor(member.joinedAt / 1000)}:R>`,
 | 
				
			||||||
 | 
					                  inline: true,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                member?.nick && {
 | 
				
			||||||
 | 
					                  name: "Nickname",
 | 
				
			||||||
 | 
					                  value: member.nick,
 | 
				
			||||||
 | 
					                  inline: true,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                member?.roles?.length > 0 && {
 | 
				
			||||||
 | 
					                  name: "Roles",
 | 
				
			||||||
 | 
					                  value: member.roles
 | 
				
			||||||
 | 
					                    .sort((a, b) => guild.roles.get(b).position - guild.roles.get(a).position)
 | 
				
			||||||
 | 
					                    .map((role) => `<@&${role}>`)
 | 
				
			||||||
 | 
					                    .join(", "),
 | 
				
			||||||
 | 
					                  inline: false,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					              ].filter((x) => !!x),
 | 
				
			||||||
 | 
					              footer: {
 | 
				
			||||||
 | 
					                text: `User ID: ${user.id}`,
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            fields: [
 | 
					          ],
 | 
				
			||||||
              {
 | 
					        })
 | 
				
			||||||
                name: "Joined",
 | 
					        .catch(() => {});
 | 
				
			||||||
                value: `<t:${Math.floor(member.joinedAt / 1000)}:R>`,
 | 
					    };
 | 
				
			||||||
                inline: true,
 | 
					
 | 
				
			||||||
              },
 | 
					    leaveTimeout[guild.id] = {
 | 
				
			||||||
              member?.nick && {
 | 
					      user: member.user.id,
 | 
				
			||||||
                name: "Nickname",
 | 
					      member,
 | 
				
			||||||
                value: member.nick,
 | 
					      timeout: setTimeout(callback, 2000),
 | 
				
			||||||
                inline: true,
 | 
					    };
 | 
				
			||||||
              },
 | 
					 | 
				
			||||||
              member?.roles?.length > 0 && {
 | 
					 | 
				
			||||||
                name: "Roles",
 | 
					 | 
				
			||||||
                value: member.roles
 | 
					 | 
				
			||||||
                  .sort((a, b) => guild.roles.get(b).position - guild.roles.get(a).position)
 | 
					 | 
				
			||||||
                  .map((role) => `<@&${role}>`)
 | 
					 | 
				
			||||||
                  .join(", "),
 | 
					 | 
				
			||||||
                inline: false,
 | 
					 | 
				
			||||||
              },
 | 
					 | 
				
			||||||
            ].filter((x) => !!x),
 | 
					 | 
				
			||||||
            footer: {
 | 
					 | 
				
			||||||
              text: `User ID: ${user.id}`,
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
        ],
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
      .catch(() => {});
 | 
					 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    const user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(member.user.id), true);
 | 
					    const user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(member.user.id), true);
 | 
				
			||||||
    const defaultAvatar = getDefaultAvatar(user.id, user.discriminator ?? 0);
 | 
					    const defaultAvatar = getDefaultAvatar(user.id, user.discriminator ?? 0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue