Haha-Yes/commands/general/tweet.js

117 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-02-24 23:03:53 +01:00
const { Command } = require('discord-akairo');
const Twitter = require('twitter-lite');
const rand = require('../../rand.js');
2019-08-13 16:53:16 +02:00
//const Filter = require('bad-words');
//let filter = new Filter();
2019-10-06 20:29:42 +02:00
const TwitterBlacklist = require('../../models').TwitterBlacklist;
const { twiConsumer, twiConsumerSecret, twiToken, twiTokenSecret, twiChannel } = require('../../config.json');
2019-02-24 23:03:53 +01:00
class tweetCommand extends Command {
constructor() {
super('tweet', {
aliases: ['tweet'],
category: 'general',
2019-11-09 12:04:01 +01:00
clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'],
2019-11-08 19:42:22 +01:00
cooldown: 3600000,
2019-10-07 00:01:03 +02:00
ratelimit: 3,
2019-02-24 23:03:53 +01:00
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-08-13 16:53:16 +02:00
/*
2019-10-06 20:29:42 +02:00
// Censor words
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-08-13 16:53:16 +02:00
*/
2019-02-26 00:23:12 +01:00
2019-10-06 20:29:42 +02:00
// see if user is not banned
const blacklist = await TwitterBlacklist.findOne({where: {userID:message.author.id}});
if (blacklist) {
return message.channel.send(`You have been blacklisted for the following reasons: \`\`${blacklist.get('reason')}\`\` be less naughty less time.`);
}
2019-10-05 22:14:23 +02:00
// Don't let account new account use this command to prevent spam
let date = new Date();
if (message.author.createdAt > date.setDate(date.getDate() - 7)) {
return message.channel.send('Your account is too new to be able to use this command!');
}
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-08-13 16:53:16 +02:00
/*
//Filter out swear word
text = filter.clean(text);
2019-08-13 16:53:16 +02:00
*/
2019-02-24 23:41:37 +01:00
2019-02-24 23:03:53 +01:00
text = rand.random(text, message);
if (text.length > 280) {
return message.channel.send('Your message is more than the 280 characters limit!');
}
2019-02-24 23:03:53 +01:00
try {
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-11-22 12:30:20 +01:00
const publicEmbed = this.client.util.embed()
2019-10-13 16:53:46 +02:00
.setAuthor('Some user of discord said...')
.setDescription(args.text)
.addField('Link', `https://twitter.com/HahaYesDB/status/${tweetid}`)
.setTimestamp();
2019-07-19 04:36:12 +02:00
2019-07-19 04:35:28 +02:00
// Im too lazy for now to make an entry in config.json
let channel = this.client.channels.get('597964498921455637');
channel.send({embed: publicEmbed});
2019-11-22 12:30:20 +01:00
const Embed = this.client.util.embed()
2019-03-30 15:19:29 +01:00
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setDescription(args.text)
2019-07-19 04:35:28 +02:00
.addField('Link', `https://twitter.com/HahaYesDB/status/${tweetid}`, true)
.addField('Tweet ID', tweetid, true)
2019-07-19 04:36:12 +02:00
.addField('Author', `${message.author.username} (${message.author.id})`, true)
.addField('Guild', `${message.guild.name} (${message.guild.id})`, true)
2019-03-30 15:19:29 +01:00
.setTimestamp();
channel = this.client.channels.get(twiChannel);
2019-03-30 15:19:29 +01:00
channel.send({embed: Embed});
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;