utility: fix up command missing empty arg checks and add reply support to charinfo

This commit is contained in:
Cynthia Foxwell 2024-05-21 11:39:19 -06:00
parent f2b7c49baf
commit b087833972

View file

@ -6,7 +6,6 @@ const CATEGORY = "utility";
const sharp = require("sharp"); const sharp = require("sharp");
const {Constants, VoiceChannel} = require("@projectdysnomia/dysnomia"); const {Constants, VoiceChannel} = require("@projectdysnomia/dysnomia");
const Endpoints = require("@projectdysnomia/dysnomia/lib/rest/Endpoints.js");
const {getOption} = require("../lib/interactionDispatcher.js"); const {getOption} = require("../lib/interactionDispatcher.js");
const { const {
@ -578,7 +577,7 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
}; };
} }
} else { } else {
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID); const guild = msg.channel.guild ?? hf.bot.guilds.get(msg.guildID);
const baseEmbed = { const baseEmbed = {
title: `Avatar for \`${formatUsername(msg.author)}\``, title: `Avatar for \`${formatUsername(msg.author)}\``,
@ -785,9 +784,7 @@ lookupinvite.addAlias("inviteinfo");
lookupinvite.addAlias("iinfo"); lookupinvite.addAlias("iinfo");
lookupinvite.addAlias("ii"); lookupinvite.addAlias("ii");
lookupinvite.callback = async function (msg, line) { lookupinvite.callback = async function (msg, line) {
if (!line || line == "") { if (!line || line == "") return "Arguments required.";
return "No arguments passed.";
}
line = line.replace(/(https?:\/\/)?discord(\.gg|(app)?.com\/invite)\//, ""); line = line.replace(/(https?:\/\/)?discord(\.gg|(app)?.com\/invite)\//, "");
@ -1086,6 +1083,8 @@ flagdump.category = CATEGORY;
flagdump.helpText = "Dumps Discord user flags."; flagdump.helpText = "Dumps Discord user flags.";
flagdump.usage = "[flags or user mention]"; flagdump.usage = "[flags or user mention]";
flagdump.callback = async function (msg, line, [numOrMention], {id, list}) { flagdump.callback = async function (msg, line, [numOrMention], {id, list}) {
if (!line || line == "") numOrMention = `<@${msg.author.id}>`;
const num = Number(numOrMention); const num = Number(numOrMention);
if (list) { if (list) {
let allFlags = 0n; let allFlags = 0n;
@ -1097,20 +1096,12 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) {
} else if (/<@!?(\d+)>/.test(numOrMention) || !isNaN(id)) { } 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."; if (!targetId) return "Got null ID.";
const guild = msg.channel.guild ?? hf.bot.guilds.get(msg.guildID); let user = hf.bot.users.get(id);
let user = guild && (await guild.fetchMembers({userIDs: [targetId]}));
if (!user || !user[0]) {
user = hf.bot.users.get(id);
} else {
user = user[0].user;
}
if (!user) if (!user)
user = await hf.bot.requestHandler.request( user = await hf.bot.requestHandler
"GET", .request("GET", `/users/${id}`, true)
Endpoints.USER(id), .catch(() => {});
true
);
if (!user) { if (!user) {
return "Failed to get user."; return "Failed to get user.";
@ -1141,6 +1132,8 @@ jumbo.addAlias("e");
jumbo.addAlias("emote"); jumbo.addAlias("emote");
jumbo.addAlias("emoji"); jumbo.addAlias("emoji");
jumbo.callback = async function (msg, line) { jumbo.callback = async function (msg, line) {
if (!line || line === "") return "Arguments required.";
if (CUSTOM_EMOTE_REGEX.test(line)) { if (CUSTOM_EMOTE_REGEX.test(line)) {
const [_, animatedFlag, name, id] = line.match(CUSTOM_EMOTE_REGEX); const [_, animatedFlag, name, id] = line.match(CUSTOM_EMOTE_REGEX);
const animated = animatedFlag === "a"; const animated = animatedFlag === "a";
@ -1272,6 +1265,13 @@ charinfo.helpText = "Get information about a set of characters.";
charinfo.usage = "[characters]"; charinfo.usage = "[characters]";
charinfo.addAlias("char"); charinfo.addAlias("char");
charinfo.callback = async function (msg, line) { charinfo.callback = async function (msg, line) {
if (!line || (line == "" && msg.messageReference?.messageID)) {
const reply = await msg.channel.getMessage(msg.messageReference.messageID);
line = reply.content;
}
if (!line || line == "") return "Arguments required.";
const names = await getNamesFromString(line); const names = await getNamesFromString(line);
const chars = [...line]; const chars = [...line];
const lines = names const lines = names