2021-04-09 01:00:55 +00:00
module . exports = async ( bot , api ) => {
bot . on ( 'message' , async ( message ) => {
if ( ! message . content . startsWith ( process . env . PREFIX ) ) {
if ( message . channel . id == process . env . TTS _CHANNEL ) {
let chan = message . member . voice . channel ;
let userRow = await api . db . get ( 'select * from TTSPreferences where user_id=?' , message . author . id ) ;
if ( ! userRow ) {
await api . db . run ( 'insert into TTSPreferences (user_id,engine,voice) values (?,?,?)' , [ message . author . id , api . announcementEngine . shortName , api . announcementVoice ] ) ;
userRow = await api . db . get ( 'select * from TTSPreferences where user_id=?' , message . author . id ) ;
}
if ( api . ttsEngines [ userRow . engine ] ) {
api . speak ( chan , message . content , api . ttsEngines [ userRow . engine ] , userRow . voice )
} else {
}
}
}
} ) ;
api . registerCommand ( 'myvoice' , async ( args , message ) => {
let userEngine , userVoice ;
if ( args . length > 3 ) {
return api . respond ( message , "You tried to change your speaking voice with too many arguments." ) ;
}
if ( api . ttsEngines [ args [ 1 ] ] ) {
userEngine = args [ 1 ] ;
2021-04-10 21:45:02 +00:00
if ( api . ttsEngines [ userEngine ] . validateVoice ( args [ 2 ] . toLowerCase ( ) ) ) {
userVoice = args [ 2 ] . toLowerCase ( ) ;
2021-04-09 01:00:55 +00:00
api . respond ( message , "Your voice is now " + userVoice + " from " + api . ttsEngines [ userEngine ] . longName ) ;
} else {
userVoice = api . ttsEngines [ userEngine ] . getDefaultVoice ( ) ;
api . respond ( message , "Your voice name was invalid, so I switched to the default voice (" + userVoice + ") for " + api . ttsEngines [ userEngine ] . longName + " instead." ) ;
}
await api . db . run ( 'update TTSPreferences set engine=?, voice=? where user_id=?' , userEngine , userVoice , message . author . id ) ;
} else {
api . respond ( message , args [ 1 ] + " is not a valid engine name" ) ;
}
} ) ;
}