mirror of
https://github.com/artiemis/artemis.js.git
synced 2026-02-14 10:21:54 +00:00
formatting
This commit is contained in:
parent
0a628b9dd9
commit
433df9364f
4
.prettierrc
Normal file
4
.prettierrc
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"trailingComma": "es5"
|
||||||
|
}
|
||||||
@ -43,7 +43,7 @@ export class ArtemisClient extends Client {
|
|||||||
const rest = new REST().setToken(env.DISCORD_TOKEN);
|
const rest = new REST().setToken(env.DISCORD_TOKEN);
|
||||||
this.api = new API(rest);
|
this.api = new API(rest);
|
||||||
|
|
||||||
this.on("error", (err) => {
|
this.on("error", err => {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -56,15 +56,15 @@ export class ArtemisClient extends Client {
|
|||||||
const commandsDir = path.join(import.meta.dir, "commands");
|
const commandsDir = path.join(import.meta.dir, "commands");
|
||||||
const categories = await fs
|
const categories = await fs
|
||||||
.readdir(commandsDir)
|
.readdir(commandsDir)
|
||||||
.then((categories) =>
|
.then(categories =>
|
||||||
categories.filter((category) => !category.includes("."))
|
categories.filter(category => !category.includes("."))
|
||||||
);
|
);
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
|
|
||||||
for (const category of categories) {
|
for (const category of categories) {
|
||||||
const files = await fs
|
const files = await fs
|
||||||
.readdir(path.join(commandsDir, category))
|
.readdir(path.join(commandsDir, category))
|
||||||
.then((files) => files.filter((file) => file.endsWith(".ts")));
|
.then(files => files.filter(file => file.endsWith(".ts")));
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
promises.push(
|
promises.push(
|
||||||
@ -90,7 +90,7 @@ export class ArtemisClient extends Client {
|
|||||||
const eventsDir = path.join(import.meta.dir, "events");
|
const eventsDir = path.join(import.meta.dir, "events");
|
||||||
const files = await fs
|
const files = await fs
|
||||||
.readdir(eventsDir)
|
.readdir(eventsDir)
|
||||||
.then((files) => files.filter((file) => file !== "index.ts"));
|
.then(files => files.filter(file => file !== "index.ts"));
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const { default: event } = await import(path.join(eventsDir, file));
|
const { default: event } = await import(path.join(eventsDir, file));
|
||||||
@ -107,8 +107,8 @@ export class ArtemisClient extends Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const publicCommands = this.commands
|
const publicCommands = this.commands
|
||||||
.filter((command) => !command.isOwnerOnly)
|
.filter(command => !command.isOwnerOnly)
|
||||||
.map((command) =>
|
.map(command =>
|
||||||
command.data
|
command.data
|
||||||
.setIntegrationTypes(
|
.setIntegrationTypes(
|
||||||
ApplicationIntegrationType.GuildInstall,
|
ApplicationIntegrationType.GuildInstall,
|
||||||
@ -122,8 +122,8 @@ export class ArtemisClient extends Client {
|
|||||||
.toJSON()
|
.toJSON()
|
||||||
);
|
);
|
||||||
const ownerCommands = this.commands
|
const ownerCommands = this.commands
|
||||||
.filter((command) => command.isOwnerOnly)
|
.filter(command => command.isOwnerOnly)
|
||||||
.map((command) =>
|
.map(command =>
|
||||||
command.data
|
command.data
|
||||||
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
||||||
.toJSON()
|
.toJSON()
|
||||||
@ -138,7 +138,7 @@ export class ArtemisClient extends Client {
|
|||||||
...publicCommands,
|
...publicCommands,
|
||||||
...ownerCommands,
|
...ownerCommands,
|
||||||
])
|
])
|
||||||
.then((res) => (guildCount += res.length));
|
.then(res => (guildCount += res.length));
|
||||||
} else {
|
} else {
|
||||||
await this.api.applicationCommands
|
await this.api.applicationCommands
|
||||||
.bulkOverwriteGuildCommands(
|
.bulkOverwriteGuildCommands(
|
||||||
@ -146,10 +146,10 @@ export class ArtemisClient extends Client {
|
|||||||
env.DEV_GUILD_ID,
|
env.DEV_GUILD_ID,
|
||||||
ownerCommands
|
ownerCommands
|
||||||
)
|
)
|
||||||
.then((res) => (guildCount += res.length));
|
.then(res => (guildCount += res.length));
|
||||||
await this.api.applicationCommands
|
await this.api.applicationCommands
|
||||||
.bulkOverwriteGlobalCommands(env.APPLICATION_ID, publicCommands)
|
.bulkOverwriteGlobalCommands(env.APPLICATION_ID, publicCommands)
|
||||||
.then((res) => (globalCount += res.length));
|
.then(res => (globalCount += res.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|||||||
@ -27,10 +27,10 @@ export async function translateAutocompleteImpl(
|
|||||||
? await getSourceLanguages()
|
? await getSourceLanguages()
|
||||||
: await getTargetLanguages();
|
: await getTargetLanguages();
|
||||||
const choices = languages
|
const choices = languages
|
||||||
.filter((language) =>
|
.filter(language =>
|
||||||
language.name.toLowerCase().includes(option.value.toLowerCase())
|
language.name.toLowerCase().includes(option.value.toLowerCase())
|
||||||
)
|
)
|
||||||
.map((language) => ({
|
.map(language => ({
|
||||||
name: language.name,
|
name: language.name,
|
||||||
value: language.code,
|
value: language.code,
|
||||||
}))
|
}))
|
||||||
@ -109,19 +109,19 @@ export default defineCommand({
|
|||||||
.setDescription(
|
.setDescription(
|
||||||
"Translates text using DeepL or Google Translate as fallback"
|
"Translates text using DeepL or Google Translate as fallback"
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("text")
|
.setName("text")
|
||||||
.setDescription("The text to translate")
|
.setDescription("The text to translate")
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("source")
|
.setName("source")
|
||||||
.setDescription("Source language of the text")
|
.setDescription("Source language of the text")
|
||||||
.setAutocomplete(true)
|
.setAutocomplete(true)
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("target")
|
.setName("target")
|
||||||
.setDescription("Target language of the text")
|
.setDescription("Target language of the text")
|
||||||
|
|||||||
@ -13,36 +13,29 @@ import { translateImpl } from "./translate";
|
|||||||
import { findFuzzyLanguage } from "../../utils/deepl";
|
import { findFuzzyLanguage } from "../../utils/deepl";
|
||||||
|
|
||||||
export function buildTranslateModal() {
|
export function buildTranslateModal() {
|
||||||
const modal = new ModalBuilder()
|
return new ModalBuilder()
|
||||||
.setTitle("Translate")
|
.setTitle("Translate")
|
||||||
.setCustomId("translate-modal");
|
.setCustomId("translate-modal")
|
||||||
|
.addComponents(
|
||||||
const sourceInput = new TextInputBuilder()
|
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
|
||||||
|
new TextInputBuilder()
|
||||||
.setLabel("Source language")
|
.setLabel("Source language")
|
||||||
.setCustomId("source")
|
.setCustomId("source")
|
||||||
.setStyle(TextInputStyle.Short)
|
.setStyle(TextInputStyle.Short)
|
||||||
.setMaxLength(20)
|
.setMaxLength(20)
|
||||||
.setPlaceholder("en, pl, hungarian, japanese...")
|
.setPlaceholder("en, pl, hungarian, japanese...")
|
||||||
.setRequired(false);
|
.setRequired(false)
|
||||||
|
),
|
||||||
const targetInput = new TextInputBuilder()
|
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
|
||||||
|
new TextInputBuilder()
|
||||||
.setLabel("Target language")
|
.setLabel("Target language")
|
||||||
.setCustomId("target")
|
.setCustomId("target")
|
||||||
.setStyle(TextInputStyle.Short)
|
.setStyle(TextInputStyle.Short)
|
||||||
.setMaxLength(20)
|
.setMaxLength(20)
|
||||||
.setPlaceholder("en, pl, hungarian, japanese...")
|
.setPlaceholder("en, pl, hungarian, japanese...")
|
||||||
.setRequired(false);
|
.setRequired(false)
|
||||||
|
)
|
||||||
const sourceRow =
|
|
||||||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
|
|
||||||
sourceInput
|
|
||||||
);
|
);
|
||||||
const targetRow =
|
|
||||||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
|
|
||||||
targetInput
|
|
||||||
);
|
|
||||||
|
|
||||||
return modal.addComponents(sourceRow, targetRow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineCommand({
|
export default defineCommand({
|
||||||
@ -61,10 +54,10 @@ export default defineCommand({
|
|||||||
|
|
||||||
await interaction
|
await interaction
|
||||||
.awaitModalSubmit({
|
.awaitModalSubmit({
|
||||||
filter: (i) => i.customId === "translate-modal",
|
filter: i => i.customId === "translate-modal",
|
||||||
time: 60000 * 5,
|
time: 60000 * 5,
|
||||||
})
|
})
|
||||||
.then(async (interaction) => {
|
.then(async interaction => {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
const sourceField =
|
const sourceField =
|
||||||
@ -75,15 +68,11 @@ export default defineCommand({
|
|||||||
const source =
|
const source =
|
||||||
sourceField === "auto"
|
sourceField === "auto"
|
||||||
? null
|
? null
|
||||||
: await findFuzzyLanguage(sourceField, "source").then(
|
: await findFuzzyLanguage(sourceField, "source").then(l => l?.code);
|
||||||
(l) => l?.code
|
|
||||||
);
|
|
||||||
const target =
|
const target =
|
||||||
targetField === "en-US"
|
targetField === "en-US"
|
||||||
? targetField
|
? targetField
|
||||||
: await findFuzzyLanguage(targetField, "target").then(
|
: await findFuzzyLanguage(targetField, "target").then(l => l?.code);
|
||||||
(l) => l?.code
|
|
||||||
);
|
|
||||||
|
|
||||||
if (source === undefined) {
|
if (source === undefined) {
|
||||||
abort("Source language not found");
|
abort("Source language not found");
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export default defineCommand({
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("wiktionary")
|
.setName("wiktionary")
|
||||||
.setDescription("Looks up a term on Wiktionary")
|
.setDescription("Looks up a term on Wiktionary")
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("term")
|
.setName("term")
|
||||||
.setDescription("The term to look up")
|
.setDescription("The term to look up")
|
||||||
@ -33,12 +33,12 @@ export default defineCommand({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
suggestions.forEach((suggestion) => {
|
suggestions.forEach(suggestion => {
|
||||||
titleCache.set(suggestion.key, suggestion.title);
|
titleCache.set(suggestion.key, suggestion.title);
|
||||||
});
|
});
|
||||||
|
|
||||||
const choices = suggestions
|
const choices = suggestions
|
||||||
.map((suggestion) => ({
|
.map(suggestion => ({
|
||||||
name: suggestion.title,
|
name: suggestion.title,
|
||||||
value: `:${suggestion.key}`,
|
value: `:${suggestion.key}`,
|
||||||
}))
|
}))
|
||||||
@ -69,17 +69,17 @@ export default defineCommand({
|
|||||||
|
|
||||||
const title = titleCache.get(term) ?? term;
|
const title = titleCache.get(term) ?? term;
|
||||||
const msg = new PaginatedMessage();
|
const msg = new PaginatedMessage();
|
||||||
msg.setSelectMenuOptions((i) => ({
|
msg.setSelectMenuOptions(i => ({
|
||||||
label: definitions[i - 1].language,
|
label: definitions[i - 1].language,
|
||||||
description: `Page ${i}`,
|
description: `Page ${i}`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
definitions.forEach((definition) => {
|
definitions.forEach(definition => {
|
||||||
const description = definition.entries
|
const description = definition.entries
|
||||||
.map((entry) => {
|
.map(entry => {
|
||||||
const name = entry.partOfSpeech;
|
const name = entry.partOfSpeech;
|
||||||
const definitions = entry.definitions
|
const definitions = entry.definitions
|
||||||
.filter((def) => def.definition)
|
.filter(def => def.definition)
|
||||||
.map((def, i) => {
|
.map((def, i) => {
|
||||||
const prefix = inlineCode(`${i + 1}.`);
|
const prefix = inlineCode(`${i + 1}.`);
|
||||||
const definition = stripHtml(def.definition);
|
const definition = stripHtml(def.definition);
|
||||||
@ -91,7 +91,7 @@ export default defineCommand({
|
|||||||
})
|
})
|
||||||
.join("\n\n");
|
.join("\n\n");
|
||||||
|
|
||||||
msg.addPageEmbed((embed) =>
|
msg.addPageEmbed(embed =>
|
||||||
embed
|
embed
|
||||||
.setAuthor({
|
.setAuthor({
|
||||||
name: `Wiktionary - ${definition.language}`,
|
name: `Wiktionary - ${definition.language}`,
|
||||||
|
|||||||
@ -102,10 +102,10 @@ export default defineCommand({
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("ocr")
|
.setName("ocr")
|
||||||
.setDescription("OCR an image using Google Lens or Yandex as fallback")
|
.setDescription("OCR an image using Google Lens or Yandex as fallback")
|
||||||
.addAttachmentOption((option) =>
|
.addAttachmentOption(option =>
|
||||||
option.setName("image").setDescription("The image to OCR")
|
option.setName("image").setDescription("The image to OCR")
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option.setName("url").setDescription("The image URL to OCR")
|
option.setName("url").setDescription("The image URL to OCR")
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@ -15,19 +15,19 @@ export default defineCommand({
|
|||||||
.setDescription(
|
.setDescription(
|
||||||
"OCR an image using Google Lens or Yandex and translate the result using DeepL or Google Translate"
|
"OCR an image using Google Lens or Yandex and translate the result using DeepL or Google Translate"
|
||||||
)
|
)
|
||||||
.addAttachmentOption((option) =>
|
.addAttachmentOption(option =>
|
||||||
option.setName("image").setDescription("The image to OCR")
|
option.setName("image").setDescription("The image to OCR")
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option.setName("url").setDescription("The image URL to OCR")
|
option.setName("url").setDescription("The image URL to OCR")
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("source")
|
.setName("source")
|
||||||
.setDescription("Source language of the text")
|
.setDescription("Source language of the text")
|
||||||
.setAutocomplete(true)
|
.setAutocomplete(true)
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("target")
|
.setName("target")
|
||||||
.setDescription("Target language of the text")
|
.setDescription("Target language of the text")
|
||||||
|
|||||||
@ -22,10 +22,10 @@ export default defineCommand({
|
|||||||
|
|
||||||
await interaction
|
await interaction
|
||||||
.awaitModalSubmit({
|
.awaitModalSubmit({
|
||||||
filter: (i) => i.customId === "translate-modal",
|
filter: i => i.customId === "translate-modal",
|
||||||
time: 60000 * 5,
|
time: 60000 * 5,
|
||||||
})
|
})
|
||||||
.then(async (interaction) => {
|
.then(async interaction => {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
const sourceField =
|
const sourceField =
|
||||||
@ -36,15 +36,11 @@ export default defineCommand({
|
|||||||
const source =
|
const source =
|
||||||
sourceField === null
|
sourceField === null
|
||||||
? sourceField
|
? sourceField
|
||||||
: await findFuzzyLanguage(sourceField, "source").then(
|
: await findFuzzyLanguage(sourceField, "source").then(l => l?.code);
|
||||||
(l) => l?.code
|
|
||||||
);
|
|
||||||
const target =
|
const target =
|
||||||
targetField === "en-US"
|
targetField === "en-US"
|
||||||
? targetField
|
? targetField
|
||||||
: await findFuzzyLanguage(targetField, "target").then(
|
: await findFuzzyLanguage(targetField, "target").then(l => l?.code);
|
||||||
(l) => l?.code
|
|
||||||
);
|
|
||||||
|
|
||||||
if (source === undefined) {
|
if (source === undefined) {
|
||||||
abort("Source language not found");
|
abort("Source language not found");
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import { defineCommand } from "..";
|
|||||||
import { client } from "../../client";
|
import { client } from "../../client";
|
||||||
import { abort } from "../../utils/error";
|
import { abort } from "../../utils/error";
|
||||||
import { restart as restartBot } from "../../utils/restart";
|
import { restart as restartBot } from "../../utils/restart";
|
||||||
import { shell } from "../../utils/functions";
|
import { noop, shell } from "../../utils/functions";
|
||||||
|
|
||||||
export async function sync(interaction: ChatInputCommandInteraction) {
|
export async function sync(interaction: ChatInputCommandInteraction) {
|
||||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
@ -39,7 +39,7 @@ export async function restart(interaction: ChatInputCommandInteraction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function update(interaction: ChatInputCommandInteraction) {
|
export async function update(interaction: ChatInputCommandInteraction) {
|
||||||
const response = await interaction.deferReply({ withResponse: true });
|
const reply = await interaction.deferReply();
|
||||||
const result = await shell`git pull`;
|
const result = await shell`git pull`;
|
||||||
const output = result.stdout + result.stderr;
|
const output = result.stdout + result.stderr;
|
||||||
|
|
||||||
@ -63,14 +63,14 @@ export async function update(interaction: ChatInputCommandInteraction) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!isUpToDate && !result.failed) {
|
if (!isUpToDate && !result.failed) {
|
||||||
response.resource?.message
|
await reply
|
||||||
?.awaitMessageComponent({
|
.awaitMessageComponent({
|
||||||
componentType: ComponentType.Button,
|
componentType: ComponentType.Button,
|
||||||
time: 30000,
|
time: 30000,
|
||||||
filter: (i) => i.user.id === interaction.user.id,
|
filter: i => i.user.id === interaction.user.id,
|
||||||
dispose: true,
|
dispose: true,
|
||||||
})
|
})
|
||||||
.then(async (interaction) => {
|
.then(async interaction => {
|
||||||
await interaction.update({
|
await interaction.update({
|
||||||
components: [],
|
components: [],
|
||||||
});
|
});
|
||||||
@ -81,7 +81,8 @@ export async function update(interaction: ChatInputCommandInteraction) {
|
|||||||
channelId: interaction.message.channelId,
|
channelId: interaction.message.channelId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
|
.catch(noop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,13 +90,13 @@ export default defineCommand({
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("dev")
|
.setName("dev")
|
||||||
.setDescription("Owner commands")
|
.setDescription("Owner commands")
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand(subcommand =>
|
||||||
subcommand.setName("sync").setDescription("Sync application commands")
|
subcommand.setName("sync").setDescription("Sync application commands")
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand(subcommand =>
|
||||||
subcommand.setName("restart").setDescription("Restarts the bot")
|
subcommand.setName("restart").setDescription("Restarts the bot")
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand(subcommand =>
|
||||||
subcommand.setName("update").setDescription("Updates the bot")
|
subcommand.setName("update").setDescription("Updates the bot")
|
||||||
),
|
),
|
||||||
isOwnerOnly: true,
|
isOwnerOnly: true,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ export default defineCommand({
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("charinfo")
|
.setName("charinfo")
|
||||||
.setDescription("Unicode character info for given text")
|
.setDescription("Unicode character info for given text")
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("text")
|
.setName("text")
|
||||||
.setDescription("The text to get info for")
|
.setDescription("The text to get info for")
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export default defineCommand({
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("httpcat")
|
.setName("httpcat")
|
||||||
.setDescription("Sends a cat for the given HTTP code")
|
.setDescription("Sends a cat for the given HTTP code")
|
||||||
.addIntegerOption((option) =>
|
.addIntegerOption(option =>
|
||||||
option
|
option
|
||||||
.setName("code")
|
.setName("code")
|
||||||
.setDescription("HTTP code")
|
.setDescription("HTTP code")
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export default defineCommand({
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("isdown")
|
.setName("isdown")
|
||||||
.setDescription("URL healthcheck")
|
.setDescription("URL healthcheck")
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option.setName("url").setDescription("The URL to check").setRequired(true)
|
option.setName("url").setDescription("The URL to check").setRequired(true)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@ -15,19 +15,20 @@ export default defineCommand({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const msg = (
|
await interaction
|
||||||
await interaction.reply({
|
.reply({
|
||||||
content: `:ping_pong: Pong!\nWebSocket latency is ${inlineCode(
|
content: `:ping_pong: Pong!\nWebSocket latency is ${inlineCode(
|
||||||
Math.round(client.ws.ping).toString()
|
Math.round(client.ws.ping).toString()
|
||||||
)} ms.`,
|
)} ms.`,
|
||||||
withResponse: true,
|
withResponse: true,
|
||||||
})
|
})
|
||||||
).resource!.message!;
|
.then(reply => {
|
||||||
|
const msg = reply.resource?.message;
|
||||||
await msg.edit(
|
return msg?.edit(
|
||||||
`${msg.content}\nAPI roundtrip latency is ${inlineCode(
|
`${msg?.content}\nAPI roundtrip latency is ${inlineCode(
|
||||||
(msg.createdTimestamp - interaction.createdTimestamp).toString()
|
(msg?.createdTimestamp - interaction.createdTimestamp).toString()
|
||||||
)}ms.`
|
)}ms.`
|
||||||
);
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,7 +6,7 @@ export default defineCommand({
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("whois")
|
.setName("whois")
|
||||||
.setDescription("Look up IP or domain info")
|
.setDescription("Look up IP or domain info")
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option.setName("query").setDescription("IP or domain").setRequired(true)
|
option.setName("query").setDescription("IP or domain").setRequired(true)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@ -15,13 +15,13 @@ export default defineCommand({
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("wikipedia")
|
.setName("wikipedia")
|
||||||
.setDescription("Looks up a thing on Wikipedia")
|
.setDescription("Looks up a thing on Wikipedia")
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("query")
|
.setName("query")
|
||||||
.setDescription("The thing to look up")
|
.setDescription("The thing to look up")
|
||||||
.setAutocomplete(true)
|
.setAutocomplete(true)
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("language")
|
.setName("language")
|
||||||
.setDescription("The Wikipedia language edition to use")
|
.setDescription("The Wikipedia language edition to use")
|
||||||
@ -37,11 +37,11 @@ export default defineCommand({
|
|||||||
const editions = await getWikipediaEditions();
|
const editions = await getWikipediaEditions();
|
||||||
const choices = editions
|
const choices = editions
|
||||||
.filter(
|
.filter(
|
||||||
(edition) =>
|
edition =>
|
||||||
edition.subdomain.toLowerCase() === value ||
|
edition.subdomain.toLowerCase() === value ||
|
||||||
edition.language.toLowerCase().includes(value)
|
edition.language.toLowerCase().includes(value)
|
||||||
)
|
)
|
||||||
.map((edition) => ({
|
.map(edition => ({
|
||||||
name: `${edition.language} (${edition.subdomain})`,
|
name: `${edition.language} (${edition.subdomain})`,
|
||||||
value: `:${edition.subdomain}`,
|
value: `:${edition.subdomain}`,
|
||||||
}))
|
}))
|
||||||
@ -57,7 +57,7 @@ export default defineCommand({
|
|||||||
option.value
|
option.value
|
||||||
);
|
);
|
||||||
const choices = suggestions
|
const choices = suggestions
|
||||||
.map((suggestion) => ({
|
.map(suggestion => ({
|
||||||
name: suggestion,
|
name: suggestion,
|
||||||
value: `:${suggestion}`,
|
value: `:${suggestion}`,
|
||||||
}))
|
}))
|
||||||
@ -77,10 +77,9 @@ export default defineCommand({
|
|||||||
} else {
|
} else {
|
||||||
const editions = await getWikipediaEditions();
|
const editions = await getWikipediaEditions();
|
||||||
const edition =
|
const edition =
|
||||||
editions.find((endpoint) => endpoint.subdomain === language) ||
|
editions.find(endpoint => endpoint.subdomain === language) ||
|
||||||
editions.find(
|
editions.find(
|
||||||
(endpoint) =>
|
endpoint => endpoint.language.toLowerCase() === language.toLowerCase()
|
||||||
endpoint.language.toLowerCase() === language.toLowerCase()
|
|
||||||
);
|
);
|
||||||
if (!edition) {
|
if (!edition) {
|
||||||
abort("No such Wikipedia language edition");
|
abort("No such Wikipedia language edition");
|
||||||
|
|||||||
@ -3,12 +3,12 @@ import { client } from "./client";
|
|||||||
import { logger } from "./utils/logger";
|
import { logger } from "./utils/logger";
|
||||||
import { DiscordAPIError } from "discord.js";
|
import { DiscordAPIError } from "discord.js";
|
||||||
|
|
||||||
process.on("unhandledRejection", (err) => {
|
process.on("unhandledRejection", err => {
|
||||||
if (err instanceof DiscordAPIError && err.status >= 500) return;
|
if (err instanceof DiscordAPIError && err.status >= 500) return;
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("uncaughtException", (err) => {
|
process.on("uncaughtException", err => {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -21,19 +21,16 @@ export async function confirmPrompt(
|
|||||||
.setStyle(ButtonStyle.Danger)
|
.setStyle(ButtonStyle.Danger)
|
||||||
);
|
);
|
||||||
|
|
||||||
const msg = (
|
const reply = await interaction.reply({
|
||||||
await interaction.reply({
|
|
||||||
content: message,
|
content: message,
|
||||||
components: [row],
|
components: [row],
|
||||||
withResponse: true,
|
});
|
||||||
})
|
|
||||||
).resource!.message!;
|
|
||||||
|
|
||||||
const confirmation = await msg
|
const confirmation = await reply
|
||||||
.awaitMessageComponent({
|
.awaitMessageComponent({
|
||||||
componentType: ComponentType.Button,
|
componentType: ComponentType.Button,
|
||||||
time: 60000,
|
time: 60000,
|
||||||
filter: (i) => i.user.id === interaction.user.id,
|
filter: i => i.user.id === interaction.user.id,
|
||||||
dispose: true,
|
dispose: true,
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
@ -62,7 +62,7 @@ export async function getUsage() {
|
|||||||
export async function isSourceLanguage(code: string) {
|
export async function isSourceLanguage(code: string) {
|
||||||
const sourceLanguages = await getSourceLanguages();
|
const sourceLanguages = await getSourceLanguages();
|
||||||
return (
|
return (
|
||||||
sourceLanguages.find((l) => l.code.toLowerCase() === code.toLowerCase()) !==
|
sourceLanguages.find(l => l.code.toLowerCase() === code.toLowerCase()) !==
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ export async function isSourceLanguage(code: string) {
|
|||||||
export async function isTargetLanguage(code: string) {
|
export async function isTargetLanguage(code: string) {
|
||||||
const targetLanguages = await getTargetLanguages();
|
const targetLanguages = await getTargetLanguages();
|
||||||
return (
|
return (
|
||||||
targetLanguages.find((l) => l.code.toLowerCase() === code.toLowerCase()) !==
|
targetLanguages.find(l => l.code.toLowerCase() === code.toLowerCase()) !==
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ export function pickRandom<T>(arr: T[]): T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function sleep(ms: number) {
|
export function sleep(ms: number) {
|
||||||
return new Promise<void>((resolve) => setTimeout(resolve, ms));
|
return new Promise<void>(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function chunk<T>(arr: T[], size: number): T[][];
|
export function chunk<T>(arr: T[], size: number): T[][];
|
||||||
|
|||||||
@ -20,7 +20,7 @@ const languageCodes = lazy(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const getLanguages = lazy(() =>
|
export const getLanguages = lazy(() =>
|
||||||
languageCodes().map((code) => ({
|
languageCodes().map(code => ({
|
||||||
code,
|
code,
|
||||||
name: languageCodeToName(code),
|
name: languageCodeToName(code),
|
||||||
}))
|
}))
|
||||||
@ -51,7 +51,7 @@ export async function translate(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
translatedText: sentences
|
translatedText: sentences
|
||||||
.map((s) => s?.trans)
|
.map(s => s?.trans)
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(""),
|
.join(""),
|
||||||
detectedSourceLang: src,
|
detectedSourceLang: src,
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export async function lensOcr(resource: string | Buffer): Promise<OCRResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
text: result.segments.map((s) => s.text).join("\n"),
|
text: result.segments.map(s => s.text).join("\n"),
|
||||||
language: result.language ?? "n/a",
|
language: result.language ?? "n/a",
|
||||||
model: "google",
|
model: "google",
|
||||||
};
|
};
|
||||||
|
|||||||
@ -52,7 +52,7 @@ export async function maybeSendRestarted() {
|
|||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
|
|
||||||
await silently(
|
await silently(
|
||||||
channel.messages.fetch(state.message.id).then((msg) => msg.react("☑️"))
|
channel.messages.fetch(state.message.id).then(msg => msg.react("☑️"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,7 @@ export const getWikipediaEditions = lazy(async () => {
|
|||||||
subdomain: $(el).find("> td:nth-child(5)").text(),
|
subdomain: $(el).find("> td:nth-child(5)").text(),
|
||||||
}))
|
}))
|
||||||
.toArray()
|
.toArray()
|
||||||
.filter((edition) => edition.language && edition.subdomain);
|
.filter(edition => edition.language && edition.subdomain);
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function searchWikipedia(client: KyInstance, query: string) {
|
export async function searchWikipedia(client: KyInstance, query: string) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user