From 376fdb790bd0449e7d07fb9ae80e50543a89e07f Mon Sep 17 00:00:00 2001 From: Supositware Date: Thu, 28 Feb 2019 17:35:53 +0100 Subject: [PATCH] Moved thing arround and now able to post to facebook --- commands/general/facebook.js | 63 ++++++++++++++++++++++++ commands/general/tweet.js | 6 +-- commands/owner/{twitter => }/censor.js | 6 +-- commands/owner/rfacebook.js | 41 +++++++++++++++ commands/owner/{twitter => }/rtweet.js | 2 +- commands/owner/{twitter => }/uncensor.js | 6 +-- 6 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 commands/general/facebook.js rename commands/owner/{twitter => }/censor.js (79%) create mode 100644 commands/owner/rfacebook.js rename commands/owner/{twitter => }/rtweet.js (96%) rename commands/owner/{twitter => }/uncensor.js (79%) diff --git a/commands/general/facebook.js b/commands/general/facebook.js new file mode 100644 index 00000000..1f50ab67 --- /dev/null +++ b/commands/general/facebook.js @@ -0,0 +1,63 @@ +const { Command } = require('discord-akairo'); +const Filter = require('bad-words'); +let filter = new Filter(); +const fetch = require('node-fetch'); +const reload = require('auto-reload'); +const rand = require('../../rand.js'); +const { fbChannel, fbToken } = require('../../config.json'); + +class facebookCommand extends Command { + constructor() { + super('facebook', { + aliases: ['facebook', 'fb'], + category: 'general', + args: [ + { + id: 'text', + type: 'string', + match: 'rest' + } + ], + description: { + content: 'Post your message to the bot facebook page', + usage: '[text]', + examples: ['epic'] + } + }); + } + + async exec(message, args) { + let text = args.text; + + let censor = reload('../../json/censor.json'); + let uncensor = reload('../../json/uncensor.json'); + filter.addWords(...censor); + filter.removeWords(...uncensor); + + const blacklist = reload('../../json/Blacklist.json'); + const channel = this.client.channels.get(fbChannel); + + if (blacklist.includes(message.author.id)) { + return message.channel.send('You have been blacklisted from this command... be less naughty next time.'); + } + + //Filter out swear word + text = filter.clean(text); + + text = rand.random(text, message); + text = encodeURI(text); + + fetch(`https://graph.facebook.com/v3.2/1254967721332652/feed?message=${text}&access_token=${fbToken}`, { + method: 'post', + }).then((response) => { + return response.json(); + }).then((response) => { + let postID = response.id.slice(17); + message.channel.send(`Go see ur epic post https://www.facebook.com/HahaYesDiscord/posts/${postID}`); + channel.send(`AUTHOR: ${message.author.username} (${message.author.id}) Sent: ${args.text}\nhttps://www.facebook.com/HahaYesDiscord/posts/${postID}`); + console.log(response); + }); + } +} + +module.exports = facebookCommand; \ No newline at end of file diff --git a/commands/general/tweet.js b/commands/general/tweet.js index 5c808999..415d3a95 100644 --- a/commands/general/tweet.js +++ b/commands/general/tweet.js @@ -29,12 +29,12 @@ class tweetCommand extends Command { } async exec(message, args) { - let censor = reload('../../json/twitter/censor.json'); - let uncensor = reload('../../json/twitter/uncensor.json'); + let censor = reload('../../json/censor.json'); + let uncensor = reload('../../json/uncensor.json'); filter.addWords(...censor); filter.removeWords(...uncensor); - const blacklist = reload('../../json/twiBlacklist.json'); + const blacklist = reload('../../json/Blacklist.json'); const channel = this.client.channels.get(twiChannel); if (blacklist.includes(message.author.id)) { diff --git a/commands/owner/twitter/censor.js b/commands/owner/censor.js similarity index 79% rename from commands/owner/twitter/censor.js rename to commands/owner/censor.js index 4b55ed52..baf55fc3 100644 --- a/commands/owner/twitter/censor.js +++ b/commands/owner/censor.js @@ -30,9 +30,9 @@ class censorCommand extends Command { let words = []; let json = JSON.stringify(words); - fs.readFile('./json/twitter/censor.json', 'utf8', function readFileCallback(err, data) { + fs.readFile('./json/censor.json', 'utf8', function readFileCallback(err, data) { if (err) { - fs.writeFile('./json/twitter/censor.json', `["${word}"]`, function (err) { + fs.writeFile('./json/censor.json', `["${word}"]`, function (err) { if (err) { console.log(err); @@ -42,7 +42,7 @@ class censorCommand extends Command { words = JSON.parse(data); //now it an object words.push(word); json = JSON.stringify(words); //convert it back to json - fs.writeFile('./json/twitter/censor.json', json, 'utf8', function (err) { + fs.writeFile('./json/censor.json', json, 'utf8', function (err) { if (err) { return console.log(err); } diff --git a/commands/owner/rfacebook.js b/commands/owner/rfacebook.js new file mode 100644 index 00000000..99d9e4ae --- /dev/null +++ b/commands/owner/rfacebook.js @@ -0,0 +1,41 @@ +const { Command } = require('discord-akairo'); +const fetch = require('node-fetch'); +const { fbToken, fbID } = require('../../config.json'); + +class rfacebookCommand extends Command { + constructor() { + super('rfacebook', { + aliases: ['rfacebook', 'rfb'], + category: 'general', + args: [ + { + id: 'id', + type: 'string', + match: 'rest' + } + ], + description: { + content: 'Post your message to the bot rfacebook page', + usage: '[text]', + examples: ['epic'] + } + }); + } + + async exec(message, args) { + fetch(`https://graph.facebook.com/${fbID}_${args.id}?access_token=${fbToken}`, { + method: 'delete', + }).then((response) => { + return response.json(); + }).then((response) => { + console.log(response.success); + if (response.success) { + return message.channel.send('Sucessfully deleted the post'); + } else { + return message.channel.send('An error has occured :('); + } + }); + } +} + +module.exports = rfacebookCommand; \ No newline at end of file diff --git a/commands/owner/twitter/rtweet.js b/commands/owner/rtweet.js similarity index 96% rename from commands/owner/twitter/rtweet.js rename to commands/owner/rtweet.js index 9f57a16d..73d02fab 100644 --- a/commands/owner/twitter/rtweet.js +++ b/commands/owner/rtweet.js @@ -1,6 +1,6 @@ const { Command } = require('discord-akairo'); const Twitter = require('twitter-lite'); -const { twiConsumer, twiConsumerSecret, twiToken, twiTokenSecret } = require('../../../config.json'); +const { twiConsumer, twiConsumerSecret, twiToken, twiTokenSecret } = require('../../config.json'); class rtweetCommand extends Command { constructor() { diff --git a/commands/owner/twitter/uncensor.js b/commands/owner/uncensor.js similarity index 79% rename from commands/owner/twitter/uncensor.js rename to commands/owner/uncensor.js index 918b0750..ed10b9f7 100644 --- a/commands/owner/twitter/uncensor.js +++ b/commands/owner/uncensor.js @@ -30,9 +30,9 @@ class uncensorCommand extends Command { let words = []; let json = JSON.stringify(words); - fs.readFile('./json/twitter/uncensor.json', 'utf8', function readFileCallback(err, data) { + fs.readFile('./json/uncensor.json', 'utf8', function readFileCallback(err, data) { if (err) { - fs.writeFile('./json/twitter/uncensor.json', `["${word}"]`, function (err) { + fs.writeFile('./json/uncensor.json', `["${word}"]`, function (err) { if (err) { console.log(err); @@ -42,7 +42,7 @@ class uncensorCommand extends Command { words = JSON.parse(data); //now it an object words.push(word); json = JSON.stringify(words); //convert it back to json - fs.writeFile('./json/twitter/uncensor.json', json, 'utf8', function (err) { + fs.writeFile('./json/uncensor.json', json, 'utf8', function (err) { if (err) { return console.log(err); }