Moved thing arround and now able to post to facebook

This commit is contained in:
Supositware 2019-02-28 17:35:53 +01:00
parent 3e40f07e46
commit 376fdb790b
6 changed files with 114 additions and 10 deletions

View file

@ -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;

View file

@ -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)) {

View file

@ -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);
}

View file

@ -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;

View file

@ -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() {

View file

@ -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);
}