Fix that lol
This commit is contained in:
parent
49357220de
commit
b52bb1139b
39
index.js
39
index.js
|
@ -31,13 +31,13 @@ const commands = [
|
||||||
{
|
{
|
||||||
name: "number",
|
name: "number",
|
||||||
description: "The number to look up (11 digit US only!)",
|
description: "The number to look up (11 digit US only!)",
|
||||||
type: 4,
|
type: Discord.ApplicationCommandOptionType.String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "show",
|
name: "show",
|
||||||
description: "Whether to show the response to everyone or not.",
|
description: "Whether to show the response to everyone or not.",
|
||||||
type: 5
|
type: Discord.ApplicationCommandOptionType.Boolean,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -50,19 +50,19 @@ const commands = [
|
||||||
{
|
{
|
||||||
name: "did",
|
name: "did",
|
||||||
description: "The number to look up (11 digit US only!)",
|
description: "The number to look up (11 digit US only!)",
|
||||||
type: 4,
|
type: Discord.ApplicationCommandOptionType.String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ani",
|
name: "ani",
|
||||||
description: "The ANI to use for the lookup. i.e the caller's number (for routing info) (11 digit US only!)",
|
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
|
required: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "show",
|
name: "show",
|
||||||
description: "Whether to show the response to everyone or not.",
|
description: "Whether to show the response to everyone or not.",
|
||||||
type: 5,
|
type: Discord.ApplicationCommandOptionType.Boolean,
|
||||||
required: false
|
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) => {
|
Client.on("interactionCreate", async (interaction) => {
|
||||||
switch (interaction.type) {
|
switch (interaction.type) {
|
||||||
case Discord.InteractionType.ApplicationCommand:
|
case Discord.InteractionType.ApplicationCommand:
|
||||||
|
@ -89,7 +112,7 @@ Client.on("interactionCreate", async (interaction) => {
|
||||||
case "cid":
|
case "cid":
|
||||||
let show = !interaction.options.getBoolean("show");
|
let show = !interaction.options.getBoolean("show");
|
||||||
if (show == null) show = true;
|
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 (!/^\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}`)) {
|
if (await db.exists(`/cache/${number}`)) {
|
||||||
cached = await db.getData(`/cache/${number}`);
|
cached = await db.getData(`/cache/${number}`);
|
||||||
|
@ -119,9 +142,9 @@ Client.on("interactionCreate", async (interaction) => {
|
||||||
case "lrn":
|
case "lrn":
|
||||||
let showLrn = !interaction.options.getBoolean("show");
|
let showLrn = !interaction.options.getBoolean("show");
|
||||||
if (showLrn == null) showLrn = true;
|
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)" });
|
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)) {
|
if (ani && !/^\d{11}$/.test(ani)) {
|
||||||
return interaction.reply({ ephemeral: true, content: "<:invalid:1305271064993071185> That's not a valid ANI! (11 digit US only)" });
|
return interaction.reply({ ephemeral: true, content: "<:invalid:1305271064993071185> That's not a valid ANI! (11 digit US only)" });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue