2019-02-24 23:03:53 +01:00
const { Command } = require ( 'discord-akairo' ) ;
const Twitter = require ( 'twitter-lite' ) ;
const rand = require ( '../../rand.js' ) ;
2019-02-25 18:42:22 +01:00
const Filter = require ( 'bad-words' ) ;
2019-03-30 15:19:29 +01:00
const { MessageEmbed } = require ( 'discord.js' ) ;
2019-02-25 18:42:22 +01:00
let filter = new Filter ( ) ;
2019-02-25 03:18:04 +01:00
const { twiConsumer , twiConsumerSecret , twiToken , twiTokenSecret , twiChannel } = require ( '../../config.json' ) ;
2019-02-25 03:26:06 +01:00
const reload = require ( 'auto-reload' ) ;
2019-02-24 23:03:53 +01:00
class tweetCommand extends Command {
constructor ( ) {
super ( 'tweet' , {
aliases : [ 'tweet' ] ,
category : 'general' ,
args : [
{
id : 'text' ,
type : 'string' ,
2019-06-23 03:41:59 +02:00
prompt : {
start : 'Write something to tweet' ,
} ,
2019-02-24 23:03:53 +01:00
match : 'rest'
}
] ,
description : {
2019-07-08 20:34:18 +02:00
content : 'Send tweet from Haha yes twitter account (NOTE: all the tweet sent using this command are logged, so don\'t say nasty thing or you might get blacklisted from it! )' ,
2019-02-24 23:03:53 +01:00
usage : '[text]' ,
examples : [ 'this epic tweet is in my epic twitter' ]
}
} ) ;
}
async exec ( message , args ) {
2019-02-28 17:35:53 +01:00
let censor = reload ( '../../json/censor.json' ) ;
let uncensor = reload ( '../../json/uncensor.json' ) ;
2019-02-26 15:28:08 +01:00
filter . addWords ( ... censor ) ;
filter . removeWords ( ... uncensor ) ;
2019-02-26 00:23:12 +01:00
2019-03-10 01:29:54 +01:00
const blacklist = reload ( '../../json/twiBlacklist.json' ) ;
2019-02-25 03:18:04 +01:00
const channel = this . client . channels . get ( twiChannel ) ;
if ( blacklist . includes ( message . author . id ) ) {
return message . channel . send ( 'You have been blacklisted from this command... be less naughty next time.' ) ;
}
2019-07-01 00:41:14 +02:00
// remove zero width space
2019-07-01 00:42:08 +02:00
let text = args . text . replace ( ' ' , '' ) ;
2019-02-24 23:03:53 +01:00
if ( ! text )
return ;
2019-02-25 04:27:38 +01:00
//Filter out swear word
text = filter . clean ( text ) ;
2019-02-24 23:41:37 +01:00
2019-02-24 23:03:53 +01:00
text = rand . random ( text , message ) ;
try {
2019-02-25 03:18:04 +01:00
let client = new Twitter ( {
consumer _key : twiConsumer ,
consumer _secret : twiConsumerSecret ,
access _token _key : twiToken ,
access _token _secret : twiTokenSecret
} ) ;
2019-02-24 23:03:53 +01:00
const response = await client . post ( 'statuses/update' , {
status : text
} ) ;
const tweetid = response . id _str ;
2019-03-30 15:19:29 +01:00
const Embed = new MessageEmbed ( )
. setAuthor ( message . author . username , message . author . displayAvatarURL ( ) )
. setDescription ( args . text )
. addField ( 'Link' , ` https://twitter.com/HahaYesDB/status/ ${ tweetid } ` )
2019-07-01 06:21:00 +02:00
. setFooter ( ` Tweet ID: ${ tweetid } | Author ID: ${ message . author . id } | Guild ID: ${ message . guild . id } ` )
2019-03-30 15:19:29 +01:00
. setTimestamp ( ) ;
2019-02-25 03:18:04 +01:00
2019-03-30 15:19:29 +01:00
channel . send ( { embed : Embed } ) ;
2019-02-25 03:18:04 +01:00
2019-02-24 23:03:53 +01:00
return message . channel . send ( ` Go see ur epic tweet https://twitter.com/HahaYesDB/status/ ${ tweetid } ` ) ;
} catch ( err ) {
2019-02-24 23:41:37 +01:00
console . error ( err ) ;
2019-02-24 23:03:53 +01:00
return message . channel . send ( 'Oh no, an error has occured :(' ) ;
}
}
}
module . exports = tweetCommand ;