Migrate from local storage to remote PostgreSQL DB

This commit is contained in:
= 2021-07-21 22:00:17 -04:00
parent cd560395cc
commit a8489deb40
31 changed files with 91 additions and 126 deletions

View File

@ -1,10 +1,14 @@
const { emoji, weed } = require('../src/strings.json'); const { emoji } = require('../src/strings.json');
module.exports = { module.exports = {
name: 'joint', name: 'joint',
description: 'Pass the joint!', description: 'Pass the joint!',
execute(message, args) { execute(message, args) {
const randIndex = Math.floor(Math.random() * weed.length); let phrases = [];
message.channel.send(`${weed[randIndex]} ${emoji.joint}`); for (const entry of message.client.potphrases.map(potphrase => potphrase.content)) {
phrases.push(entry);
}
const randIndex = Math.floor(Math.random() * phrases.length);
message.channel.send(`${phrases[randIndex]} ${emoji.joint}`);
} }
} }

View File

@ -1,14 +1,12 @@
const { weed } = require('../src/strings.json');
module.exports = { module.exports = {
name: 'joints', name: 'joints',
description: 'Get a list of the phrases saved for .joint', description: 'Get a list of the phrases saved for .joint',
execute(message, file) { execute(message, file) {
let data = []; let phrases = [];
for (const phrase of weed) { for (const phrase of message.client.potphrases.map(potphrase => potphrase.content)) {
data.push(phrase); phrases.push(phrase);
} }
message.channel.send('Here are all the `.joint` phrases I have saved:\n\n' + data.join('\n')); message.channel.send('Here are all the `.joint` phrases I have saved:\n\n' + phrases.join('\n'));
} }
} }

11
commands/upload.js Normal file
View File

@ -0,0 +1,11 @@
module.exports = {
name: 'upload',
description: '',
execute(message, file) {
const fn = require('../functions');
fn.uploadGIFs(message);
message.reply('Uploaded, I hope.');
}
}

View File

@ -1,9 +1,17 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const fs = require('fs'); const fs = require('fs');
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const gifFiles = fs.readdirSync('./gifs').filter(file => file.endsWith('.js'));
const pastaFiles = fs.readdirSync('./pastas').filter(file => file.endsWith('.js'));
const config = require('./config.json'); const config = require('./config.json');
const pg = require('pg');
let dbConnected = false;
const db = new pg.Client({
connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
}
});
db.connect();
module.exports = { module.exports = {
setValidExtensions(client) { setValidExtensions(client) {
@ -20,20 +28,61 @@ module.exports = {
}, },
getGifFiles(client) { getGifFiles(client) {
client.gifs = new Discord.Collection(); client.gifs = new Discord.Collection();
for (const file of gifFiles) {
const gif = require(`./gifs/${file}`); const query = "SELECT name, embed_url FROM gifs";
client.gifs.set(gif.name, gif); return new Promise((resolve, reject) => {
} db.query(query)
.then(res => {
for (let row of res.rows) {
const gif = {
name: row.name,
embed_url: row.embed_url
};
client.gifs.set(gif.name, gif);
}
resolve();
})
.catch(err => console.error(err));
});
},
getPotPhrases(client) {
client.potphrases = new Discord.Collection();
const query = "SELECT id, content FROM potphrases";
db.query(query)
.then(res => {
for (let row of res.rows) {
const potphrase = {
id: row.id,
content: row.content
};
client.potphrases.set(potphrase.id, potphrase);
}
})
.catch(err => console.error(err));
}, },
getPastaFiles(client) { getPastaFiles(client) {
client.pastas = new Discord.Collection(); client.pastas = new Discord.Collection();
for (const file of pastaFiles) {
const pasta = require(`./pastas/${file}`); const query = "SELECT name, content FROM pastas";
client.pastas.set(pasta.name, pasta); return new Promise((resolve, reject) => {
} db.query(query)
.then(res => {
for (let row of res.rows) {
const pasta = {
name: row.name,
content: row.content
};
client.pastas.set(pasta.name, pasta);
}
resolve();
})
.catch(err => console.error(err));
});
}, },
getFileInfo(content) { getFileInfo(content) {
// const finalPeriod = content.search(/\.(?:.(?!\\))+$/gim); // Split the message content at the final instance of a period
const finalPeriod = content.lastIndexOf('.'); const finalPeriod = content.lastIndexOf('.');
if (finalPeriod < 0) return false; if (finalPeriod < 0) return false;
const extension = content.slice(finalPeriod).replace('.','').toLowerCase(); const extension = content.slice(finalPeriod).replace('.','').toLowerCase();
@ -48,8 +97,8 @@ module.exports = {
const extensions = require('./config.json').validExtensions; const extensions = require('./config.json').validExtensions;
return extensions.includes(extension); return extensions.includes(extension);
}, },
cleanInput(input) { cleanInput(string) {
return input.replace(/'/g, '\\\'').replace(/\n/g, '\\n'); return string.replace(/'/g, "''").replace(/\n/g, '\\n');
}, },
createGifEmbed(data, author, command) { createGifEmbed(data, author, command) {
return new Discord.MessageEmbed() return new Discord.MessageEmbed()
@ -183,5 +232,11 @@ module.exports = {
.setDescription(list.join('\n')) .setDescription(list.join('\n'))
.setTimestamp() .setTimestamp()
.setFooter(`@${message.author.username}#${message.author.discriminator}`); .setFooter(`@${message.author.username}#${message.author.discriminator}`);
},
uploadGIF(name, embed_url) {
const query = `INSERT INTO gifs (name, embed_url) VALUES ('${name}','${embed_url})'`;
db.query(query)
.then()
.catch(e => console.error(e));
} }
} }

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'psh',
embed_url: 'https://media.tenor.com/images/c88d8cdde582c01cb1396db7f01023eb/tenor.gif'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'shedsalive',
embed_url: 'https://media.giphy.com/media/glL1yvxJ4KvYc/source.gif'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'test',
embed_url: 'https://media.tenor.com/images/0f097ed319d498c2bda3d87ba4f6ff10/tenor.gif'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'unreal',
embed_url: 'https://media.tenor.com/images/5ff1d1ef874429a81db93a15d49f208c/tenor.gif'
}

View File

@ -18,6 +18,7 @@ client.once('ready', () => {
functions.getCommandFiles(client); functions.getCommandFiles(client);
functions.getGifFiles(client); functions.getGifFiles(client);
functions.getPastaFiles(client); functions.getPastaFiles(client);
functions.getPotPhrases(client);
functions.setValidExtensions(client); functions.setValidExtensions(client);
// Get the owner and DM them a message that the bot is ready, useful for remote deployment // Get the owner and DM them a message that the bot is ready, useful for remote deployment
client.users.fetch(process.env.ownerID).then(user => { client.users.fetch(process.env.ownerID).then(user => {

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'bot',
content: 'NodBot v2 Starting Up'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'burn',
content: 'Find your nearest burn center: https://ameriburn.org/public-resources/find-a-burn-center/'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'cat',
content: '⣿⣿⣿⠟⠛⠛⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⢋⣩⣉⢻ ⣿⣿⣿⠀⣿⣶⣕⣈⠹⠿⠿⠿⠿⠟⠛⣛⢋⣰⠣⣿⣿⠀⣿ ⣿⣿⣿⡀⣿⣿⣿⣧⢻⣿⣶⣷⣿⣿⣿⣿⣿⣿⠿⠶⡝⠀⣿ ⣿⣿⣿⣷⠘⣿⣿⣿⢏⣿⣿⣋⣀⣈⣻⣿⣿⣷⣤⣤⣿⡐⢿ ⣿⣿⣿⣿⣆⢩⣝⣫⣾⣿⣿⣿⣿⡟⠿⠿⠦⠀⠸⠿⣻⣿⡄⢻ ⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⠇⣼ ⣿⣿⣿⣿⣿⣿⡄⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣰ ⣿⣿⣿⣿⣿⣿⠇⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣿ ⣿⣿⣿⣿⣿⠏⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢸⣿ ⣿⣿⣿⣿⠟⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⣿ ⣿⣿⣿⠋⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⣿ ⣿⣿⠋⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'cat2',
content: '⣿⣿⣿⠟⠛⠛⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⢋⣩⣉⢻\n\n⣿⣿⣿⣿⣶⣕⣈⠹⠿⠿⠿⠿⠟⠛⣛⢋⣰⠣⣿⣿⣿\n\n⣿⣿⣿⡀⣿⣿⣿⣧⢻⣿⣶⣷⣿⣿⣿⣿⣿⣿⠿⠶⡝⣿\n\n⣿⣿⣿⣷⠘⣿⣿⣿⢏⣿⣿⣋⣀⣈⣻⣿⣿⣷⣤⣤⣿⡐⢿\n\n⣿⣿⣿⣿⣆⢩⣝⣫⣾⣿⣿⣿⣿⡟⠿⠿⠦⠸⠿⣻⣿⡄⢻\n\n⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⠇⣼\n\n⣿⣿⣿⣿⣿⣿⡄⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣰\n\n⣿⣿⣿⣿⣿⣿⠇⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣿\n\n⣿⣿⣿⣿⣿⠏⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢸⣿\n\n⣿⣿⣿⣿⠟⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n\n⣿⣿⣿⠋⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⣿\n\n⣿⣿⠋⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'cat3',
content: '⣿⣿⣿⠟⠛⠛⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⢋⣩⣉⢻\n⣿⣿⣿⣿⣶⣕⣈⠹⠿⠿⠿⠿⠟⠛⣛⢋⣰⠣⣿⣿⣿\n⣿⣿⣿⡀⣿⣿⣿⣧⢻⣿⣶⣷⣿⣿⣿⣿⣿⣿⠿⠶⡝⣿\n⣿⣿⣿⣷⠘⣿⣿⣿⢏⣿⣿⣋⣀⣈⣻⣿⣿⣷⣤⣤⣿⡐⢿\n⣿⣿⣿⣿⣆⢩⣝⣫⣾⣿⣿⣿⣿⡟⠿⠿⠦⠸⠿⣻⣿⡄⢻\n⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⠇⣼\n⣿⣿⣿⣿⣿⣿⡄⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣰\n⣿⣿⣿⣿⣿⣿⠇⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣿\n⣿⣿⣿⣿⣿⠏⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢸⣿\n⣿⣿⣿⣿⠟⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⠋⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⣿\n⣿⣿⠋⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'cumcoin',
content: 'YOOOO CUM SHIT & PISS TOKEN IS GOING TO THE MOON 🚀 🌙\n\n$CUMSHITPISS 👍👍👍👀\n\nThis is a project Ive fully believed in for at least 13 seconds 💰 💴 💵\n\n🚀 LETS GOOOOOOOOOOOO 🚀\n\nGet on now before you miss out 😂you dont wanna stay poor do you??😂 (NOT FINANCIAL'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'dickhang',
content: 'Should I cut a hole in my mattress for my dick to hang in while sleeping at night?\n\nIm a stomach sleeper and all that weight on my massive bulge is uncomfortable. So what if I cut a hole in the middle of my mattress so my dick can just hang down there at night?\n\nCould this deform my dick in some way? Since all that blood would rush to the tip, could it make my dick look like a maraca?'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'gaminglaptops',
content: 'Today when I walked into my economics class I saw something I dread every time I close my eyes. Someone had brought their new gaming laptop to class. The Forklift he used to bring it was still running idle at the back. I started sweating as I sat down and gazed over at the 700lb beast that was his laptop. He had already reinforced his desk with steel support beams and was in the process of finding an outlet for a power cable thicker than Amy Schumer\'s thigh. I start shaking. I keep telling myself I\'m going to be alright and that there\'s nothing to worry about. He somehow finds a fucking outlet. Tears are running down my cheeks as I send my last texts to my family saying I love them. The teacher starts the lecture, and the student turns his laptop on. The colored lights on his RGB Backlit keyboard flare to life like a nuclear flash, and a deep humming fills my ears and shakes my very soul. The entire city power grid goes dark. The classroom begins to shake as the massive fans begin to spin. In mere seconds my world has gone from vibrant life, to a dark, earth shattering void where my body is getting torn apart by the 150mph gale force winds and the 500 decibel groan of the cooling fans. As my body finally surrenders, I weep, as my school and my city go under. I fucking hate gaming laptops.'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'lenny',
content: '( ͡° ͜ʖ ͡°)'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'matt',
content: 'PISS OUT MY ASS'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'mlm',
content: 'Hey👋 ladies💁 📷 Would 😍 you 👈 like 👍 to 2⃣ get 😮 rich 💰💰💰 by running 🏃‍♀️🏃‍♀️ your 👈 own business 👩‍💼💼 from home 🏡 with just ☝ your phone? 📱🤳 Well 🤷‍♀️ you can\'t. 😂 Get 👏 a 👏 real 👏 job 👏 you 👏 stupid 👏 cunt'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'pridemonth',
content: '🚨ALERT🚨 🚨ALERT🚨\n\nPRIDE 🏳️‍🌈 MONTH🗓 IS OFFICIALLY OVER❌\n\nMEN ♂️ AND WOMEN ♀️ OF THE NATION🇨🇮🇧🇼🇧🇿🇨🇲🇧🇷🇨🇨🇨🇲🇨🇰🇨🇫🇨🇮🇫🇰🇪🇦🇪🇹🇫🇮🇩🇯🇫🇲🇭🇲🇬🇵🇮🇪🇮🇱🇮🇲🇬🇹🇮🇴🇭🇰🇬🇾🇲🇵🇱🇷🇲🇴🇲🇨🇱🇻🇲🇱🇲🇱🇳🇮🇵🇭🇴🇲🇳🇺🇴🇲🇳🇪🇵🇪🇵🇫🇳🇦🇸🇭🇸🇽🇶🇦🇸🇬🇶🇦🇸🇪🇸🇸🇸🇽🇸🇭:\n\nIT IS NOW ILLEGAL TO BE #GAY 🏳️‍🌈 ANYWHERE ON STRAIGHT📏 MOTHER EARTH 🌎🌐🌍🌏\n\nBISEXUALS MUST HEAD TO YOUR NEAREST GOVERNMENT BUILDING 🎟 AND RECEIVE A "Bi-Ticket Admission Allowance System Check in Mark" TO BE PUT UNDER EXAMINATION 🔍 TO DETERMINE IF YOU ARE TO BE LEFT IN THE GENE POOL. 🤽‍♂️🤽‍♀️\n\nTHE 🏳🌈❌GAYSTAPO❌🏳🌈 👮‍♂️👮‍♂️🚔🚔 WILL BE INSPECTING ALL RESIDENTS🏘 OF THE UNITED STATES OF AMERICA 🇳🇺🇳🇺🇳🇺 TO SEARCH FOR ANY GAY ACTIVITY\n\nANY HOMOSEXUAL ACTIVITY CAN WARRANT ARREST🔒👮OR POSSIBLE ☠DEATH☠ PENALTY\n\nSTAY VIGILANT AND STRAIGHT📏📏❌🏳🌈❌🏳🌈❌🏳🌈❌🏳🌈❌'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'realestateagent',
content: 'What if their agent is actually their polymorous third partner and is in on it? They don\'t actually want to buy a house and he\'s not actually a real estate agent, they just put in offers, view the house, have a nasty 3some, complain to come back a couple times, then eventually cancel the offer.\n\nIt\'s classic, I\'ve seen it a million times'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'ruccoa',
content: 'what if it just said "Ruccoa: shid fard cumb" instead of 2 lines'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'seal',
content: 'What the fuck did you just fucking say about me, you little bitch? I\'ll have you know I graduated top of my class in the Navy Seals, and I\'ve been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I\'m the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You\'re fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that\'s just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little "clever" comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn\'t, you didn\'t, and now you\'re paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You\'re fucking dead, kiddo.'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'shid',
content: 'shid, fard and cumb'
}

File diff suppressed because one or more lines are too long

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'syntax',
content: 'Eat a bag of dicks'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'test',
content: 'afsd\'adsf\'asdf\'afdsdsfa\'f"dfsa\'adsf\'adsf\ndfs\'asdf\'f\'a\ndafssd\'afds\'sdf'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'trump',
content: 'How Trump Can Stay in Office:\nunder section 34 of Secure Credits and Taxes act, the president can induce artificial inflation and if the inflation gets high enough, technically Trump can declare emergency powers and not leave the office, google "Trump SCAT inflation rule 34" for more info'
}

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'wupup',
content: 'You see this WUPUP right here? So, this means that southwest of WUPUP up to 30 miles between the 003 course-to and the 093 course is this quadrant, southwest of WUPUP. Once you hit 30 miles from WUPUP you can descend to 3600 feet, then you go cross WUPUP at 3600 feet, then down to 3200 feet and continue.'
};

View File

@ -1,4 +0,0 @@
module.exports = {
name: 'xplane',
content: 'I\'d just like to interject for a moment. What youre referring to as X-Plane, is in fact, Mods/X-Plane, or as Ive recently taken to calling it, Mods plus X-Plane. X-Plane is not a flight sim unto itself, but rather another component of a fully functioning mod system made useful by the mod HD Mesh Scenery, ActiveSky and vital system components comprising a full sim as defined by the flight sim community.\n\nMany sim users run a modified version of the mod system every day, without realizing it. Through a peculiar turn of events, the version of mods which is widely used today is often called “X-Plane”, and many of its users are not aware that it is basically the mods system, developed by the mod developers. There really is a X-Plane, and these people are using it, but it is just a part of the system they use.\n\nX-Plane is the platform: the program in the system that allocates the machines resources to the other mods that you run. The platform is an essential part of a sim, but useless by itself; it can only function in the context of a complete flight sim. X-Plane is normally used in combination with the mod system: the whole system is basically mods with X-Plane added, or mod/X-Plane. All the so-called “X-Plane” distributions are really distributions of mod/X-Plane.'
}