-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
2,397 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Translate from '../../modules/Translate/Translate.mjs'; | ||
|
||
export default async message => { | ||
const { content } = message; | ||
|
||
// Translate any non-English message to English | ||
if (message.author.bot) return null; | ||
|
||
// Translate the message | ||
const { text, embed } = (await Translate.translate(content, 'en')) ?? {}; | ||
|
||
// If the message couldn't be translated, don't send a response | ||
if (!text || !embed) return; | ||
|
||
// Send the response | ||
await message.reply({ | ||
embeds: [embed], | ||
allowedMentions: { repliedUser: false }, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Events } from 'discord.js'; | ||
import Emoji from '../modules/Emoji/Emoji.mjs'; | ||
import Translate from '../modules/Translate/Translate.mjs'; | ||
|
||
export default { | ||
name: Events.MessageReactionAdd, | ||
async execute(reaction, user) { | ||
// When a reaction is received, check if the structure is partial | ||
if (reaction.partial) | ||
// If the message this reaction belongs to was removed, the fetching might result in an API error which should be handled | ||
await reaction.fetch().catch(() => {}); | ||
|
||
if (!reaction.message?.content) return; | ||
|
||
// Convert the emoji to a language code | ||
const targetLanguage = Emoji.emojiToLanguage(reaction.emoji.name); | ||
if (!targetLanguage) return; | ||
|
||
// Translate the message | ||
const { embed } = | ||
(await Translate.translate(reaction.message.content, targetLanguage)) ?? | ||
{}; | ||
|
||
if (!embed) return; | ||
|
||
// Send the response | ||
await reaction.message.reply({ | ||
embeds: [embed], | ||
allowedMentions: { repliedUser: false }, | ||
}); | ||
}, | ||
}; |
Oops, something went wrong.