utility.lookupinvite: code cleanup
This commit is contained in:
		
							parent
							
								
									1eab6674c0
								
							
						
					
					
						commit
						778f5aeab1
					
				
					 1 changed files with 93 additions and 74 deletions
				
			
		| 
						 | 
				
			
			@ -442,6 +442,15 @@ lookupinvite.callback = async function (msg, line) {
 | 
			
		|||
          : `<t:${Math.floor(new Date(invite.expires_at).getTime() / 1000)}>`,
 | 
			
		||||
      inline: true,
 | 
			
		||||
    };
 | 
			
		||||
    const inviter = {
 | 
			
		||||
      name: "Inviter",
 | 
			
		||||
      value: `**${
 | 
			
		||||
        invite.inviter.discriminator && invite.inviter.discriminator != "0"
 | 
			
		||||
          ? `${invite.inviter.username}#${invite.inviter.discriminator}`
 | 
			
		||||
          : `@${invite.inviter.username}`
 | 
			
		||||
      }** (${invite.inviter.id})`,
 | 
			
		||||
      inline: false,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    if (invite.type == 0) {
 | 
			
		||||
      embed.fields.push(
 | 
			
		||||
| 
						 | 
				
			
			@ -467,6 +476,7 @@ lookupinvite.callback = async function (msg, line) {
 | 
			
		|||
            inline: true,
 | 
			
		||||
          },
 | 
			
		||||
          expires,
 | 
			
		||||
          inviter,
 | 
			
		||||
          invite.guild.welcome_screen && {
 | 
			
		||||
            name: "Welcome Screen",
 | 
			
		||||
            value: `"${
 | 
			
		||||
| 
						 | 
				
			
			@ -509,6 +519,49 @@ lookupinvite.callback = async function (msg, line) {
 | 
			
		|||
              : "png?size=1024"
 | 
			
		||||
          }`,
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      if (
 | 
			
		||||
        invite.guild &&
 | 
			
		||||
        (invite.guild.icon || invite.guild.splash || invite.guild.banner)
 | 
			
		||||
      ) {
 | 
			
		||||
        embed.fields.push({
 | 
			
		||||
          name: "\u200b",
 | 
			
		||||
          value: `${
 | 
			
		||||
            invite.guild.icon
 | 
			
		||||
              ? `[Icon](${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${
 | 
			
		||||
                  invite.guild.icon.startsWith("a_")
 | 
			
		||||
                    ? "gif?size=1024"
 | 
			
		||||
                    : "png?size=1024"
 | 
			
		||||
                })`
 | 
			
		||||
              : ""
 | 
			
		||||
          }${
 | 
			
		||||
            invite.guild.splash
 | 
			
		||||
              ? `${invite.guild.icon ? " | " : ""}[Splash](${SPLASH_BASE}${
 | 
			
		||||
                  invite.guild.id
 | 
			
		||||
                }/${invite.guild.splash}.png?size=2048)`
 | 
			
		||||
              : ""
 | 
			
		||||
          }${
 | 
			
		||||
            invite.guild.banner
 | 
			
		||||
              ? `${
 | 
			
		||||
                  invite.guild.icon || invite.guild.splash ? " | " : ""
 | 
			
		||||
                }[Banner](${BANNER_BASE}${invite.guild.id}/${
 | 
			
		||||
                  invite.guild.banner
 | 
			
		||||
                }.${
 | 
			
		||||
                  invite.guild.banner.startsWith("a_")
 | 
			
		||||
                    ? "gif?size=1024"
 | 
			
		||||
                    : "png?size=1024"
 | 
			
		||||
                })`
 | 
			
		||||
              : ""
 | 
			
		||||
          }`,
 | 
			
		||||
          inline: false,
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (invite.guild?.splash) {
 | 
			
		||||
        embed.image = {
 | 
			
		||||
          url: `${SPLASH_BASE}${invite.guild.id}/${invite.guild.splash}.png?size=256`,
 | 
			
		||||
        };
 | 
			
		||||
      }
 | 
			
		||||
    } else if (invite.type == 1) {
 | 
			
		||||
      embed.title += " (Group DM)";
 | 
			
		||||
      embed.fields.push(
 | 
			
		||||
| 
						 | 
				
			
			@ -527,89 +580,55 @@ lookupinvite.callback = async function (msg, line) {
 | 
			
		|||
          value: `${STATUS_ICONS.offline}${invite.approximate_member_count} members`,
 | 
			
		||||
          inline: true,
 | 
			
		||||
        },
 | 
			
		||||
        expires
 | 
			
		||||
        expires,
 | 
			
		||||
        inviter
 | 
			
		||||
      );
 | 
			
		||||
      embed.thumbnail = {
 | 
			
		||||
        url: invite.channel.icon
 | 
			
		||||
          ? `${CHANNEL_ICON_BASE}${invite.channel.id}/${invite.channel.icon}.${
 | 
			
		||||
              invite.channel.icon.startsWith("a_")
 | 
			
		||||
                ? "gif?size=1024&_=.gif"
 | 
			
		||||
                : "png?size=1024"
 | 
			
		||||
            }`
 | 
			
		||||
          : "https://discord.com" +
 | 
			
		||||
            DEFAULT_GROUP_DM_AVATARS[
 | 
			
		||||
              (Math.floor(Number(invite.channel.id) / Math.pow(2, 22)) +
 | 
			
		||||
                1420070400000) %
 | 
			
		||||
                DEFAULT_GROUP_DM_AVATARS.length
 | 
			
		||||
            ],
 | 
			
		||||
      };
 | 
			
		||||
    } else if (invite.type == 2) {
 | 
			
		||||
      embed.title += " (Friend)";
 | 
			
		||||
      embed.fields.push(expires);
 | 
			
		||||
      embed.thumbnail = {
 | 
			
		||||
        url:
 | 
			
		||||
          invite.inviter?.avatar &&
 | 
			
		||||
          `${AVATAR_BASE}${invite.inviter.id}/${invite.inviter.avatar}.${
 | 
			
		||||
            invite.inviter.avatar.startsWith("a_")
 | 
			
		||||
 | 
			
		||||
      const groupIcon = invite.channel.icon
 | 
			
		||||
        ? `${CHANNEL_ICON_BASE}${invite.channel.id}/${invite.channel.icon}.${
 | 
			
		||||
            invite.channel.icon.startsWith("a_")
 | 
			
		||||
              ? "gif?size=1024&_=.gif"
 | 
			
		||||
              : "png?size=1024"
 | 
			
		||||
          }`,
 | 
			
		||||
          }`
 | 
			
		||||
        : "https://discord.com" +
 | 
			
		||||
          DEFAULT_GROUP_DM_AVATARS[
 | 
			
		||||
            (Math.floor(Number(invite.channel.id) / Math.pow(2, 22)) +
 | 
			
		||||
              1420070400000) %
 | 
			
		||||
              DEFAULT_GROUP_DM_AVATARS.length
 | 
			
		||||
          ];
 | 
			
		||||
 | 
			
		||||
      embed.thumbnail = {
 | 
			
		||||
        url: groupIcon,
 | 
			
		||||
      };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (invite.inviter) {
 | 
			
		||||
      embed.fields.push({
 | 
			
		||||
        name: "Inviter",
 | 
			
		||||
        value: `**${
 | 
			
		||||
          invite.inviter.discriminator && invite.inviter.discriminator != "0"
 | 
			
		||||
            ? `${invite.inviter.username}#${invite.inviter.discriminator}`
 | 
			
		||||
            : `@${invite.inviter.username}`
 | 
			
		||||
        }** (${invite.inviter.id})`,
 | 
			
		||||
        inline: false,
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (
 | 
			
		||||
      invite.guild &&
 | 
			
		||||
      (invite.guild.icon || invite.guild.splash || invite.guild.banner)
 | 
			
		||||
    ) {
 | 
			
		||||
      embed.fields.push({
 | 
			
		||||
        name: "\u200b",
 | 
			
		||||
        value: `${
 | 
			
		||||
          invite.guild.icon
 | 
			
		||||
            ? `[Icon](${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${
 | 
			
		||||
                invite.guild.icon.startsWith("a_")
 | 
			
		||||
                  ? "gif?size=1024"
 | 
			
		||||
                  : "png?size=1024"
 | 
			
		||||
              })`
 | 
			
		||||
            : ""
 | 
			
		||||
        }${
 | 
			
		||||
          invite.guild.splash
 | 
			
		||||
            ? `${invite.guild.icon ? " | " : ""}[Splash](${SPLASH_BASE}${
 | 
			
		||||
                invite.guild.id
 | 
			
		||||
              }/${invite.guild.splash}.png?size=2048)`
 | 
			
		||||
            : ""
 | 
			
		||||
        }${
 | 
			
		||||
          invite.guild.banner
 | 
			
		||||
            ? `${
 | 
			
		||||
                invite.guild.icon || invite.guild.splash ? " | " : ""
 | 
			
		||||
              }[Banner](${BANNER_BASE}${invite.guild.id}/${
 | 
			
		||||
                invite.guild.banner
 | 
			
		||||
              }.${
 | 
			
		||||
                invite.guild.banner.startsWith("a_")
 | 
			
		||||
                  ? "gif?size=1024"
 | 
			
		||||
                  : "png?size=1024"
 | 
			
		||||
              })`
 | 
			
		||||
            : ""
 | 
			
		||||
        }`,
 | 
			
		||||
        value: `[Icon](${groupIcon})`,
 | 
			
		||||
        inline: false,
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
    } else if (invite.type == 2) {
 | 
			
		||||
      embed.title += " (Friend)";
 | 
			
		||||
      embed.fields.push(expires, inviter);
 | 
			
		||||
 | 
			
		||||
    if (invite.guild?.splash) {
 | 
			
		||||
      embed.image = {
 | 
			
		||||
        url: `${SPLASH_BASE}${invite.guild.id}/${invite.guild.splash}.png?size=256`,
 | 
			
		||||
      };
 | 
			
		||||
      const avatarURL =
 | 
			
		||||
        invite.inviter?.avatar &&
 | 
			
		||||
        `${AVATAR_BASE}${invite.inviter.id}/${invite.inviter.avatar}.${
 | 
			
		||||
          invite.inviter.avatar.startsWith("a_")
 | 
			
		||||
            ? "gif?size=1024&_=.gif"
 | 
			
		||||
            : "png?size=1024"
 | 
			
		||||
        }`;
 | 
			
		||||
 | 
			
		||||
      if (avatarURL) {
 | 
			
		||||
        embed.thumbnail = {
 | 
			
		||||
          url: avatarURL,
 | 
			
		||||
        };
 | 
			
		||||
        embed.fields.push({
 | 
			
		||||
          name: "\u200b",
 | 
			
		||||
          value: `[Avatar](${avatarURL})`,
 | 
			
		||||
          inline: false,
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      return `Unhandled invite type: \`${invite.type}\``;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return {embed};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue