Send tweet from discord!

This commit is contained in:
Supositware 2019-02-24 23:03:53 +01:00
parent bab84c7890
commit b70ba6fb49
3 changed files with 57 additions and 57 deletions

56
commands/general/tweet.js Normal file
View file

@ -0,0 +1,56 @@
const { Command } = require('discord-akairo');
const Twitter = require('twitter-lite');
const rand = require('../../rand.js');
const { twiConsumer, twiConsumerSecret, twiToken, twiTokenSecret } = require('../../config.json');
class tweetCommand extends Command {
constructor() {
super('tweet', {
aliases: ['tweet'],
category: 'general',
args: [
{
id: 'text',
type: 'string',
match: 'rest'
}
],
description: {
content: 'Send tweet from Haha yes twitter account',
usage: '[text]',
examples: ['this epic tweet is in my epic twitter']
}
});
}
async exec(message, args) {
let text = args.text;
if (!text)
return;
text = rand.random(text, message);
let client = new Twitter({
consumer_key: twiConsumer,
consumer_secret: twiConsumerSecret,
access_token_key: twiToken,
access_token_secret: twiTokenSecret
});
try {
const response = await client.post('statuses/update', {
status: text
});
const tweetid = response.id_str;
// Send the final text
return message.channel.send(`Go see ur epic tweet https://twitter.com/HahaYesDB/status/${tweetid}`);
} catch(err) {
return message.channel.send('Oh no, an error has occured :(');
}
}
}
module.exports = tweetCommand;

View file

@ -1,56 +0,0 @@
//TODO
//FIX INDENT
//PUT TWITTER KEY ON CONFIG.JSON
//SEND FEEDBACK ONCE THE COMMAND HAVE BEEN EXECUTED
const { Command } = require('discord-akairo');
const Twitter = require('twitter');
const rand = require('../../rand.js');
class twitterCommand extends Command {
constructor() {
super('twitter', {
aliases: ['twitter'],
category: 'general',
args: [
{
id: 'text',
type: 'string',
match: 'rest'
}
],
description: {
content: 'Send tweet from Haha yes twitter account',
usage: '[text]',
examples: ['this epic tweet is in my epic twitter']
}
});
}
async exec(message, args) {
let client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
let text = args.text;
if (!text)
return;
text = rand.random(text, message);
client.post('statuses/update', {status: 'test'}, function(error, tweet, response) {
if (!error) {
console.log(tweet);
}
console.log(response);
});
// Send the final text
return message.channel.send('epic');
}
}
module.exports = twitterCommand;

View file

@ -14,7 +14,7 @@
"node-fetch": "^2.3.0", "node-fetch": "^2.3.0",
"reload-json": "^0.3.1", "reload-json": "^0.3.1",
"superagent": "^4.1.0", "superagent": "^4.1.0",
"twitter": "^1.7.1", "twitter-lite": "^0.9.1",
"youtube-dl": "^1.12.2" "youtube-dl": "^1.12.2"
}, },
"devDependencies": { "devDependencies": {