Fix that lol

This commit is contained in:
Christopher Cookman 2025-05-28 10:50:22 -06:00
parent 49357220de
commit b52bb1139b

View file

@ -31,13 +31,13 @@ const commands = [
{
name: "number",
description: "The number to look up (11 digit US only!)",
type: 4,
type: Discord.ApplicationCommandOptionType.String,
required: true
},
{
name: "show",
description: "Whether to show the response to everyone or not.",
type: 5
type: Discord.ApplicationCommandOptionType.Boolean,
}
]
},
@ -50,19 +50,19 @@ const commands = [
{
name: "did",
description: "The number to look up (11 digit US only!)",
type: 4,
type: Discord.ApplicationCommandOptionType.String,
required: true
},
{
name: "ani",
description: "The ANI to use for the lookup. i.e the caller's number (for routing info) (11 digit US only!)",
type: 4,
type: Discord.ApplicationCommandOptionType.String,
required: false
},
{
name: "show",
description: "Whether to show the response to everyone or not.",
type: 5,
type: Discord.ApplicationCommandOptionType.Boolean,
required: false
}
]
@ -82,6 +82,29 @@ Client.on("ready", async () => {
})();
})
/**
* Converts a T9-style alphanumeric phone number to its numeric equivalent.
* Example: "1610LITENET" => "16105483638"
* @param {string} input
* @returns {string}
*/
function t9ToNumber(input) {
input = String(input).replace(/[^a-zA-Z0-9]/g, '');
const t9 = {
A: '2', B: '2', C: '2',
D: '3', E: '3', F: '3',
G: '4', H: '4', I: '4',
J: '5', K: '5', L: '5',
M: '6', N: '6', O: '6',
P: '7', Q: '7', R: '7', S: '7',
T: '8', U: '8', V: '8',
W: '9', X: '9', Y: '9', Z: '9'
};
return String(input).toUpperCase().split('').map(c =>
t9[c] || (/\d/.test(c) ? c : '')
).join('');
}
Client.on("interactionCreate", async (interaction) => {
switch (interaction.type) {
case Discord.InteractionType.ApplicationCommand:
@ -89,7 +112,7 @@ Client.on("interactionCreate", async (interaction) => {
case "cid":
let show = !interaction.options.getBoolean("show");
if (show == null) show = true;
let number = interaction.options.getInteger("number")
let number = t9ToNumber(interaction.options.getString("number"))
if (!/^\d{11}$/.test(number)) return interaction.reply({ ephemeral: true, content: "<:invalid:1305271064993071185> That's not a valid number! (11 digit US only)" });
if (await db.exists(`/cache/${number}`)) {
cached = await db.getData(`/cache/${number}`);
@ -119,9 +142,9 @@ Client.on("interactionCreate", async (interaction) => {
case "lrn":
let showLrn = !interaction.options.getBoolean("show");
if (showLrn == null) showLrn = true;
let did = interaction.options.getInteger("did")
let did = t9ToNumber(interaction.options.getString("did"))
if (!/^\d{11}$/.test(did)) return interaction.reply({ ephemeral: true, content: "<:invalid:1305271064993071185> That's not a valid number! (11 digit US only)" });
let ani = interaction.options.getInteger("ani") || null;
let ani = t9ToNumber(interaction.options.getString("ani")) || null;
if (ani && !/^\d{11}$/.test(ani)) {
return interaction.reply({ ephemeral: true, content: "<:invalid:1305271064993071185> That's not a valid ANI! (11 digit US only)" });
}