This commit is contained in:
cameron 2021-02-28 20:47:09 -05:00
parent 67e86200ed
commit 921b0690cc
4 changed files with 2059 additions and 305 deletions

View File

@ -2,11 +2,62 @@ const Discord = require("discord.js");
const fs = require('fs');
const request = require('request');
const rp = require('request-promise-native');
const sqlite = require('sqlite3');
const crypto = require('crypto');
class Lewd {
constructor() {
this.matches = [ "tits", "ass", "booty", "thicc", "2d", "furry", "sexy", "reddimg", "dick", "cock", "penis", "milf", "fuck", "sex", "degenerate", "milkers", "goth", "btgg" ];
try {
this.db = new sqlite.Database('./db/pr0n.db');
this.db.run('CREATE TABLE IF NOT EXISTS pr0n(id PRIMARY KEY, url, subreddit, author, title, reddit_ratio, discord_ratio, post_id, channel_id, guild_id)');
this.db.close();
} catch (e) {
console.log('Failed to open SQlite db for Lewd module! Data logging will not function.');
}
this.setReactionCollectors();
}
async setReactionCollectors() {
try {
const db = new sqlite.Database('./db/pr0n.db');
const results = db.all('SELECT post_id, channel_id, guild_id FROM pr0n', [], (err, rows) => {
if (err) {
throw err;
}
rows.forEach((r) => {
console.log(r.post_id);
});
});
db.close();
} catch (e) {
console.log('Failed to open SQlite db for Lewd module! Data logging will not function.');
db.close();
}
}
async fixOldEntries() {
try {
const db = new sqlite.Database('./db/pr0n.db');
const results = db.all('SELECT id, post_id, channel_id, guild_id, discord_ratio FROM pr0n WHERE discord_ratio=0.0', [], (err, rows) => {
if (err) {
throw err;
}
rows.forEach((r) => {
console.log(r);
});
});
db.close();
} catch (e) {
console.log('Failed to open SQlite db for Lewd module! Data logging will not function.');
db.close();
}
}
async loadSubreddit(name, desired_entries=400) {
@ -55,8 +106,13 @@ class Lewd {
for(let i = 0; i < 10; i++) {
let selection = Math.floor(Math.random() * count);
let url = srData[selection].data.url;
let selectionData = srData[selection].data;
let infoBundle = { url: selectionData.url, subreddit: selectionData.subreddit, author: selectionData.author, title: selectionData.title, upvote_ratio: selectionData.upvote_ratio };
if(url.endsWith('.jpg') || url.endsWith('.gif') || url.endsWith('.png') || url.endsWith('.jpeg') || url.includes('gfycat.com') ) {
return url.toString();
//return url.toString();
console.log(infoBundle);
return infoBundle;
}
}
@ -64,53 +120,125 @@ class Lewd {
}
async getRandomRedditImg(sub) {
let rEmbed = new Discord.RichEmbed();
let rEmbed = new Discord.MessageEmbed();
let img = await this.getRandomEntry(sub);
console.log(img);
if(img.includes('gfycat.com')) {
return img;
console.log(img.url);
if(img.url.includes('gfycat.com')) {
return img.url;
} else {
rEmbed.setImage(img);
rEmbed.setImage(img.url);
}
return rEmbed;
}
async sendAndLog(chan, sub) {
const db = new sqlite.Database('./db/pr0n.db');
const shasum = crypto.createHash('sha256');
let rEmbed = new Discord.MessageEmbed();
let imgInfo = await this.getRandomEntry(sub);
shasum.update(imgInfo.url);
const shaHash = shasum.digest('hex').slice(0,9);
if(imgInfo.url.includes('gfycat.com')) {
rEmbed = imgInfo.url;
} else {
rEmbed.setImage(imgInfo.url);
}
const sentMsg = await chan.send(rEmbed);
await sentMsg.react('\uD83D\uDC4D');
await sentMsg.react('\uD83D\uDC4E');
try {
db.run('INSERT INTO pr0n(id, url, subreddit, author, title, reddit_ratio, discord_ratio, post_id, channel_id, guild_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[
shaHash,
imgInfo.url,
imgInfo.subreddit,
imgInfo.author,
imgInfo.title,
imgInfo.upvote_ratio,
'0.0',
sentMsg.id,
sentMsg.channel.id,
sentMsg.guild.id
]);
} catch (e) {
console.log(e);
}
db.close();
}
async updateRating(messageID, new_ratio) {
const db = new sqlite.Database('./db/pr0n.db');
try {
db.run('UPDATE pr0n SET discord_ratio = ? WHERE post_id = ?',
[
new_ratio,
messageID
]);
} catch (e) {
console.log(e);
}
db.close();
}
async action(msg) {
let chan = msg.channel;
if(msg.content.startsWith('!tits')) {
chan.send(await this.getRandomRedditImg('homegrowntits+BigBoobsGW+Boobies+hugehangers+biggerthanyouthought+udders+tittydrop'));
await sendAndLog(chan,'homegrowntits+BigBoobsGW+Boobies+hugehangers+biggerthanyouthought+udders+tittydrop');
} else if (msg.content.startsWith('!booty') || msg.content.startsWith('!ass')) {
chan.send(await this.getRandomRedditImg('bigasses+pawg+slightcellulite'));
await this.sendAndLog(chan,'bigasses+pawg+slightcellulite');
} else if (msg.content.startsWith('!thicc')) {
chan.send(await this.getRandomRedditImg('thickthighs+voluptuous+breedingmaterial+thickchixx+plumper+gonewildplus+thickchixxx+bbw_chubby'));
await this.sendAndLog(chan,'thickthighs+voluptuous+breedingmaterial+thickchixx+plumper+gonewildplus+thickchixxx+bbw_chubby');
} else if (msg.content.startsWith('!2d')) {
chan.send(await this.getRandomRedditImg('hentai+rule34'));
await this.sendAndLog(chan,'hentai+rule34');
} else if (msg.content.startsWith('!furry')) {
chan.send(await this.getRandomRedditImg('furry+yiff'));
await this.sendAndLog(chan,'furry+yiff');
} else if (msg.content.startsWith('!sexy')) {
chan.send(await this.getRandomRedditImg('lingerie+gonemild'));
await this.sendAndLog(chan,'lingerie+gonemild');
} else if (msg.content.startsWith('!reddimg')) {
let contentArr = msg.content.split(" ");
if(contentArr.length < 2) return;
chan.send(await this.getRandomRedditImg(contentArr[1]));
await this.sendAndLog(chan,contentArr[1]);
} else if (msg.content.startsWith('!dick') || msg.content.startsWith('!cock') || msg.content.startsWith('!penis')) {
chan.send(await this.getRandomRedditImg('penis+massivecock+ratemycock+sizecomparison+averagepenis+naturalpenis+smallpenis'));
await this.sendAndLog(chan,'penis+massivecock+ratemycock+sizecomparison+averagepenis+naturalpenis+smallpenis');
} else if (msg.content.startsWith('!milf')) {
chan.send(await this.getRandomRedditImg('milf+wifesharing+gonewild30plus+milfie'));
await this.sendAndLog(chan,'milf+wifesharing+gonewild30plus+milfie');
} else if (msg.content.startsWith('!fuck') || msg.content.startsWith('!sex')) {
chan.send(await this.getRandomRedditImg('gonewildcouples+nsfw_gif+besthqporngifs+60fpsporn+girlsfinishingthejob+lipsthatgrip+amateurgirlsbigcocks+shelikesitrough'));
await this.sendAndLog(chan,'gonewildcouples+nsfw_gif+besthqporngifs+60fpsporn+girlsfinishingthejob+lipsthatgrip+amateurgirlsbigcocks+shelikesitrough');
} else if (msg.content.startsWith('!degenerate')) {
chan.send(await this.getRandomRedditImg('yiff+cuckold+hotwife+bondage+bdsm+bdsmgw+forcedorgasms+rule34+furry+dominated+teenbdsm+bondageblowjobs+fetish+cumsluts+vore'));
await this.sendAndLog(chan,'yiff+cuckold+hotwife+bondage+bdsm+bdsmgw+forcedorgasms+rule34+furry+dominated+teenbdsm+bondageblowjobs+fetish+cumsluts+vore');
} else if (msg.content.startsWith('!milkers')) {
chan.send(await this.getRandomRedditImg('udders+hugehangers+bigboobsgw+hugeboobs+hugetits+hugeboobgifs'));
await this.sendAndLog(chan,'udders+hugehangers+bigboobsgw+hugeboobs+hugetits+hugeboobgifs');
} else if (msg.content.startsWith('!goth')) {
chan.send(await this.getRandomRedditImg('gothsluts+bigtiddygothgf+snowwhites+altgonewild'));
await this.sendAndLog(chan,'gothsluts+bigtiddygothgf+snowwhites+altgonewild');
} else if (msg.content.startsWith('!btgg')) {
chan.send(await this.getRandomRedditImg('bigtiddygothgf'));
await this.sendAndLog(chan, 'bigtiddygothgf');
}
}
async react(reaction, user) {
console.log("***REACTION CAUGHT***");
const emojis = reaction.message.reactions.cache;
//console.log(emojis);
if(!emojis.has('\uD83D\uDC4D') || !emojis.has('\uD83D\uDC4E')) {
return;
}
const upCount = emojis.get('\uD83D\uDC4D').count;
const downCount = emojis.get('\uD83D\uDC4E').count;
console.log("Message ID" + reaction.message.id);
console.log("Upvotes: " + upCount);
console.log("Downvotes: " + downCount);
if (upCount+downCount > 2) {
await this.updateRating(reaction.message.id, upCount/(upCount+downCount));
}
}
}
module.exports = Lewd;

14
main.js
View File

@ -1,6 +1,6 @@
const Discord = require("discord.js");
const Gamedig = require('gamedig');
const client = new Discord.Client();
const client = new Discord.Client({ partials: ['REACTION', 'CHANNEL', 'MESSAGE'] });
const fs = require('fs');
const request = require('request');
const rp = require('request-promise-native');
@ -47,6 +47,18 @@ async function main() {
}
}
});
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.partial) {
try {
await reaction.fetch();
} catch (err) {
console.error(error);
return;
}
}
await bot_modules['lewd'].react(reaction, user);
});
}
main();

2177
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
"description": "",
"main": "main.js",
"dependencies": {
"discord.js": "^11.2.1",
"discord.js": "^12.5.1",
"gamedig": "^1.0.37",
"glob": "^7.1.2",
"markov": "0.0.7",
@ -12,6 +12,7 @@
"npm-init": "^1.3.1",
"request": "^2.83.0",
"request-promise-native": "^1.0.5",
"sqlite3": "^5.0.2",
"striptags": "^3.1.0",
"twitter": "^1.7.1"
},