diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6bd45c0..2986394 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -42,4 +42,5 @@ model server { verificationChannel String @default("none") levelsEnabled Boolean @default(false) levelsMessage String @default("Congratulations, {user}! You've leveled up to level {level}!") + flagTrans Boolean @default(false) } diff --git a/src/handlers/flagTranslation.ts b/src/handlers/flagTranslation.ts index c03dc1e..cb935c8 100644 --- a/src/handlers/flagTranslation.ts +++ b/src/handlers/flagTranslation.ts @@ -23,11 +23,18 @@ const translate = new Translate({ const vision = new ImageAnnotatorClient({ apiKey: process.env.GOOGLE_API_KEY as string, -}) +}); const prisma = new PrismaClient(); export async function translateMessage(reaction: MessageReaction, user: User) { + const server = reaction.message.guildId; + const serverData = await prisma.server.findUnique({ + where: { + id: server as string, + }, + }); + if (!serverData?.flagTrans) return; const country = emojiCountryCode(reaction.emoji.name as string); const language = countryToLanguage(country); if (!language) { @@ -40,7 +47,7 @@ export async function translateMessage(reaction: MessageReaction, user: User) { message.reactions.removeAll(); await dmUser( user.id, - "MikanBot", + "MikanBot Flag Translation", "You are being ratelimited! Please wait a bit before translating another message. You can speed this up by becoming a premium user.", ); return; @@ -62,7 +69,7 @@ export async function translateMessage(reaction: MessageReaction, user: User) { }, }, features: [{ type: "TEXT_DETECTION" }], - }) + }); const [image] = visionResult; if (!image.textAnnotations) { message.reactions.removeAll(); @@ -83,7 +90,10 @@ export async function translateMessage(reaction: MessageReaction, user: User) { .setDescription(translation) .setColor("#FF7700") .setTimestamp(); - await message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } }); + await message.reply({ + embeds: [embed], + allowedMentions: { repliedUser: false }, + }); message.reactions.removeAll(); const userDb = await prisma.user.findUnique({ where: { @@ -111,7 +121,10 @@ export async function translateMessage(reaction: MessageReaction, user: User) { .setDescription(translation) .setColor("#FF7700") .setTimestamp(); - await message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } }); + await message.reply({ + embeds: [embed], + allowedMentions: { repliedUser: false }, + }); message.reactions.removeAll(); const userDb = await prisma.user.findUnique({ where: { @@ -123,4 +136,4 @@ export async function translateMessage(reaction: MessageReaction, user: User) { } else { setTranslationRatelimit("translate", user.id, 30); } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index ee977d1..ff0bbfc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ import { Partials, EmbedBuilder, MessageReaction, + type User, } from "discord.js"; const client = new Client({ @@ -62,8 +63,8 @@ client.on("messageReactionAdd", async (reaction: MessageReaction, user) => { } } try { - if (emojiCountryCode(reaction.emoji.name)) { - await translateMessage(reaction, user); + if (emojiCountryCode(reaction.emoji.name as string)) { + await translateMessage(reaction, user as User); } } catch (error) { return;