From 3dfe642e90d9d1b700a77609aad7f7005dffce4a Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Tue, 17 Jan 2023 19:35:24 -0500 Subject: [PATCH] Initial Commit --- .DS_Store | Bin 0 -> 6148 bytes .dockerignore | 5 + .eslintrc.json | 49 +++ .github/workflows/docker-image.yml | 26 ++ .gitignore | 117 ++++++ CHANGELOG.md | 12 + Dockerfile | 8 + README.md | 100 +++++ Roadmap.md | 14 + _clear-commands.js | 27 ++ _deploy-commands.js | 40 ++ _deploy-global.js | 39 ++ config.json | 4 + dot-commands/.DS_Store | Bin 0 -> 6148 bytes dot-commands/spongebob.js | 30 ++ functions.js | 576 +++++++++++++++++++++++++++++ main.js | 217 +++++++++++ package.json | 33 ++ slash-commands/.DS_Store | Bin 0 -> 6148 bytes slash-commands/template | 11 + strings.json | 18 + 21 files changed, 1326 insertions(+) create mode 100644 .DS_Store create mode 100644 .dockerignore create mode 100644 .eslintrc.json create mode 100644 .github/workflows/docker-image.yml create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 Roadmap.md create mode 100644 _clear-commands.js create mode 100644 _deploy-commands.js create mode 100644 _deploy-global.js create mode 100644 config.json create mode 100644 dot-commands/.DS_Store create mode 100644 dot-commands/spongebob.js create mode 100644 functions.js create mode 100644 main.js create mode 100644 package.json create mode 100644 slash-commands/.DS_Store create mode 100644 slash-commands/template create mode 100644 strings.json diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..18a8805e0fc79fa1c77c577c18e030e6247f1c35 GIT binary patch literal 6148 zcmeHKF;2rk5S)b+k%&-A%KHEXKR89n3-|yK7Ze5;CcQhp&FtPHB{E4#0khWL`1W@0 z>?yon0Jb@F55OA0lJ1C4ALi!k?lZf}h@-_GdklEv^^Esf_Rj(5uF#S9fqNYDJB;19 z?_Y+Ycj_%h^xSyF>-j`Jg-i-a0VyB_q<|E-s6bZB<;}$`ElL3?@E;ZM??a(G*2Jk{ zd^$Kp3qV{j9LD?TC5XiX#F{uYWQ1moN^Dfi7Q-5y@sfEpacbD;usE6f@zh8m@S6gXAjx=q(!|9A8={r@RRGbtbi{*(f?*gkGIe5I_dvzPN)Tj)>pZ)0wx nbBIz*j8e>rm*TslyyEv +isDev= +dbHost= +dbPort= +dbUser= +dbPass= +dbName= +tenorAPIKey= +ownerId= +statusChannelId= +clientId= +``` \ No newline at end of file diff --git a/Roadmap.md b/Roadmap.md new file mode 100644 index 0000000..80bce7b --- /dev/null +++ b/Roadmap.md @@ -0,0 +1,14 @@ +# v3.1.0 + +* Name checking for saving content +* .jpg, .wav +* Audio/Video attachments for saved content. +* Pass The Joint +* Voting system for Super Adventure Club + +# v4.0.0 +* Scalability: modify the code to allow the bot to be used in multiple servers + * including saved content, saved commands, preferences, etc. + +# v3.?.? += Joke generator for Hallihan \ No newline at end of file diff --git a/_clear-commands.js b/_clear-commands.js new file mode 100644 index 0000000..869c90d --- /dev/null +++ b/_clear-commands.js @@ -0,0 +1,27 @@ +// dotenv for handling environment variables +const dotenv = require('dotenv'); +dotenv.config(); + +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +const clientId = process.env.clientId; +const { guildId } = require('../config.json'); +const token = process.env.TOKEN; + +const rest = new REST({ version: '9' }).setToken(token); + +(async () => { + try { + console.log('Started refreshing application (/) commands.'); + + await rest.put( + Routes.applicationGuildCommands(clientId, guildId), + { body: '' }, + ); + + console.log('Successfully reloaded application (/) commands.'); + process.exit(); + } catch (error) { + console.error(error); + } +})(); \ No newline at end of file diff --git a/_deploy-commands.js b/_deploy-commands.js new file mode 100644 index 0000000..5ba21ce --- /dev/null +++ b/_deploy-commands.js @@ -0,0 +1,40 @@ +// dotenv for handling environment variables +const dotenv = require('dotenv'); +dotenv.config(); + +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +const { guildId } = require('./config.json'); +const clientId = process.env.clientId; +const token = process.env.TOKEN; +const fs = require('fs'); + +const commands = []; +const commandFiles = fs.readdirSync('./slash-commands').filter(file => file.endsWith('.js')); + +for (const file of commandFiles) { + const command = require(`./slash-commands/${file}`); + if (command.data != undefined) { + commands.push(command.data.toJSON()); + } +} + +console.log(commands); + +const rest = new REST({ version: '9' }).setToken(token); + +(async () => { + try { + console.log('Started refreshing application (/) commands.'); + + await rest.put( + Routes.applicationGuildCommands(clientId, guildId), + { body: commands }, + ); + + console.log('Successfully reloaded application (/) commands.'); + process.exit(); + } catch (error) { + console.error(error); + } +})(); \ No newline at end of file diff --git a/_deploy-global.js b/_deploy-global.js new file mode 100644 index 0000000..cd7b8ce --- /dev/null +++ b/_deploy-global.js @@ -0,0 +1,39 @@ +// dotenv for handling environment variables +const dotenv = require('dotenv'); +dotenv.config(); + +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +const clientId = process.env.clientId; +const token = process.env.TOKEN; +const fs = require('fs'); + +const commands = []; +const commandFiles = fs.readdirSync('./slash-commands').filter(file => file.endsWith('.js')); + +for (const file of commandFiles) { + const command = require(`./slash-commands/${file}`); + if (command.data != undefined) { + commands.push(command.data.toJSON()); + } +} + +console.log(commands); + +const rest = new REST({ version: '9' }).setToken(token); + +(async () => { + try { + console.log('Started refreshing application (/) commands.'); + + await rest.put( + Routes.applicationCommands(clientId), + { body: commands }, + ); + + console.log('Successfully reloaded application (/) commands.'); + process.exit(); + } catch (error) { + console.error(error); + } +})(); \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..b9087cf --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "guildId": "868542949737246730", + "validCommands": [] +} \ No newline at end of file diff --git a/dot-commands/.DS_Store b/dot-commands/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0.spongebob', + execute(message, commandData) { + // message.reply(fn.spongebob(commandData)).then(() => { + // message.delete(); + // }); + if (message.reference != undefined) { + const repliedMessageId = message.reference.messageId; + message.channel.messages.fetch(repliedMessageId) + .then(repliedMessage => { + repliedMessage.reply(fn.spongebob({ args: repliedMessage.content })).then(() => { + message.delete(); + }); + }) + .catch(err => { + console.error(err); + }); + } else { + message.channel.send(fn.spongebob(commandData)).then(() => { + message.delete(); + }); + } + } +} \ No newline at end of file diff --git a/functions.js b/functions.js new file mode 100644 index 0000000..025c020 --- /dev/null +++ b/functions.js @@ -0,0 +1,576 @@ +/* eslint-disable comma-dangle */ +// dotenv for handling environment variables +const dotenv = require('dotenv'); +dotenv.config(); +// Assignment of environment variables for database access +const dbHost = process.env.dbHost; +const dbUser = process.env.dbUser; +const dbName = process.env.dbName; +const dbPass = process.env.dbPass; +const dbPort = process.env.dbPort; +const isDev = process.env.isDev; + +const ownerId = process.env.ownerId; + +// filesystem +const fs = require('fs'); + +// Discord.js +const Discord = require('discord.js'); + +// Fuzzy text matching for db lookups +const FuzzySearch = require('fuzzy-search'); + +// Various imports from other files +const config = require('./config.json'); +const strings = require('./strings.json'); +const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => file.endsWith('.js')); +const dotCommandFiles = fs.readdirSync('./dot-commands/').filter(file => file.endsWith('.js')); + +// MySQL database connection +const mysql = require('mysql'); +const db = new mysql.createPool({ + connectionLimit: 10, + host: dbHost, + user: dbUser, + password: dbPass, + database: dbName, + port: dbPort, +}); + +const functions = { + // Functions for managing and creating Collections + collections: { + // Create the collection of slash commands + slashCommands(client) { + if (!client.slashCommands) client.slashCommands = new Discord.Collection(); + client.slashCommands.clear(); + for (const file of slashCommandFiles) { + const slashCommand = require(`./slash-commands/${file}`); + if (slashCommand.data != undefined) { + client.slashCommands.set(slashCommand.data.name, slashCommand); + } + } + if (isDev) console.log('Slash Commands Collection Built'); + }, + setvalidCommands(client) { + for (const entry of client.dotCommands.map(command => command)) { + config.validCommands.push(entry.name); + if (Array.isArray(entry.alias)) { + entry.alias.forEach(element => { + config.validCommands.push(element); + }); + } else if (entry.alias != undefined) { + config.validCommands.push(entry.alias); + } + } + if (isDev) console.log(`Valid Commands Added to Config\n${config.validCommands}`); + }, + dotCommands(client) { + if (!client.dotCommands) client.dotCommands = new Discord.Collection(); + client.dotCommands.clear(); + for (const file of dotCommandFiles) { + const dotCommand = require(`./dot-commands/${file}`); + client.dotCommands.set(dotCommand.name, dotCommand); + if (Array.isArray(dotCommand.alias)) { + dotCommand.alias.forEach(element => { + client.dotCommands.set(element, dotCommand); + }); + } else if (dotCommand.alias != undefined) { + client.dotCommands.set(dotCommand.alias, dotCommand); + } + } + if (isDev) console.log('Dot Commands Collection Built'); + }, + gifs(rows, client) { + if (!client.gifs) client.gifs = new Discord.Collection(); + client.gifs.clear(); + for (const row of rows) { + const gif = { + id: row.id, + name: row.name, + embed_url: row.embed_url + }; + client.gifs.set(gif.name, gif); + } + if (isDev) console.log('GIFs Collection Built'); + }, + joints(rows, client) { + if (!client.joints) client.joints = new Discord.Collection(); + client.joints.clear(); + for (const row of rows) { + const joint = { + id: row.id, + content: row.content + }; + client.joints.set(joint.id, joint); + } + if (isDev) console.log('Joints Collection Built'); + }, + pastas(rows, client) { + if (!client.pastas) client.pastas = new Discord.Collection(); + client.pastas.clear(); + for (const row of rows) { + const pasta = { + id: row.id, + name: row.name, + content: row.content, + iconUrl: row.iconurl, + }; + client.pastas.set(pasta.name, pasta); + } + if (isDev) console.log('Pastas Collection Built'); + }, + requests(rows, client) { + if (!client.requests) client.requests = new Discord.Collection(); + client.requests.clear(); + for (const row of rows) { + const request = { + id: row.id, + author: row.author, + request: row.request, + }; + client.requests.set(request.id, request); + } + if (isDev) console.log('Requests Collection Built'); + }, + strains(rows, client) { + if (!client.strains) client.strains = new Discord.Collection(); + client.strains.clear(); + for (const row of rows) { + const strain = { + id: row.id, + name: row.strain, + }; + client.strains.set(strain.name, strain); + // if (isDev) console.log(strain) + } + if (isDev) console.log('Strains Collection Built'); + }, + medicalAdvice(rows, client) { + if (!client.medicalAdviceCol) client.medicalAdviceColl = new Discord.Collection(); + client.medicalAdviceColl.clear(); + for (const row of rows) { + const medicalAdvice = { + id: row.id, + content: row.content + }; + client.medicalAdviceColl.set(medicalAdvice.id, medicalAdvice); + } + if (isDev) console.log('Medical Advice Collection Built'); + }, + }, + dot: { + getCommandData(message) { + const commandData = {}; + // Split the message content at the final instance of a period + const finalPeriod = message.content.lastIndexOf('.'); + if(isDev) console.log(message.content); + // If the final period is the last character, or doesn't exist + if (finalPeriod < 0) { + if (isDev) console.log(finalPeriod); + commandData.isCommand = false; + return commandData; + } + commandData.isCommand = true; + // Get the first part of the message, everything leading up to the final period + commandData.args = message.content.slice(0,finalPeriod).toLowerCase(); + // Get the last part of the message, everything after the final period + commandData.command = message.content.slice(finalPeriod).replace('.','').toLowerCase(); + commandData.author = `${message.author.username}#${message.author.discriminator}`; + return this.checkCommand(commandData); + }, + checkCommand(commandData) { + if (commandData.isCommand) { + const validCommands = require('./config.json').validCommands; + commandData.isValid = validCommands.includes(commandData.command); + // Add exceptions for messages that contain only a link + if (commandData.args.startsWith('http')) commandData.isValid = false; + } + else { + commandData.isValid = false; + console.error('Somehow a non-command made it to checkCommands()'); + } + return commandData; + } + }, + embeds: { + help(interaction) { + // Construct the Help Embed + const helpEmbed = new Discord.MessageEmbed() + .setColor('BLUE') + .setAuthor('Help Page') + .setDescription(strings.help.description) + .setThumbnail(strings.urls.avatar); + + // Construct the Slash Commands help + + let slashCommandsFields = []; + + const slashCommandsMap = interaction.client.slashCommands.map(e => { + return { + name: e.data.name, + description: e.data.description + }; + }) + + for (const e of slashCommandsMap) { + slashCommandsFields.push({ + name: `- /${e.name}`, + value: e.description, + inline: false, + }); + } + + // Construct the Dot Commands Help + let dotCommandsFields = []; + + const dotCommandsMap = interaction.client.dotCommands.map(e => { + return { + name: e.name, + description: e.description, + usage: e.usage + }; + }); + + for (const e of dotCommandsMap) { + dotCommandsFields.push({ + name: `- .${e.name}`, + value: `${e.description}\nUsage: ${e.usage}`, + inline: false, + }); + } + + helpEmbed.addField('Slash Commands', strings.help.slash); + helpEmbed.addFields(slashCommandsFields); + helpEmbed.addField('Dot Commands', strings.help.dot); + helpEmbed.addFields(dotCommandsFields); + + return { embeds: [ + helpEmbed + ], ephemeral: true }; + }, + gif(commandData) { + return { embeds: [new Discord.MessageEmbed() + .setAuthor(`${commandData.args}.${commandData.command}`) + .setImage(commandData.embed_url) + .setTimestamp() + .setFooter(commandData.author)]}; + }, + pasta(commandData) { + return { embeds: [ new Discord.MessageEmbed() + .setAuthor(`${commandData.args}.${commandData.command}`) + .setDescription(commandData.content) + .setThumbnail(commandData.iconUrl) + .setTimestamp() + .setFooter(commandData.author)]}; + }, + pastas(commandData) { + const pastasArray = []; + const pastasEmbed = new Discord.MessageEmbed() + .setAuthor(commandData.command) + .setTimestamp() + .setFooter(commandData.author); + + for (const row of commandData.pastas) { + pastasArray.push(`#${row.id} - ${row.name}.pasta`); + } + + const pastasString = pastasArray.join('\n'); + pastasEmbed.setDescription(pastasString); + + return { embeds: [pastasEmbed], ephemeral: true }; + }, + gifs(commandData) { + const gifsArray = []; + const gifsEmbed = new Discord.MessageEmbed() + .setAuthor(commandData.command) + .setTimestamp() + .setFooter(commandData.author); + + for (const row of commandData.gifs) { + gifsArray.push(`#${row.id} - ${row.name}.gif`); + } + + const gifsString = gifsArray.join('\n'); + gifsEmbed.setDescription(gifsString); + + return { embeds: [gifsEmbed] }; + }, + text(commandData) { + return { embeds: [new Discord.MessageEmbed() + .setAuthor(commandData.command) + .setDescription(commandData.content) + .setTimestamp() + .setFooter(commandData.author)]}; + }, + requests(commandData) { + const requestsEmbed = new Discord.MessageEmbed() + .setAuthor(commandData.command) + .setTimestamp() + .setFooter(commandData.author); + + const requestsArray = []; + + for (const row of commandData.requests) { + requestsArray.push( + `**#${row.id} - ${row.author}**`, + `Request: ${row.request}` + ); + } + + requestsEmbed.setDescription(requestsArray.join('\n')); + + return { embeds: [requestsEmbed], ephemeral: true }; + }, + strain(strainInfo, interaction) { + const strainEmbed = new Discord.MessageEmbed() + .setTimestamp(); + strainEmbed.addFields([ + { + name: 'Strain Name', + value: `${strainInfo.strain}`, + inline: true, + }, + { + name: 'Type', + value: `${strainInfo.type}`, + inline: true, + }, + { + name: 'Effects', + value: `${strainInfo.effects}`, + inline: true, + }, + { + name: 'Flavor', + value: `${strainInfo.flavor}`, + inline: true, + }, + { + name: 'Rating', + value: `⭐️${strainInfo.rating}`, + inline: true, + }, + { + name: 'Description', + value: `${strainInfo.description}`, + inline: false, + }, + ]); + + interaction.reply({ embeds: [ strainEmbed ]}); + }, + }, + collect: { + gifName(interaction) { + const gifNameFilter = m => m.author.id == strings.temp.gifUserId; + return interaction.channel.createMessageCollector({ filter: gifNameFilter, time: 30000 }); + }, + }, + upload: { + request(commandData, client) { + const query = `INSERT INTO requests (author, request, status) VALUES (${db.escape(commandData.author)},${db.escape(commandData.args)},'Active')`; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.download.requests(client); + }); + }, + pasta(pastaData, client) { + const query = `INSERT INTO pastas (name, content) VALUES (${db.escape(pastaData.name)},${db.escape(pastaData.content)})`; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.download.pastas(client); + }); + }, + joint(content, client) { + const query = `INSERT INTO joints (content) VALUES (${db.escape(content)})`; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.download.joints(client); + }); + }, + gif(gifData, client) { + const query = `INSERT INTO gifs (name, embed_url) VALUES (${db.escape(gifData.name)}, ${db.escape(gifData.embed_url)})`; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.download.gifs(client); + }); + }, + setup(interaction) { + /* Tables: + * - gifs + * - joints + * - pastas + * - requests + * - strains */ + const gifsQuery = "CREATE TABLE 'gifs' (id int(11), name varchar(100), embed_url varchar(1000), PRIMARY KEY(id))"; + const jointsQuery = "CREATE TABLE 'joints' (id int(11), content varchar(1000), PRIMARY KEY(id))"; + const pastasQuery = "CREATE TABLE 'pastas' (id int(11), name varchar(100), content varchar(1900), iconurl varchar(200) DEFAULT 'https://cdn.discordapp.com/avatars/513184762073055252/12227aa23a06d5178853e59b72c7487b.webp?size=128', PRIMARY KEY(id))"; + const requestsQuery = "CREATE TABLE 'requests' (id int(11), author varchar(100), request varchar(1000), status varchar(10) DEFAULT 'Active', PRIMARY KEY(id))"; + const strainsQuery = "CREATE TABLE 'strains' (id smallint(6), name varchar(60), type varchar(10), effects varchat(80), ailment varchar(70), flavor varchar(30), PRIMARY KEY(id))"; + + // Check for owner + if (interaction.user.id == ownerId) { + db.query(gifsQuery, (err, rows, fields) => { + if (err) throw err; + }); + db.query(jointsQuery, (err, rows, fields) => { + if (err) throw err; + }); + db.query(pastasQuery, (err, rows, fields) => { + if (err) throw err; + }); + db.query(requestsQuery, (err, rows, fields) => { + if (err) throw err; + }); + db.query(strainsQuery, (err, rows, fields) => { + if (err) throw err; + }); + return 'I\'ve created the required tables. Please check your database to validate this.'; + } else { + return 'Sorry, you don\'t have permission to do that.'; + } + }, + medicalAdvice(content, client) { + const query = `INSERT INTO medical_advice (content) VALUES (${db.escape(content)})`; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.download.medicalAdvice(client); + }); + }, + strain(interaction) { + const strain = db.escape(interaction.options.getString('name')); + const type = db.escape(interaction.options.getString('type')); + const effects = db.escape(( interaction.options.getString('effects') || 'Unkown' )); + const description = db.escape(( interaction.options.getString('description') || 'Unknown' )); + const flavor = db.escape(( interaction.options.getString('flavor') || 'Unknown' )); + const rating = db.escape(( interaction.options.getString('rating') || '3' )); + const strainQuery = `INSERT INTO strains (strain, type, effects, description, flavor, rating) VALUES (${strain}, ${type}, ${effects}, ${description}, ${flavor}, ${rating})`; + console.log(strainQuery); + return new Promise((resolve, reject) => { + db.query(strainQuery, (err, rows, fields) => { + if (err) reject(err); + functions.download.strains(interaction.client); + resolve(); + }); + }) + } + }, + download: { + requests(client) { + const query = 'SELECT * FROM requests WHERE status = \'Active\' ORDER BY id DESC'; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.collections.requests(rows, client); + }); + }, + pastas(client) { + const query = 'SELECT * FROM pastas ORDER BY id ASC'; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.collections.pastas(rows, client); + }); + }, + gifs(client) { + const query = 'SELECT * FROM gifs ORDER BY id ASC'; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.collections.gifs(rows, client); + }); + }, + joints(client) { + const query = 'SELECT * FROM joints ORDER BY id ASC'; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.collections.joints(rows, client); + }); + }, + strain(strainName, interaction) { + const query = `SELECT id, strain, type, effects, description, flavor, rating FROM strains WHERE strain = ${db.escape(strainName)}`; + db.query(query, (err, rows, fields) => { + if (rows != undefined) { + const strainInfo = { + id: `${rows[0].id}`, + strain: `${rows[0].strain}`, + type: `${rows[0].type}`, + effects: `${rows[0].effects}`, + description: `${rows[0].description}`, + flavor: `${rows[0].flavor}`, + rating: `${rows[0].rating}`, + }; + functions.embeds.strain(strainInfo, interaction); + } + }); + }, + strains(client) { + const query = 'SELECT id, strain FROM strains'; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.collections.strains(rows, client); + }); + }, + medicalAdvice(client) { + const query = 'SELECT * FROM medical_advice ORDER BY id ASC'; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.collections.medicalAdvice(rows, client); + }); + } + }, + weed: { + strain: { + lookup(strainName, client) { + const strainSearcher = new FuzzySearch(client.strains.map(e => e.name)); + return strainSearcher.search(strainName).slice(0,25); + }, + submit(strainName) { + const query = `` + return strainName; + } + } + }, + // Parent-Level functions (miscellaneuous) + closeRequest(requestId, interaction) { + if (interaction.user.id == ownerId) { + const { client } = interaction; + const query = `UPDATE requests SET status = 'Closed' WHERE id = ${db.escape(requestId)}`; + db.query(query, (err, rows, fields) => { + if (err) throw err; + functions.download.requests(client); + }); + interaction.reply({ content: `Request #${requestId} has been closed.`, ephemeral: true }); + } else { + interaction.reply({ content: 'You do not have permission to do that.', ephemeral: true }); + } + if (isDev) { + console.log(requestId, interaction, ownerId); + } + }, + spongebob(commandData) { + let newText = ''; + for (const letter of commandData.args) { + if (letter == ' ') { + newText += letter; + continue; + } + if (letter == 'i' || letter == 'I') { + newText += 'i'; + continue; + } + if (letter == 'l' || letter == 'L') { + newText += 'L'; + continue; + } + if (Math.random() > 0.5) { + newText += letter.toUpperCase(); + } else { + newText += letter.toLowerCase(); + } + } + + return newText + ' <:spongebob:1053398825965985822>'; + }, +}; + +module.exports = functions; \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..f98aa1a --- /dev/null +++ b/main.js @@ -0,0 +1,217 @@ +/* eslint-disable no-case-declarations */ +/* eslint-disable indent */ +// dotenv for handling environment variables +const dotenv = require('dotenv'); +dotenv.config(); +const token = process.env.TOKEN; +const statusChannelId = process.env.statusChannelId; + +// Discord.JS +const { Client, GatewayIntentBits, Partials } = require('discord.js'); +const client = new Client({ + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.GuildMessageReactions, + GatewayIntentBits.DirectMessages + ], + partials: [ + Partials.Channel, + Partials.Message, + ], +}); +const { MessageActionRow, MessageButton } = require('discord.js'); + +// Various imports +const fn = require('./functions.js'); +const config = require('./config.json'); +const strings = require('./strings.json'); +const isDev = process.env.isDev; + +client.once('ready', () => { + fn.collections.slashCommands(client); + fn.collections.dotCommands(client); + fn.collections.setvalidCommands(client); + fn.download.gifs(client); + fn.download.pastas(client); + fn.download.joints(client); + fn.download.requests(client); + fn.download.strains(client); + fn.download.medicalAdvice(client); + console.log('Ready!'); + client.channels.fetch(statusChannelId).then(channel => { + channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`); + }); +}); + +// slash-commands +client.on('interactionCreate', async interaction => { + if (interaction.isCommand()) { + if (isDev) { + console.log(interaction); + } + const { commandName } = interaction; + + if (client.slashCommands.has(commandName)) { + client.slashCommands.get(commandName).execute(interaction); + } else { + interaction.reply('Sorry, I don\'t have access to that command.'); + console.error('Slash command attempted to run but not found: ' + commandName); + } + } + + if (interaction.isButton()) { + if (interaction.user.id != strings.temp.gifUserId) return; + // Get some meta info from strings + const index = strings.temp.gifIndex; + const limit = strings.temp.gifLimit; + let newIndex; + const buttonId = interaction.component.customId; + switch (buttonId) { + case 'prevGif': + newIndex = index - 1; + strings.temp.gifIndex = newIndex; + // If we're leaving the last GIF, enable the Next GIF button + if (index == limit) { + // Re-Send Previous GIF button + const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY'); + // Re-Send Confirm GIF Button + const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY'); + // Enable Next GIF Button + const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY'); + // Re-Send Cancel Button + const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Cancel').setStyle('DANGER'); + // Put all the above into an ActionRow to be sent as a component of the reply + const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton); + + interaction.update({ content: strings.temp.gifs[newIndex].embed_url, components: [row] }); + break; + } + // If we're going into the first GIF, disable the Previous GIF button + if (newIndex == 0) { + // Disable Previous GIF button + const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled(); + // Re-Send Confirm GIF Button + const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY'); + // Re-Send Next GIF Button + const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY'); + // Re-Send Cancel Button + const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Canceled').setStyle('DANGER'); + // Put all the above into an ActionRow to be sent as a component of the reply + const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton); + + interaction.update({ content: strings.temp.gifs[newIndex].embed_url, components: [row] }); + break; + } + + interaction.update(strings.temp.gifs[newIndex].embed_url); + break; + case 'confirmGif': + const gifData = { + name: strings.temp.gifName, + embed_url: strings.temp.gifs[strings.temp.gifIndex].embed_url, + }; + fn.upload.gif(gifData, client); + interaction.update({ content: `I've saved the GIF as ${gifData.name}.gif`, components: [] }); + fn.download.gifs(interaction.client); + break; + case 'nextGif': + newIndex = index + 1; + strings.temp.gifIndex = newIndex; + // If we're leaving the first GIF, enable the Previous GIF button + if (index == 0) { + // Enable Previous GIF button + const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled(false); + // Re-Send Confirm GIF Button + const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY'); + // Re-Send Next GIF Button + const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY'); + // Re-Send Cancel Button + const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Cancel').setStyle('DANGER'); + // Put all the above into an ActionRow to be sent as a component of the reply + const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton); + + interaction.update({ content: strings.temp.gifs[newIndex].embed_url, components: [row] }); + break; + } + // If we're going into the last GIF, disable the Next GIF button + if (newIndex == strings.temp.gifLimit) { + // Re-Send Previous GIF button + const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY'); + // Re-Send Confirm GIF Button + const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY'); + // Disable Next GIF Button + const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY').setDisabled(); + // Re-Send Cancel Button + const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Canceled').setStyle('DANGER'); + // Put all the above into an ActionRow to be sent as a component of the reply + const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton); + + interaction.update({ content: strings.temp.gifs[newIndex].embed_url, components: [row] }); + break; + } + + interaction.update(strings.temp.gifs[newIndex].embed_url); + break; + case 'cancelGif': + // Previous GIF button + const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled(); + // Confirm GIF Button + const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY').setDisabled(); + // Next GIF Button + const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY').setDisabled(); + // Cancel Button + const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Canceled').setStyle('DANGER'); + // Put all the above into an ActionRow to be sent as a component of the reply + const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton); + interaction.component.setDisabled(true); + + interaction.update({ content: 'Canceled.', components: [row] }); + break; + default: + break; + } + } + + // Handle autocomplete requests + if (interaction.isAutocomplete()) { + if (interaction.commandName == 'strain') { + const searchString = interaction.options.getFocused(); + const choices = fn.weed.strain.lookup(searchString, interaction.client); + await interaction.respond( + choices.map(choice => ({ name: choice, value: choice })) + ) + } else { + return; + } + } +}); + +// dot-commands +client.on('messageCreate', message => { + // Some basic checking to prevent running unnecessary code + if (message.author.bot) return; + + // Wildcard Responses, will respond if any message contains the trigger word(s), excluding self-messages + const lowerContent = message.content.toLowerCase(); + if (lowerContent.includes('big') && lowerContent.includes('doinks')) message.reply('gang.'); + if (lowerContent.includes('ligma')) message.reply('ligma balls, goteem'); + if (lowerContent.includes('frfr') || lowerContent.includes('fr fr') || lowerContent.includes('bussin') || lowerContent.includes(' ong') || lowerContent.startsWith('ong')) message.reply('ongggg no :billed_cap: fr fr str8 bussin'); + + // Break the message down into its components and analyze it + const commandData = fn.dot.getCommandData(message); + console.log(commandData); + + if (commandData.isValid && commandData.isCommand) { + try { + client.dotCommands.get(commandData.command).execute(message, commandData); + } + catch (error) { + console.error(error); + message.reply('There was an error trying to execute that command.'); + } + } + return; +}); + +client.login(token); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..c3b8d21 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "nodbot", + "version": "3.0.8", + "description": "Nods and Nod Accessories.", + "main": "main.js", + "dependencies": { + "axios": "^0.21.4", + "discord.js": "^14.7.1", + "dotenv": "^10.0.0", + "fuzzy-search": "^3.2.1", + "mysql": "^2.18.1", + "tenorjs": "^1.0.10" + }, + "engines": { + "node": "18.x" + }, + "devDependencies": { + "eslint": "^7.32.0" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/voidf1sh/nodbot.git" + }, + "author": "voidf1sh#0420", + "license": "ISC", + "bugs": { + "url": "https://github.com/voidf1sh/nodbot/issues" + }, + "homepage": "https://github.com/voidf1sh/nodbot#readme" +} diff --git a/slash-commands/.DS_Store b/slash-commands/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0", + "next": "⏭️", + "previous": "⏮️", + "confirm": "☑️", + "cancel": "❌" + }, + "urls": { + "avatar": "https://cdn.discordapp.com/avatars/513184762073055252/12227aa23a06d5178853e59b72c7487b.webp?size=128" + }, + "temp": {} +} \ No newline at end of file