2022-01-16 17:37:07 +00:00
|
|
|
|
import {SlashCommandBuilder} from "@discordjs/builders";
|
|
|
|
|
import {CommandInteraction} from "discord.js";
|
2021-04-13 12:38:52 +00:00
|
|
|
|
import {NamedCommand, RestCommand} from "onion-lasers";
|
2021-03-31 01:40:29 +00:00
|
|
|
|
const letters: {[letter: string]: string[]} = {
|
|
|
|
|
a: "aáàảãạâấầẩẫậăắằẳẵặ".split(""),
|
|
|
|
|
e: "eéèẻẽẹêếềểễệ".split(""),
|
|
|
|
|
i: "iíìỉĩị".split(""),
|
|
|
|
|
o: "oóòỏõọôốồổỗộơớờởỡợ".split(""),
|
|
|
|
|
u: "uúùủũụưứừửữự".split(""),
|
|
|
|
|
y: "yýỳỷỹỵ".split(""),
|
|
|
|
|
d: "dđ".split("")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function transform(str: string) {
|
|
|
|
|
let out = "";
|
|
|
|
|
|
|
|
|
|
for (const c of str) {
|
|
|
|
|
const token = c.toLowerCase();
|
|
|
|
|
const isUpperCase = token !== c;
|
|
|
|
|
|
|
|
|
|
if (token in letters) {
|
|
|
|
|
const set = letters[token];
|
|
|
|
|
const add = set[Math.floor(Math.random() * set.length)];
|
|
|
|
|
out += isUpperCase ? add.toUpperCase() : add;
|
|
|
|
|
} else {
|
|
|
|
|
out += c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-16 17:37:07 +00:00
|
|
|
|
export const header = new SlashCommandBuilder()
|
|
|
|
|
.setDescription("Transforms your text into vietnamese.")
|
|
|
|
|
.addStringOption((option) =>
|
|
|
|
|
option.setName("text").setDescription("The text you want to transform").setRequired(true)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export async function handler(interaction: CommandInteraction) {
|
|
|
|
|
const {options} = interaction;
|
|
|
|
|
const response = options.getString("text", true);
|
2021-03-31 01:40:29 +00:00
|
|
|
|
|
2022-01-16 17:37:07 +00:00
|
|
|
|
interaction.reply(transform(response));
|
|
|
|
|
// You might notice the remove message code is missing here. It's because reactions collectors are
|
|
|
|
|
//not a thing in interactions. The best alternative would be buttons
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let phrase = "I have no currently set phrase!";
|
2021-04-05 12:21:27 +00:00
|
|
|
|
export default new NamedCommand({
|
2021-03-31 01:40:29 +00:00
|
|
|
|
description: "Transforms your text into vietnamese.",
|
2021-04-12 07:44:23 +00:00
|
|
|
|
usage: "([text])",
|
2021-04-11 09:11:21 +00:00
|
|
|
|
async run({send, author}) {
|
2021-04-10 13:34:55 +00:00
|
|
|
|
const msg = await send(transform(phrase));
|
2021-10-29 12:52:46 +00:00
|
|
|
|
msg.createReactionCollector({
|
|
|
|
|
filter: (reaction, user) => {
|
2021-04-08 11:37:49 +00:00
|
|
|
|
if (user.id === author.id && reaction.emoji.name === "❌") msg.delete();
|
|
|
|
|
return false;
|
|
|
|
|
},
|
2021-10-29 12:52:46 +00:00
|
|
|
|
time: 60000
|
|
|
|
|
});
|
2021-04-10 19:08:36 +00:00
|
|
|
|
},
|
|
|
|
|
any: new RestCommand({
|
2021-04-11 09:11:21 +00:00
|
|
|
|
async run({send, author, combined}) {
|
2021-04-12 07:44:23 +00:00
|
|
|
|
phrase = combined;
|
|
|
|
|
const msg = await send(transform(phrase));
|
2021-10-29 12:52:46 +00:00
|
|
|
|
msg.createReactionCollector({
|
|
|
|
|
filter: (reaction, user) => {
|
2021-04-10 19:08:36 +00:00
|
|
|
|
if (user.id === author.id && reaction.emoji.name === "❌") msg.delete();
|
|
|
|
|
return false;
|
|
|
|
|
},
|
2021-10-29 12:52:46 +00:00
|
|
|
|
time: 60000
|
|
|
|
|
});
|
2021-04-10 19:08:36 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
2021-03-31 01:40:29 +00:00
|
|
|
|
});
|