utility.guildinfo: fix widget invite lookup

This commit is contained in:
Cynthia Foxwell 2024-05-17 20:28:23 -06:00
parent 14b526ca55
commit 6e68754ecb

View file

@ -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`
);
}