diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 2bb7cbe..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ "pe" ] - pull_request: - branches: [ "pe" ] - -env: - DHUB_UNAME: ${{ secrets.DHUB_UNAME }} - DHUB_PWORD: ${{ secrets.DHUB_PWORD }} - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag v0idf1sh/nodbot-pe - - name: Log into Docker Hub - run: docker login -u $DHUB_UNAME -p $DHUB_PWORD - - name: Push image to Docker Hub - run: docker push v0idf1sh/nodbot-pe diff --git a/.github/workflows/pe-docker.yml b/.github/workflows/pe-docker.yml new file mode 100644 index 0000000..003f963 --- /dev/null +++ b/.github/workflows/pe-docker.yml @@ -0,0 +1,35 @@ +name: NodBot Production Dockerization + +on: + commit: + branches: + - pe + +env: + DHUB_UNAME: ${{ secrets.DHUB_UNAME }} + DHUB_PWORD: ${{ secrets.DHUB_PWORD }} + +jobs: + + build: + + runs-on: self-hosted + + steps: + - name: Pull latest from Git + run: | + pwd + whoami + cd /root/nodbot + git pull + git checkout pe + - name: Build the Docker image + run: | + cd /root/nodbot + docker build . --file Dockerfile --tag v0idf1sh/nodbot-pe + - name: Log into Docker Hub + run: docker login -u $DHUB_UNAME -p $DHUB_PWORD + - name: Push image to Docker Hub + run: | + cd /root/nodbot + docker push v0idf1sh/nodbot-pe \ No newline at end of file diff --git a/.github/workflows/production-docker.yml b/.github/workflows/production-docker.yml new file mode 100644 index 0000000..d4e5c6b --- /dev/null +++ b/.github/workflows/production-docker.yml @@ -0,0 +1,35 @@ +name: NodBot Production Dockerization + +on: + pull_request: + branches: + - main + +env: + DHUB_UNAME: ${{ secrets.DHUB_UNAME }} + DHUB_PWORD: ${{ secrets.DHUB_PWORD }} + +jobs: + + build: + + runs-on: self-hosted + + steps: + - name: Pull latest from Git + run: | + pwd + whoami + cd /root/nodbot + git pull + git checkout $GITHUB_HEAD_REF + - name: Build the Docker image + run: | + cd /root/nodbot + docker build . --file Dockerfile --tag v0idf1sh/nodbot + - name: Log into Docker Hub + run: docker login -u $DHUB_UNAME -p $DHUB_PWORD + - name: Push image to Docker Hub + run: | + cd /root/nodbot + docker push v0idf1sh/nodbot \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a0b785a..7b75fef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,4 +5,4 @@ WORKDIR /usr/src/app COPY package.json ./ RUN npm install COPY . . -CMD [ "node", "main.js" ] \ No newline at end of file +CMD ["/bin/sh", "-c", "node main.js 2> /logs/nodbot.error 1> /logs/nodbot.log"] \ No newline at end of file diff --git a/README.md b/README.md index 34bc147..7d31f60 100644 --- a/README.md +++ b/README.md @@ -97,4 +97,15 @@ tenorAPIKey= ownerId= statusChannelId= clientId= -``` \ No newline at end of file +``` + +## Changes + +v3.0.1 - Migrate TenorJS API Endpoint +v3.0.2 - Add medical advice commands +v3.0.3 - Fix broken `/requests` command +v3.0.4 - Add ability to use multiple aliases +v3.0.5 - Add ability to save strains +v3.0.6 - Move `.strain` to `/strain` and add Autocomplete +v3.0.7 - Add `.spongebob` replies +v3.0.8 - Add ability to open requests by pages \ No newline at end of file diff --git a/dot-commands/md.js b/dot-commands/md.js new file mode 100644 index 0000000..01eea4a --- /dev/null +++ b/dot-commands/md.js @@ -0,0 +1,16 @@ +const fn = require('../functions.js'); +// const { emoji } = require('../strings.json'); + +module.exports = { + name: 'md', + description: 'Get some medical advice.', + usage: '.md', + execute(message, commandData) { + let medicalAdviceArr = []; + for (const entry of message.client.medicalAdviceColl.map(medicalAdvice => medicalAdvice.content)) { + medicalAdviceArr.push(entry); + } + const randIndex = Math.floor(Math.random() * medicalAdviceArr.length); + message.reply(`${medicalAdviceArr[randIndex]}`); + } +} \ No newline at end of file diff --git a/dot-commands/spongebob.js b/dot-commands/spongebob.js index 0f0c653..f886a27 100644 --- a/dot-commands/spongebob.js +++ b/dot-commands/spongebob.js @@ -10,6 +10,21 @@ module.exports = { // message.reply(fn.spongebob(commandData)).then(() => { // message.delete(); // }); - message.channel.send(fn.spongebob(commandData)); + if (message.reference != undefined) { + const repliedMessageId = message.reference.messageId; + message.channel.messages.fetch(repliedMessageId) + .then(repliedMessage => { + repliedMessage.reply(fn.spongebob({ args: repliedMessage.content })).then(() => { + if (message.deletable) message.delete(); + }); + }) + .catch(err => { + console.error(err); + }); + } else { + message.channel.send(fn.spongebob(commandData)).then(() => { + if (message.deletable) message.delete(); + }); + } } } \ No newline at end of file diff --git a/dot-commands/strain.js b/dot-commands/strain.js.bak similarity index 100% rename from dot-commands/strain.js rename to dot-commands/strain.js.bak diff --git a/functions.js b/functions.js index bd43e22..5031f32 100644 --- a/functions.js +++ b/functions.js @@ -56,10 +56,13 @@ const functions = { setvalidCommands(client) { for (const entry of client.dotCommands.map(command => command)) { config.validCommands.push(entry.name); - if (entry.alias != undefined) { + 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}`); }, @@ -69,7 +72,11 @@ const functions = { for (const file of dotCommandFiles) { const dotCommand = require(`./dot-commands/${file}`); client.dotCommands.set(dotCommand.name, dotCommand); - if (dotCommand.alias != undefined) { + 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); } } @@ -139,7 +146,19 @@ const functions = { // 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) { @@ -418,7 +437,7 @@ const functions = { }, download: { requests(client) { - const query = 'SELECT * FROM requests WHERE status = \'Active\' ORDER BY id ASC'; + 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); @@ -470,6 +489,13 @@ const functions = { 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: { diff --git a/main.js b/main.js index 88920ec..818d094 100644 --- a/main.js +++ b/main.js @@ -38,6 +38,7 @@ client.once('ready', () => { 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`); @@ -172,6 +173,19 @@ client.on('interactionCreate', async interaction => { 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 @@ -184,7 +198,10 @@ client.on('messageCreate', message => { 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'); + if (lowerContent.includes('frfr') || lowerContent.includes('fr fr') || lowerContent.includes('bussin') || lowerContent.includes(' ong') || lowerContent.startsWith('ong')) { + const randIndex = Math.floor(Math.random() * strings.capbacks.length); + message.reply(strings.capbacks[randIndex]); + } // Break the message down into its components and analyze it const commandData = fn.dot.getCommandData(message); diff --git a/package.json b/package.json index 83577bd..7c84570 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,14 @@ { "name": "nodbot", - "version": "3.0.0", + "version": "3.1.0", "description": "Nods and Nod Accessories.", "main": "main.js", "dependencies": { - "@discordjs/builders": "^0.6.0", + "@discordjs/builders": "^0.16.0", "@discordjs/rest": "^0.1.0-canary.0", "axios": "^0.21.4", "discord-api-types": "^0.22.0", - "discord.js": "^13.1.0", - "discord.js-selfbot-v13": "^2.9.15", + "discord.js": "^13.15.1", "dotenv": "^10.0.0", "fuzzy-search": "^3.2.1", "mysql": "^2.18.1", diff --git a/slash-commands/requests.js b/slash-commands/requests.js index 75caa80..039504e 100644 --- a/slash-commands/requests.js +++ b/slash-commands/requests.js @@ -5,8 +5,14 @@ const fn = require('../functions.js'); module.exports = { data: new SlashCommandBuilder() .setName('requests') - .setDescription('Get a list of Active requests from the database'), + .setDescription('Get a list of Active requests from the database') + .addStringOption(option => + option + .setName('page') + .setDescription('Page Number') + .setRequired(true)), async execute(interaction) { + const pageNum = interaction.options.getString('page'); const commandData = { author: interaction.user.tag, command: interaction.commandName, @@ -19,12 +25,14 @@ module.exports = { request: e.request, }; }); - for (const row of requestsMap) { - commandData.requests.push({ - id: row.id, - author: row.author, - request: row.request, - }); + for (let i = ( 10 * ( pageNum - 1 ) ); i < ( 10 * pageNum ); i++) { + if (requestsMap[i] != undefined) { + commandData.requests.push({ + id: requestsMap[i].id, + author: requestsMap[i].author, + request: requestsMap[i].request, + }); + } } interaction.reply(fn.embeds.requests(commandData)); }, diff --git a/slash-commands/savemd.js b/slash-commands/savemd.js new file mode 100644 index 0000000..8391da3 --- /dev/null +++ b/slash-commands/savemd.js @@ -0,0 +1,17 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const fn = require('../functions.js'); +// const { emoji } = require('../strings.json'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('savemd') + .setDescription('Add medical advice to NodBot\'s Database!') + .addStringOption(option => + option.setName('advice-content') + .setDescription('What is the advice?') + .setRequired(true)), + async execute(interaction) { + fn.upload.medicalAdvice(interaction.options.getString('advice-content'), interaction.client); + interaction.reply({ content: `The advice has been saved!`, ephemeral: true }); + }, +}; \ No newline at end of file diff --git a/slash-commands/savestrain.js b/slash-commands/savestrain.js new file mode 100644 index 0000000..3cc90f8 --- /dev/null +++ b/slash-commands/savestrain.js @@ -0,0 +1,54 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const fn = require('../functions.js'); +const { emoji } = require('../strings.json'); + +// Strain Name | Type | Effects | Flavor | Rating | Description + +module.exports = { + data: new SlashCommandBuilder() + .setName('savestrain') + .setDescription('Store a new Strain in the database!') + .addStringOption(option => + option.setName('name') + .setDescription('Name of the Strain') + .setRequired(true)) + .addStringOption(option => + option.setName('type') + .setDescription('Indica/Sativa/Hybrid') + .setRequired(true) + .addChoices( + { name: "Indica", value: "Indica" }, + { name: "Hybrid", value: "Hybrid" }, + { name: "Sativa", value: "Sativa" } + )) + .addStringOption(option => + option.setName('effects') + .setDescription('The effects given by the strain') + .setRequired(false)) + .addStringOption(option => + option.setName('flavor') + .setDescription('Flavor notes') + .setRequired(false)) + .addStringOption(option => + option.setName('rating') + .setDescription('Number of stars') + .setRequired(false)) + .addStringOption(option => + option.setName('description') + .setDescription('Description of the strain') + .setRequired(false)), + async execute(interaction) { + fn.upload.strain(interaction).then(res => { + interaction.reply({ + content: `The strain information has been saved. (${interaction.options.getString('name')})`, + ephemeral: true + }); + }).catch(err => { + console.log(`E: ${err}`); + interaction.reply({ + content: 'There was a problem saving the strain.', + ephemeral: true + }); + }); + }, +}; \ No newline at end of file diff --git a/slash-commands/strain.js b/slash-commands/strain.js new file mode 100644 index 0000000..74cf8d3 --- /dev/null +++ b/slash-commands/strain.js @@ -0,0 +1,17 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const fn = require('../functions.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('strain') + .setDescription('Look up information about a cannabis strain.') + .addStringOption(option => + option + .setName('name') + .setDescription('Strain Name') + .setRequired(true) + .setAutocomplete(true)), + async execute(interaction) { + fn.download.strain(interaction.options.getString('name'), interaction); + }, +}; \ No newline at end of file diff --git a/strings.json b/strings.json index ccc342e..bcf8a14 100644 --- a/strings.json +++ b/strings.json @@ -14,5 +14,13 @@ "urls": { "avatar": "https://cdn.discordapp.com/avatars/513184762073055252/12227aa23a06d5178853e59b72c7487b.webp?size=128" }, + "capbacks": [ + "on god?!", + "fr fr?!", + "no cap?!", + "no cap fr", + "bussin fr, no cap", + "ongggg no :billed_cap: fr fr" + ], "temp": {} } \ No newline at end of file