Commit
This commit is contained in:
parent
6efbb811a3
commit
aff6c7158c
|
@ -7,7 +7,7 @@
|
||||||
"start": "node server.js"
|
"start": "node server.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"airtable": "^0.5.6",
|
"airtable": "^0.7.2",
|
||||||
"bignumber-to-string": "^0.1.4",
|
"bignumber-to-string": "^0.1.4",
|
||||||
"body-parser": "^1.18.3",
|
"body-parser": "^1.18.3",
|
||||||
"bootstrap": "^4.1.2",
|
"bootstrap": "^4.1.2",
|
||||||
|
|
64
server.js
64
server.js
|
@ -8,7 +8,7 @@ var ref = require('instagram-id-to-url-segment');
|
||||||
let date = require('date-and-time');
|
let date = require('date-and-time');
|
||||||
var urlSegmentToInstagramId = ref.urlSegmentToInstagramId;
|
var urlSegmentToInstagramId = ref.urlSegmentToInstagramId;
|
||||||
var Client = require('instagram-private-api').V1;
|
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');
|
var storage = new Client.CookieFileStorage(__dirname + '/cookies/anonbot.json');
|
||||||
const pngToJpeg = require('png-to-jpeg');
|
const pngToJpeg = require('png-to-jpeg');
|
||||||
var wrap = require('word-wrap');
|
var wrap = require('word-wrap');
|
||||||
|
@ -17,8 +17,8 @@ registerFont('./fonts/SourceCodePro-Regular.ttf', {family: 'SourceCodePro'});
|
||||||
const canvas = createCanvas(1080, 1080);
|
const canvas = createCanvas(1080, 1080);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
var Airtable = require('airtable');
|
var Airtable = require('airtable');
|
||||||
var logs = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('appDowHJJVQTHNJfk');
|
var logs = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('appX7lj3PyNGUSgXG');
|
||||||
var blacklist = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('applZHoMDx5uF9h1Z');
|
var blacklist = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base('appvLbOVAMuGU0btp');
|
||||||
var sha256 = require('crypto-js/sha256');
|
var sha256 = require('crypto-js/sha256');
|
||||||
|
|
||||||
function createSubmission(text, fillStyle, ip, isResponse, responseText, color) {
|
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);
|
if (exists && isResponse) publish(responseText, ip, isResponse, color);
|
||||||
else if (exists && !isResponse) publish(text, ip, isResponse, color);
|
else if (exists && !isResponse) publish(text, ip, isResponse, color);
|
||||||
})
|
})
|
||||||
}));
|
})).catch(function(rej) {
|
||||||
|
console.log(rej);
|
||||||
|
});
|
||||||
fs.unlinkSync('./submission.png');
|
fs.unlinkSync('./submission.png');
|
||||||
}
|
}
|
||||||
function createResponse(text, originalText, ip, color) {
|
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");
|
else createSubmission(originalText, '#404040', ip, true, text + "\n---\n" + originalText, "gray");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}));
|
})).catch(function(reg) {
|
||||||
|
console.log(reg);
|
||||||
|
});
|
||||||
fs.unlinkSync('./response.png');
|
fs.unlinkSync('./response.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,17 +94,21 @@ function publish(caption, ip, isResponse, color) {
|
||||||
data: './submission.jpeg'
|
data: './submission.jpeg'
|
||||||
}
|
}
|
||||||
], disabledComments = false;
|
], 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) {
|
.then(function(session) {
|
||||||
Client.Upload.album(session, photos)
|
Client.Upload.album(session, photos)
|
||||||
.then(function(payload) {
|
.then(function(payload) {
|
||||||
console.log("Uploaded new response!");
|
console.log("Uploaded new response!");
|
||||||
Client.Media.configureAlbum(session, payload, caption, disabledComments)
|
Client.Media.configureAlbum(session, payload, caption, disabledComments)
|
||||||
|
}).catch(function(reg) {
|
||||||
|
console.log(reg);
|
||||||
})
|
})
|
||||||
|
}).catch(function(reg) {
|
||||||
|
console.log(reg);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
.then(function(session) {
|
||||||
Client.Upload.photo(session, './submission.jpeg')
|
Client.Upload.photo(session, './submission.jpeg')
|
||||||
.then(function(upload) {
|
.then(function(upload) {
|
||||||
|
@ -109,7 +117,11 @@ function publish(caption, ip, isResponse, color) {
|
||||||
})
|
})
|
||||||
.then(function(medium) {
|
.then(function(medium) {
|
||||||
console.log("photo uploaded at " + medium.params.webLink);
|
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) {
|
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) {
|
.then(function(session) {
|
||||||
console.log("posted comment " + comment);
|
console.log("posted comment " + comment);
|
||||||
return Client.Comment.create(session, ''+id, comment);
|
return Client.Comment.create(session, ''+id, comment);
|
||||||
|
}).catch(function(reg) {
|
||||||
|
console.log(reg);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function postReponse(url, comment, ip) {
|
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) {
|
.then(function(session) {
|
||||||
return Client.Media.getByUrl(session, url)
|
return Client.Media.getByUrl(session, url)
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
getWhichColor().then(function(color) {
|
getWhichColor().then(function(color) {
|
||||||
createResponse(comment, data._params.caption, ip, 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) {
|
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) {
|
.then(function(session) {
|
||||||
return Client.Media.delete(session, ''+id);
|
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) {
|
function determineIfBanned(address) {
|
||||||
var banned = false;
|
var banned = false;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
/*
|
||||||
blacklist('Blacklist').select({
|
blacklist('Blacklist').select({
|
||||||
view: "Grid view"
|
view: "Grid view"
|
||||||
}).eachPage(function page(records, fetchNextPage) {
|
}).eachPage(function page(records, fetchNextPage) {
|
||||||
|
@ -182,18 +205,24 @@ function determineIfBanned(address) {
|
||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
resolve(banned);
|
resolve(banned);
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
|
resolve(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWhichColor() {
|
function getWhichColor() {
|
||||||
return new Promise(function(resolve, reject) {
|
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) {
|
.then(function(session) {
|
||||||
session.getAccount()
|
session.getAccount()
|
||||||
.then(function(account) {
|
.then(function(account) {
|
||||||
if (account.params.mediaCount % 2 === 0) resolve("gray");
|
if (account.params.mediaCount % 2 === 0) resolve("gray");
|
||||||
else resolve("red");
|
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) {
|
getWhichColor().then(function(color) {
|
||||||
if (color === "red") createSubmission(req.body.anon, '#b20000', getClientIP(req), false, "", "gray");
|
if (color === "red") createSubmission(req.body.anon, '#b20000', getClientIP(req), false, "", "gray");
|
||||||
else createSubmission(req.body.anon, '#404040', getClientIP(req), false, "", "red");
|
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);
|
//createSubmission(req.body.anon, '#404040', getClientIP(req), false);
|
||||||
return res.redirect('/submitted');
|
return res.redirect('/submitted');
|
||||||
|
@ -223,11 +255,11 @@ app.post("/postcomment", function(req, res) {
|
||||||
var commentType = commentString[1];
|
var commentType = commentString[1];
|
||||||
console.log("received comment " + comment + " type " + commentType + " on " + req.body.url);
|
console.log("received comment " + comment + " type " + commentType + " on " + req.body.url);
|
||||||
var shortcode = getShortcode(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) {
|
.then(function(session) {
|
||||||
return Client.Media.getByUrl(session, ''+req.body.url)
|
return Client.Media.getByUrl(session, ''+req.body.url)
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
if (data._params.user.username === "anonbot.wl") {
|
if (data._params.user.username === "anonbot3.wl") {
|
||||||
if (commentType === "comm") postComment(urlSegmentToInstagramId(shortcode), comment);
|
if (commentType === "comm") postComment(urlSegmentToInstagramId(shortcode), comment);
|
||||||
else postReponse(req.body.url, comment, getClientIP(req));
|
else postReponse(req.body.url, comment, getClientIP(req));
|
||||||
return res.redirect('/commented');
|
return res.redirect('/commented');
|
||||||
|
@ -242,6 +274,8 @@ app.post("/postcomment", function(req, res) {
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}).catch(function(reg) {
|
||||||
|
console.log(reg);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -288,6 +322,8 @@ app.get("/", function(request, response) {
|
||||||
determineIfBanned(getClientIP(request)).then(function(banned) {
|
determineIfBanned(getClientIP(request)).then(function(banned) {
|
||||||
if (banned) return response.sendFile(__dirname + '/views/banned.html');
|
if (banned) return response.sendFile(__dirname + '/views/banned.html');
|
||||||
else return response.sendFile(__dirname + '/views/index.html');
|
else return response.sendFile(__dirname + '/views/index.html');
|
||||||
|
}).catch(function(reg) {
|
||||||
|
console.log(reg);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
app.get("/submitted", function(request, response) {
|
app.get("/submitted", function(request, response) {
|
||||||
|
@ -303,6 +339,8 @@ app.get("/respond", function(request, response) {
|
||||||
determineIfBanned(getClientIP(request)).then(function(banned) {
|
determineIfBanned(getClientIP(request)).then(function(banned) {
|
||||||
if (banned) return response.sendFile(__dirname + '/views/banned.html');
|
if (banned) return response.sendFile(__dirname + '/views/banned.html');
|
||||||
else return response.sendFile(__dirname + '/views/respond.html');
|
else return response.sendFile(__dirname + '/views/respond.html');
|
||||||
|
}).catch(function(reg) {
|
||||||
|
console.log(reg);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
app.get("/commented", function(request, response) {
|
app.get("/commented", function(request, response) {
|
||||||
|
|
Loading…
Reference in New Issue