utility: add interaction commands for jumbo, charinfo, appinfo, guildinfo

This commit is contained in:
Cynthia Foxwell 2024-05-18 23:09:28 -06:00
parent 80833c60a2
commit cfd6664ea8
2 changed files with 115 additions and 9 deletions

View File

@ -46,7 +46,7 @@ async function runCommand(interaction, command) {
async function InteractionDispatcher(interaction) {
const command = hf.interactionCommands.get(interaction.data.name);
const shouldSend = getOption(interaction, command, "send");
await interaction.acknowledge(shouldSend ? 0 : MessageFlags.EPHEMERAL);
const ack = interaction.acknowledge(shouldSend ? 0 : MessageFlags.EPHEMERAL);
try {
const response = await runCommand(interaction, command);
@ -93,6 +93,7 @@ async function InteractionDispatcher(interaction) {
}
try {
await ack;
await interaction.createMessage(
Object.assign(
typeof response === "string" ? {content: response} : response,
@ -105,6 +106,7 @@ async function InteractionDispatcher(interaction) {
)
);
} catch (err) {
await ack;
await interaction.createMessage({
content: `:warning: An error has occurred:\n\`\`\`${err}\`\`\``,
flags: MessageFlags.EPHEMERAL,
@ -115,6 +117,7 @@ async function InteractionDispatcher(interaction) {
}
}
} catch (err) {
await ack;
await interaction.createMessage({
content: `:warning: An error has occurred:\n\`\`\`${err}\`\`\``,
flags: MessageFlags.EPHEMERAL,

View File

@ -1,4 +1,5 @@
const Command = require("../lib/command.js");
const InteractionCommand = require("../lib/interactionCommand.js");
const CATEGORY = "utility";
// {{{ imports
@ -7,6 +8,7 @@ const sharp = require("sharp");
const {Constants, VoiceChannel} = require("@projectdysnomia/dysnomia");
const Endpoints = require("@projectdysnomia/dysnomia/lib/rest/Endpoints.js");
const {getOption} = require("../lib/interactionDispatcher.js");
const {
formatTime,
hastebin,
@ -368,12 +370,13 @@ const EMOJI_SETS = {
suffix: ".svg",
},
noto: {
prefix: "https://gitcdn.xyz/repo/googlefonts/noto-emoji/master/svg/emoji_u",
prefix:
"https://cdn.jsdelivr.net/gh/googlefonts/noto-emoji@master/svg/emoji_u",
sep: "_",
suffix: ".svg",
},
twemoji: {
prefix: "https://twemoji.maxcdn.com/v/latest/svg/",
prefix: "https://jdecked.github.io/twemoji/v/latest/svg/",
sep: "-",
suffix: ".svg",
},
@ -383,7 +386,7 @@ const EMOJI_SETS = {
sep: "-",
suffix: ".svg",
},
apple: {
/*apple: {
prefix: "https://intrnl.github.io/assetsEmoji/AppleColor/emoji_u",
sep: "_",
suffix: ".png",
@ -392,14 +395,14 @@ const EMOJI_SETS = {
prefix: "https://intrnl.github.io/assetsEmoji/facebook/emoji_u",
sep: "_",
suffix: ".png",
},
},*/
};
EMOJI_SETS["noto-old"] = EMOJI_SETS.blobs;
EMOJI_SETS.mutant = EMOJI_SETS.mustd;
EMOJI_SETS.mutstd = EMOJI_SETS.mustd;
EMOJI_SETS.ms = EMOJI_SETS.mustd;
//EMOJI_SETS.ms = EMOJI_SETS.mustd;
EMOJI_SETS.twitter = EMOJI_SETS.twemoji;
EMOJI_SETS.fb = EMOJI_SETS.facebook;
//EMOJI_SETS.fb = EMOJI_SETS.facebook;
// }}}
@ -1205,6 +1208,48 @@ jumbo.callback = async function (msg, line) {
};
hf.registerCommand(jumbo);
const jumboInteraction = new InteractionCommand("jumbo");
jumboInteraction.helpText = "Gets the raw image of an emoji.";
jumboInteraction.options.content = {
name: "content",
type: Constants.ApplicationCommandOptionTypes.STRING,
description: "Emoji to get image of",
required: true,
default: "",
};
jumboInteraction.options.set = {
name: "set",
type: Constants.ApplicationCommandOptionTypes.STRING,
description: "Emoji set for non-custom emoji",
required: false,
choices: [
{
name: "Twemoji (Twitter/Discord)",
value: "twemoji",
},
{
name: "Noto (Google)",
value: "noto",
},
{
name: "Noto Old (Blobs)",
value: "blobs",
},
{
name: "Mutant Standard",
value: "mustd",
},
],
default: "twemoji",
};
jumboInteraction.callback = async function (interaction) {
const content = getOption(interaction, jumboInteraction, "content");
const set = getOption(interaction, jumboInteraction, "set");
return jumbo.callback(interaction, `--${set} ${content}`);
};
hf.registerCommand(jumboInteraction);
const charinfo = new Command("charinfo");
charinfo.category = CATEGORY;
charinfo.helpText = "Get information about a set of characters.";
@ -1216,7 +1261,16 @@ charinfo.callback = async function (msg, line) {
const lines = names
.map(
([code, name], index) =>
`\`\\u${code}\`: ${name} - ${chars[index]} - <http://www.fileformat.info/info/unicode/char/${code}>`
`[\`\\u${code}${
chars[index].legnth > 1
? ` (${chars[index]
.split("")
.map((c) => `\\u${c.codePointAt().toString(16)}`)
.join("")})`
: ""
}\`](<http://www.fileformat.info/info/unicode/char/${code}>): ${name} - ${
chars[index]
}`
)
.join("\n");
@ -1228,6 +1282,22 @@ charinfo.callback = async function (msg, line) {
};
hf.registerCommand(charinfo);
const charinfoInteraction = new InteractionCommand("charinfo");
charinfoInteraction.helpText = "Get information about a set of characters.";
charinfoInteraction.options.content = {
name: "content",
type: Constants.ApplicationCommandOptionTypes.STRING,
description: "Characters to get info for",
required: true,
default: "",
};
charinfoInteraction.callback = async function (interaction) {
const content = getOption(interaction, charinfoInteraction, "content");
return charinfo.callback(interaction, content);
};
hf.registerCommand(charinfoInteraction);
const presence = new Command("presence");
presence.category = CATEGORY;
presence.helpText = "Get presences of a user.";
@ -1879,6 +1949,22 @@ appinfo.callback = async function (msg, line) {
};
hf.registerCommand(appinfo);
const appinfoInteraction = new InteractionCommand("appinfo");
appinfoInteraction.helpText = "Get information on an application";
appinfoInteraction.options.id = {
name: "id",
type: Constants.ApplicationCommandOptionTypes.STRING,
description: "Application ID to get info for",
required: true,
default: "",
};
appinfoInteraction.callback = async function (interaction) {
const id = getOption(interaction, appinfoInteraction, "id");
return appinfo.callback(interaction, id);
};
hf.registerCommand(appinfoInteraction);
const guildinfo = new Command("guildinfo");
guildinfo.category = CATEGORY;
guildinfo.helpText = "Get information on a guild";
@ -1894,7 +1980,8 @@ guildinfo.callback = async function (msg, line) {
let _guild, clanEmbed;
if (!line || line == "") {
if (!msg.guildID) return "Not in a guild.";
_guild = {source: "local", data: msg.channel.guild};
const __guild = msg.channel.guild ?? hf.bot.guilds.get(msg.guildID);
if (__guild) _guild = {source: "local", data: __guild};
} else {
if (!SNOWFLAKE_REGEX.test(line)) return "Not a snowflake.";
const snowflake = line.match(SNOWFLAKE_REGEX)[1];
@ -2599,4 +2686,20 @@ guildinfo.callback = async function (msg, line) {
};
hf.registerCommand(guildinfo);
const guildinfoInteraction = new InteractionCommand("guildinfo");
guildinfoInteraction.helpText = "Get information on an guild";
guildinfoInteraction.options.id = {
name: "id",
type: Constants.ApplicationCommandOptionTypes.STRING,
description: "Guild ID to get info for",
required: false,
default: "",
};
guildinfoInteraction.callback = async function (interaction) {
const id = getOption(interaction, guildinfoInteraction, "id");
return guildinfo.callback(interaction, id);
};
hf.registerCommand(guildinfoInteraction);
// }}}