Last active
September 22, 2020 15:06
-
-
Save theabbie/250f2c0456bf4c81be2123e776530271 to your computer and use it in GitHub Desktop.
Bot that searches and posts memes for you
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('express')(); | |
var devRant = require("rantscript"); | |
const Fs = require('fs') | |
const Path = require('path') | |
const Axios = require('axios') | |
const cheerio = require("cheerio") | |
async function load(url) { | |
const writer = Fs.createWriteStream("meme.jpg") | |
const response = await Axios({ | |
url, | |
method: 'GET', | |
responseType: 'stream' | |
}) | |
response.data.pipe(writer) | |
return new Promise((resolve, reject) => { | |
writer.on('finish', resolve) | |
writer.on('error', reject) | |
}) | |
} | |
app.get("/*", async function(req,res) { | |
try { | |
var token = (await devRant.login('memesbot', process.env.devpass))["auth_token"] | |
var notifs = await devRant.notifications(token); | |
for (x of notifs.data.items) { | |
if (x.type=="comment_mention" && x.read==0) { | |
var rant = (await devRant.rant(x["rant_id"],token)).comments; | |
for (p of rant) { | |
if (p.id==x["comment_id"]) { | |
var $ = cheerio.load((await Axios("https://www.google.com/search?tbm=isch&q="+p.body.split("@memesbot").join("")+" site:https://knowyourmeme.com/")).data); | |
await load($("img").eq(1)[0].attribs["src"]); | |
var comment = await devRant.postComment("@"+p["user_username"],x["rant_id"],token,"meme.jpg"); | |
} | |
} | |
} | |
} | |
res.end(JSON.stringify(notifs,null,2)) | |
} | |
catch (e) { | |
res.end(e.message); | |
} | |
}) | |
app.listen(process.env.PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment