import type { Emoji , Member , Message } from "eris" ; import { Event } from "../classes/Event" ; export class EasyTranslate extends Event { events = [ "messageReactionAdd" ] ; async run ( _event , msg , emoji , member ) { if ( ! msg || ! msg . author || ! msg . content || ! msg . channel || msg . channel . type !== 0 ) return ; const toUni = function ( str ) { if ( str . length < 4 ) return str . codePointAt ( 0 ) . toString ( 16 ) ; return `${ str . codePointAt ( 0 ) . toString ( 16 ) }-${ str . codePointAt ( 2 ) . toString ( 16 ) }` ; } ; const [ letter1 , letter2 ] = toUni ( emoji . name ) . split ( "-" ) ; const finalLetter1 = parseInt ( letter1 , 16 ) - 127397 ; const finalLetter2 = parseInt ( letter2 , 16 ) - 127397 ; let lang = String . fromCharCode ( finalLetter1 ) + String . fromCharCode ( finalLetter2 ) ; if ( ! /[A-Z]{2}/ . test ( lang ) ) return ; switch ( lang ) { case "CZ" : lang = "CS" ; break ; case "JP" : lang = "JA" ; break ; case "SE" : lang = "SV" ; break ; case "BR" : lang = "PT" ; break ; case "GB" : case "US" : lang = "EN" ; } const cfg = await this . bot . db . getGuildConfig ( msg . channel . guild . id ) ; if ( cfg ?. easyTranslate === false ) return ; const cooldown = this . bot . cooldowns . get ( `easytranslate:${ msg . channel . id }` ) ; if ( cooldown ) return ; this . bot . cooldowns . set ( `easytranslate:${ msg . channel . id }` , new Date ( ) ) ; setTimeout ( ( ) => { this . bot . cooldowns . delete ( `easytranslate:${ msg . channel . id }` ) ; } , 5000 ) ; let localeString = "" ; const userLocale = await this . bot . localeSystem . getUserLocale ( msg . author . id , this . bot , true ) ; if ( userLocale ) localeString = userLocale ; else if ( cfg ?. guildLocale && ! userLocale ) localeString = cfg . guildLocale ; const string = this . bot . localeSystem . getLocaleFunction ( localeString ) ; msg . string = string ; this . bot . commands . find ( ( c ) => c . name === "translate" ) . run ( msg , null , [ lang ] . concat ( msg . content . split ( " " ) ) , true , member . user ) ; } }