From aff6c7158c5b64566a5062967e3aa57707936352 Mon Sep 17 00:00:00 2001 From: PaperStaple Date: Sun, 3 Nov 2019 21:06:44 -0800 Subject: [PATCH] Commit --- package.json | 2 +- server.js | 64 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 296a533..1e3d72f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "node server.js" }, "dependencies": { - "airtable": "^0.5.6", + "airtable": "^0.7.2", "bignumber-to-string": "^0.1.4", "body-parser": "^1.18.3", "bootstrap": "^4.1.2", diff --git a/server.js b/server.js index b63b699..2a1afe9 100644 --- a/server.js +++ b/server.js @@ -8,7 +8,7 @@ var ref = require('instagram-id-to-url-segment'); let date = require('date-and-time'); var urlSegmentToInstagramId = ref.urlSegmentToInstagramId; var Client = require('instagram-private-api').V1; -var device = new Client.Device('anonbot.wl'); +var device = new Client.Device('anonbot3.wl'); var storage = new Client.CookieFileStorage(__dirname + '/cookies/anonbot.json'); const pngToJpeg = require('png-to-jpeg'); var wrap = require('word-wrap'); @@ -17,8 +17,8 @@ registerFont('./fonts/SourceCodePro-Regular.ttf', {family: 'SourceCodePro'}); const canvas = createCanvas(1080, 1080); const ctx = canvas.getContext('2d'); var Airtable = require('airtable'); -var logs = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('appDowHJJVQTHNJfk'); -var blacklist = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('applZHoMDx5uF9h1Z'); +var logs = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('appX7lj3PyNGUSgXG'); +var blacklist = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('appvLbOVAMuGU0btp'); var sha256 = require('crypto-js/sha256'); function createSubmission(text, fillStyle, ip, isResponse, responseText, color) { @@ -43,7 +43,9 @@ function createSubmission(text, fillStyle, ip, isResponse, responseText, color) if (exists && isResponse) publish(responseText, ip, isResponse, color); else if (exists && !isResponse) publish(text, ip, isResponse, color); }) - })); + })).catch(function(rej) { + console.log(rej); + }); fs.unlinkSync('./submission.png'); } function createResponse(text, originalText, ip, color) { @@ -72,7 +74,9 @@ function createResponse(text, originalText, ip, color) { else createSubmission(originalText, '#404040', ip, true, text + "\n---\n" + originalText, "gray"); } }) - })); + })).catch(function(reg) { + console.log(reg); + }); fs.unlinkSync('./response.png'); } @@ -90,17 +94,21 @@ function publish(caption, ip, isResponse, color) { data: './submission.jpeg' } ], disabledComments = false; - Client.Session.create(device, storage, 'anonbot.wl', process.env.ANON_PASSWORD) + Client.Session.create(device, storage, 'anonbot3.wl', process.env.ANON_PASSWORD) .then(function(session) { Client.Upload.album(session, photos) .then(function(payload) { console.log("Uploaded new response!"); Client.Media.configureAlbum(session, payload, caption, disabledComments) + }).catch(function(reg) { + console.log(reg); }) + }).catch(function(reg) { + console.log(reg); }) } else { - Client.Session.create(device, storage, 'anonbot.wl', process.env.ANON_PASSWORD) + Client.Session.create(device, storage, 'anonbot3.wl', process.env.ANON_PASSWORD) .then(function(session) { Client.Upload.photo(session, './submission.jpeg') .then(function(upload) { @@ -109,7 +117,11 @@ function publish(caption, ip, isResponse, color) { }) .then(function(medium) { console.log("photo uploaded at " + medium.params.webLink); + }).catch(function(reg) { + console.log(reg); }) + }).catch(function(reg) { + console.log(reg); }); } @@ -117,29 +129,39 @@ function publish(caption, ip, isResponse, color) { } function postComment(id, comment) { - Client.Session.create(device, storage, 'anonbot.wl', process.env.ANON_PASSWORD) + Client.Session.create(device, storage, 'anonbot3.wl', process.env.ANON_PASSWORD) .then(function(session) { console.log("posted comment " + comment); return Client.Comment.create(session, ''+id, comment); + }).catch(function(reg) { + console.log(reg); }) } function postReponse(url, comment, ip) { - Client.Session.create(device, storage, 'anonbot.wl', process.env.ANON_PASSWORD) + Client.Session.create(device, storage, 'anonbot3.wl', process.env.ANON_PASSWORD) .then(function(session) { return Client.Media.getByUrl(session, url) .then(function(data) { getWhichColor().then(function(color) { createResponse(comment, data._params.caption, ip, color); + }).catch(function(reg) { + console.log(reg); }) + }).catch(function(reg) { + console.log(reg); }) + }).catch(function(reg) { + console.log(reg); }) } function delPost(id) { - Client.Session.create(device, storage, 'anonbot.wl', process.env.ANON_PASSWORD) + Client.Session.create(device, storage, 'anonbot3.wl', process.env.ANON_PASSWORD) .then(function(session) { return Client.Media.delete(session, ''+id); + }).catch(function(reg) { + console.log(reg); }) } @@ -168,6 +190,7 @@ function getClientIP(req){ // Anonbot logs IPs for safety & moderation function determineIfBanned(address) { var banned = false; return new Promise(function(resolve, reject) { + /* blacklist('Blacklist').select({ view: "Grid view" }).eachPage(function page(records, fetchNextPage) { @@ -182,18 +205,24 @@ function determineIfBanned(address) { if (err) reject(err); resolve(banned); }) + */ + resolve(false) }) } function getWhichColor() { return new Promise(function(resolve, reject) { - Client.Session.create(device, storage, 'anonbot.wl', process.env.ANON_PASSWORD) + Client.Session.create(device, storage, 'anonbot3.wl', process.env.ANON_PASSWORD) .then(function(session) { session.getAccount() .then(function(account) { if (account.params.mediaCount % 2 === 0) resolve("gray"); else resolve("red"); + }).catch(function(reg) { + console.log(reg); }) + }).catch(function(reg) { + console.log(reg); }) }) } @@ -213,6 +242,9 @@ app.post("/submission", function(req, res) { getWhichColor().then(function(color) { if (color === "red") createSubmission(req.body.anon, '#b20000', getClientIP(req), false, "", "gray"); else createSubmission(req.body.anon, '#404040', getClientIP(req), false, "", "red"); + }).catch(function(reg) { + console.log(reg); + console.log("Line 247"); }) //createSubmission(req.body.anon, '#404040', getClientIP(req), false); return res.redirect('/submitted'); @@ -223,11 +255,11 @@ app.post("/postcomment", function(req, res) { var commentType = commentString[1]; console.log("received comment " + comment + " type " + commentType + " on " + req.body.url); var shortcode = getShortcode(req.body.url); - Client.Session.create(device, storage, 'anonbot.wl', process.env.ANON_PASSWORD) + Client.Session.create(device, storage, 'anonbot3.wl', process.env.ANON_PASSWORD) .then(function(session) { return Client.Media.getByUrl(session, ''+req.body.url) .then(function(data) { - if (data._params.user.username === "anonbot.wl") { + if (data._params.user.username === "anonbot3.wl") { if (commentType === "comm") postComment(urlSegmentToInstagramId(shortcode), comment); else postReponse(req.body.url, comment, getClientIP(req)); return res.redirect('/commented'); @@ -242,6 +274,8 @@ app.post("/postcomment", function(req, res) { return res.redirect('/'); } }) + }).catch(function(reg) { + console.log(reg); }) }); @@ -288,6 +322,8 @@ app.get("/", function(request, response) { determineIfBanned(getClientIP(request)).then(function(banned) { if (banned) return response.sendFile(__dirname + '/views/banned.html'); else return response.sendFile(__dirname + '/views/index.html'); + }).catch(function(reg) { + console.log(reg); }) }); app.get("/submitted", function(request, response) { @@ -303,6 +339,8 @@ app.get("/respond", function(request, response) { determineIfBanned(getClientIP(request)).then(function(banned) { if (banned) return response.sendFile(__dirname + '/views/banned.html'); else return response.sendFile(__dirname + '/views/respond.html'); + }).catch(function(reg) { + console.log(reg); }) }); app.get("/commented", function(request, response) {