From 6e68754ecb0407c66c144cc3e5dd3b82778e99ca Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Fri, 17 May 2024 20:28:23 -0600 Subject: [PATCH] utility.guildinfo: fix widget invite lookup --- src/modules/utility.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/modules/utility.js b/src/modules/utility.js index bd629cb..b56fe05 100644 --- a/src/modules/utility.js +++ b/src/modules/utility.js @@ -5,6 +5,7 @@ const CATEGORY = "utility"; const sharp = require("sharp"); const {Constants, VoiceChannel} = require("@projectdysnomia/dysnomia"); +const Endpoints = require("@projectdysnomia/dysnomia/lib/rest/Endpoints.js"); const { formatTime, @@ -764,7 +765,9 @@ lookupinvite.callback = async function (msg, line) { return "No arguments passed."; } - line = line.replace(/(https?:\/\/)?discord\.gg\//, ""); + line = line.replace(/(https?:\/\/)?discord(\.gg|(app)?.com\/invites)\//, ""); + + if (decodeURI(line).indexOf("../") > -1) return "nuh uh"; let bail = false; let error; @@ -1052,9 +1055,9 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) { } return `All flags:\n\`\`\`${flagsFromInt(allFlags, USER_FLAGS)}\`\`\``; } else if (/<@!?(\d+)>/.test(numOrMention) || !isNaN(id)) { - const targetId = id || numOrMention.match(/<@!?(\d+)>/)?.[1]; + const targetId = id ?? numOrMention.match(/<@!?(\d+)>/)?.[1]; if (!targetId) return "Got null ID."; - const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID); + const guild = msg.channel.guild ?? hf.bot.guilds.get(msg.guildID); let user = guild && (await guild.fetchMembers({userIDs: [targetId]})); if (!user || !user[0]) { user = hf.bot.users.get(id); @@ -1062,11 +1065,18 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) { user = user[0].user; } + if (!user) + user = await hf.bot.requestHandler.request( + "GET", + Endpoints.USER(id), + true + ); + if (!user) { - return "User not cached."; + return "Failed to get user."; } else { return `\`${formatUsername(user)}\`'s public flags:\n\`\`\`${flagsFromInt( - user.publicFlags, + user.public_flags ?? user.publicFlags, USER_FLAGS )}\`\`\``; } @@ -2356,7 +2366,10 @@ guildinfo.callback = async function (msg, line) { if (guild.instant_invite) { invite = await hf.bot.requestHandler.request( "GET", - `/invites/${guild.instant_invite}?with_counts=true&with_expiration=true` + `/invites/${guild.instant_invite.replace( + /(https?:\/\/)?discord(\.gg|(app)?.com\/invites)\//, + "" + )}?with_counts=true&with_expiration=true` ); }