From ed315d0cb12436f341021ebd47392e3b387724ae Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 09:43:05 -0400 Subject: [PATCH 01/21] Versioning -- v3.4.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8fcfff9..ed51b46 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nodbot", - "version": "3.3.3", - "description": "Nods and Nod Accessories, now with ChatGPT!", + "version": "3.4.0", + "description": "Nods and Nod Accessories", "main": "main.js", "dependencies": { "@discordjs/builders": "^0.16.0", -- 2.45.2 From 2cbfc7f35463f9db85c1d977d513bcc9e511c705 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 09:55:49 -0400 Subject: [PATCH 02/21] WIP DNU --- CustomModules/NodBot.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CustomModules/NodBot.js b/CustomModules/NodBot.js index d18c21b..f1d3a4a 100644 --- a/CustomModules/NodBot.js +++ b/CustomModules/NodBot.js @@ -16,6 +16,17 @@ module.exports = { if (this.args.startsWith('http')) return false; if (this.args.startsWith('www')) return false; + // Check for and extract the part of the message that's + // wrapped in any type of brackets or quotes eg. ([{``''""}]) + const bracketStart = this.args.match(/[\[\(\{\`\'\"\`]/g); + const bracketEnd = this.args.match(/[\]\)\}\`\'\"\`]/g); + let bracketedText = new String(); + if ((bracketStart && bracketEnd) && (bracketStart.length !== bracketEnd.length)) { + bracketedText = this.args.slice(this.args.indexOf(bracketStart[0]), this.args.lastIndexOf(bracketEnd[0]) + 1); + this.args = this.args.replace(bracketedText, ''); + } + console.log(bracketedText); + for (const [key, value] of dotCommands) { if (key === this.command) { this.isValid = true; -- 2.45.2 From e4fbcca6c43acdbc735fd5a7dc00b78168945b8c Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 14:20:56 -0400 Subject: [PATCH 03/21] MVP for nested commands --- CustomModules/NodBot.js | 108 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 11 deletions(-) diff --git a/CustomModules/NodBot.js b/CustomModules/NodBot.js index f1d3a4a..9b993c3 100644 --- a/CustomModules/NodBot.js +++ b/CustomModules/NodBot.js @@ -8,6 +8,7 @@ module.exports = { this.args = message.content.slice(0,this.finalPeriod).toLowerCase(); // Grab everything leading up to the final period this.command = message.content.slice(this.finalPeriod + 1).toLowerCase(); // Grab everything after the final period this.author = message.author.username; + this.message = message; return this; } @@ -16,25 +17,110 @@ module.exports = { if (this.args.startsWith('http')) return false; if (this.args.startsWith('www')) return false; + const indices = { + curlyBrace: { + start: -1, + end: -1 + }, + bracket: { + start: -1, + end: -1 + }, + parenthesis: { + start: -1, + end: -1 + } + } + // Check for and extract the part of the message that's // wrapped in any type of brackets or quotes eg. ([{``''""}]) - const bracketStart = this.args.match(/[\[\(\{\`\'\"\`]/g); - const bracketEnd = this.args.match(/[\]\)\}\`\'\"\`]/g); - let bracketedText = new String(); - if ((bracketStart && bracketEnd) && (bracketStart.length !== bracketEnd.length)) { - bracketedText = this.args.slice(this.args.indexOf(bracketStart[0]), this.args.lastIndexOf(bracketEnd[0]) + 1); - this.args = this.args.replace(bracketedText, ''); + const curlyBraceStart = this.message.content.match(/[\{]/g); + const curlyBraceEnd = this.message.content.match(/[\}]/g); + if (curlyBraceStart && curlyBraceEnd) { + indices.curlyBrace.start = this.message.content.indexOf(curlyBraceStart[0]) + 1; + indices.curlyBrace.end = this.message.content.lastIndexOf(curlyBraceEnd[0]); + } + + const bracketStart = this.message.content.match(/[\[]/g); + const bracketEnd = this.message.content.match(/[\]]/g); + if (bracketStart && bracketEnd) { + indices.bracket.start = this.message.content.indexOf(bracketStart[0]) + 1; + indices.bracket.end = this.message.content.lastIndexOf(bracketEnd[0]); + } + + const parenthesisStart = this.message.content.match(/[\(]/g); + const parenthesisEnd = this.message.content.match(/[\)]/g); + if (parenthesisStart && parenthesisEnd) { + indices.parenthesis.start = this.message.content.indexOf(parenthesisStart[0]) + 1; + indices.parenthesis.end = this.message.content.lastIndexOf(parenthesisEnd[0]); + } + + let nestedText = new String(); + + if (indices.curlyBrace.start >= 0 && indices.curlyBrace.end > 0) { + nestedText = this.message.content.slice(indices.curlyBrace.start, indices.curlyBrace.end); + } + + if (indices.bracket.start >= 0 && indices.bracket.end > 0) { + nestedText = this.message.content.slice(indices.bracket.start, indices.bracket.end); + } + + if (indices.parenthesis.start >= 0 && indices.parenthesis.end > 0) { + nestedText = this.message.content.slice(indices.parenthesis.start, indices.parenthesis.end); + } + + console.log(nestedText); + + if (nestedText !== "") { + this.nestedCommand = { + finalPeriod: nestedText.lastIndexOf('.'), + isCommand: nestedText.lastIndexOf('.') >= 0 ? true : false, + args: nestedText.slice(0, nestedText.lastIndexOf('.')).toLowerCase(), + command: nestedText.slice(nestedText.lastIndexOf('.') + 1).toLowerCase() + } + + for (const [key, value] of dotCommands) { + if (key === this.nestedCommand.command) { + this.isValid = true; + this.args = this.nestedCommand.args; + this.command = key; + this.isCommand = this.nestedCommand.isCommand; + this.finalPeriod = this.nestedCommand.finalPeriod; + return this; + } else if (value.alias) { + if (typeof value.alias === 'string' && value.alias === this.nestedCommand.command) { + this.command = key + this.args = this.nestedCommand.args; + this.isValid = true; + this.isCommand = this.nestedCommand.isCommand; + this.finalPeriod = this.nestedCommand.finalPeriod; + return this; + } else if (typeof value.alias === 'object' && value.alias.includes(this.nestedCommand.command)) { + this.command = key + this.args = this.nestedCommand.args; + this.isValid = true; + this.isCommand = this.nestedCommand.isCommand; + this.finalPeriod = this.nestedCommand.finalPeriod; + return this; + } + } + } } - console.log(bracketedText); for (const [key, value] of dotCommands) { if (key === this.command) { this.isValid = true; return this; - } else if (value.alias && value.alias.includes(this.command)) { - this.command = key; - this.isValid = true; - return this; + } else if (value.alias) { + if (typeof value.alias === 'string' && value.alias === this.command) { + this.command = key; + this.isValid = true; + return this; + } else if (typeof value.alias === 'object' && value.alias.includes(this.command)) { + this.command = key; + this.isValid = true; + return this; + } } } return this; -- 2.45.2 From 8d5f75e471bc3621298178956404d021cc4579a4 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 14:25:22 -0400 Subject: [PATCH 04/21] Add nested commands --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b83906..fa31e1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v3.4.x +#### v3.4.0 +* Added nested commands, enclose a command in brackets, braces, or parenthesis inside a longer message: `You really don't get it do you? [that's the joke.gif] You're so dense` would return the results for just `that's the joke.gif` + ## v3.3.x #### v3.3.3 (#20) * Fixed content-list slash commands `/gifs`, `/pastas`, `/joints`, `/requests` (#19) -- 2.45.2 From 6175a30974400e65f57ffc13ec4486fec1bcb625 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 14:28:11 -0400 Subject: [PATCH 05/21] Add PR tag # --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa31e1f..5b969d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## v3.4.x -#### v3.4.0 +#### v3.4.0 (#25) * Added nested commands, enclose a command in brackets, braces, or parenthesis inside a longer message: `You really don't get it do you? [that's the joke.gif] You're so dense` would return the results for just `that's the joke.gif` ## v3.3.x -- 2.45.2 From b536ebda5b3830c0746ccc3b6b34b8052778b273 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 19:30:01 -0400 Subject: [PATCH 06/21] Add ability to handle pages of different length, defaulting to 10 --- CustomModules/Indexer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CustomModules/Indexer.js b/CustomModules/Indexer.js index dacb3bb..8b9c2a3 100644 --- a/CustomModules/Indexer.js +++ b/CustomModules/Indexer.js @@ -1,5 +1,5 @@ -module.exports = (collection, page) => { - const itemsPerPage = 10; +module.exports = (collection, page, qty) => { + const itemsPerPage = qty ? qty : 10; const index = page * itemsPerPage; const totalPages = Math.ceil(collection.size / itemsPerPage); let state = page === 0 ? 'first' : 'middle'; -- 2.45.2 From 3def31b0fb703f3d773fa4da30cbc71a2862f505 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 19:30:41 -0400 Subject: [PATCH 07/21] Moved all button handling to ButtonHandlers.js and cleaned up /save gifSearch --- CustomModules/ButtonHandlers.js | 53 ++++++++++ CustomModules/Embeds.js | 167 +++++++++++++++++--------------- functions.js | 8 +- main.js | 112 +-------------------- slash-commands/save.js | 37 ++++--- 5 files changed, 175 insertions(+), 202 deletions(-) diff --git a/CustomModules/ButtonHandlers.js b/CustomModules/ButtonHandlers.js index cf3d6d9..610bbf0 100644 --- a/CustomModules/ButtonHandlers.js +++ b/CustomModules/ButtonHandlers.js @@ -3,6 +3,7 @@ const InteractionStorage = require('../CustomModules/InteractionStorage.js'); const indexer = require('../CustomModules/Indexer.js'); const fn = require('../functions.js'); const requests = require('../slash-commands/requests.js'); +const { GifData } = require('./NodBot.js'); module.exports = { baseEvent(interaction) { @@ -40,6 +41,18 @@ module.exports = { case 'nextJointsPage': module.exports.jointsPage(interaction); break; + case 'prevGif': + module.exports.gifSearchPage(interaction); + break; + case 'nextGif': + module.exports.gifSearchPage(interaction); + break; + case 'confirmGif': + module.exports.gifSearchPage(interaction); + break; + case 'cancelGif': + module.exports.gifSearchPage(interaction); + break; default: return; } @@ -147,5 +160,45 @@ module.exports = { } interaction.update(fn.embeds.joints({command: "/joints", author: interaction.member.displayName}, indexedJoints)); + }, + gifSearchPage(interaction) { + const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id); + + switch (interaction.component.customId) { + case 'prevGif': + if (iStorage.page > 0) { + iStorage.page = iStorage.page - 1; + } + break; + case 'nextGif': + if (iStorage.page < interaction.client.gifs.size / 10) { + iStorage.page = iStorage.page + 1; + } + break; + case 'confirmGif': + const gif = indexer(iStorage.gifsCollection, iStorage.page, 1).thisPage[0]; + const gifData = new GifData().setInfo(iStorage.gifName, gif.media_formats.gif.url, gif.id); + fn.upload.gif(gifData, interaction.client); + interaction.update({ content: `I've saved the GIF as ${gifData.name}.gif`, components: [] }); + fn.download.gifs(interaction.client); + return; + break; + case 'cancelGif': + interaction.update({ content: 'The GIF has been discarded.', components: [], embeds: [] }); + return; + break; + default: + break; + } + // Generate the action row + const gifSearchAR = customEmbeds.actionRows.gifSearchAR(iStorage.state); + // Update the index + const indexedGifs = indexer(iStorage.gifsCollection, iStorage.page, 1); + indexedGifs.query = iStorage.query; + indexedGifs.gifName = iStorage.gifName; + // Generate the embed + const gifEmbed = customEmbeds.core.gifSearch({ author: interaction.member.displayName }, indexedGifs); + // Update the interaction + interaction.update({ embeds: [gifEmbed], components: [gifSearchAR], ephemeral: true }); } } \ No newline at end of file diff --git a/CustomModules/Embeds.js b/CustomModules/Embeds.js index 115e66a..95f40cb 100644 --- a/CustomModules/Embeds.js +++ b/CustomModules/Embeds.js @@ -1,139 +1,154 @@ -const { MessageActionRow, MessageButton } = require('discord.js'); +const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js'); module.exports = { - gifSearchAR(state) { - // Setup the buttons - const previousButton = new MessageButton() + actionRows: { + gifSearchAR(state) { + // Setup the buttons + const previousButton = new MessageButton() .setCustomId('prevGif') .setLabel('⬅️') .setStyle('SECONDARY'); - - const confirmButton = new MessageButton() + + const confirmButton = new MessageButton() .setCustomId('confirmGif') - .setLabel('✅') + .setLabel('Select') .setStyle('PRIMARY'); - - const nextButton = new MessageButton() + + const nextButton = new MessageButton() .setCustomId('nextGif') .setLabel('➡️') .setStyle('SECONDARY'); - - const cancelButton = new MessageButton() + + const cancelButton = new MessageButton() .setCustomId('cancelGif') - .setLabel('❌') + .setLabel('Cancel') .setStyle('DANGER'); - - switch (state) { - case 'first': + + switch (state) { + case 'first': previousButton.setDisabled(true); break; - case 'last': + case 'last': nextButton.setDisabled(true); break; - } - - // Put the buttons into an ActionRow - return new MessageActionRow() + } + + // Put the buttons into an ActionRow + return new MessageActionRow() .addComponents(previousButton, confirmButton, nextButton, cancelButton); - }, - gifsPageAR(state) { - // Setup the buttons - const previousButton = new MessageButton() + }, + gifsPageAR(state) { + // Setup the buttons + const previousButton = new MessageButton() .setCustomId('prevGifsPage') .setLabel('⬅️') .setStyle('SECONDARY'); - - const nextButton = new MessageButton() + + const nextButton = new MessageButton() .setCustomId('nextGifsPage') .setLabel('➡️') .setStyle('SECONDARY'); - - switch (state) { - case 'first': + + switch (state) { + case 'first': previousButton.setDisabled(true); break; - case 'last': + case 'last': nextButton.setDisabled(true); break; - } - - // Put the buttons into an ActionRow - return new MessageActionRow() + } + + // Put the buttons into an ActionRow + return new MessageActionRow() .addComponents(previousButton, nextButton); - }, - requestsPageAR(state) { - // Setup the buttons - const previousButton = new MessageButton() + }, + requestsPageAR(state) { + // Setup the buttons + const previousButton = new MessageButton() .setCustomId('prevRequestsPage') .setLabel('⬅️') .setStyle('SECONDARY'); - - const nextButton = new MessageButton() + + const nextButton = new MessageButton() .setCustomId('nextRequestsPage') .setLabel('➡️') .setStyle('SECONDARY'); - - switch (state) { - case 'first': + + switch (state) { + case 'first': previousButton.setDisabled(true); break; - case 'last': + case 'last': nextButton.setDisabled(true); break; - } - - // Put the buttons into an ActionRow - return new MessageActionRow() + } + + // Put the buttons into an ActionRow + return new MessageActionRow() .addComponents(previousButton, nextButton); - }, - pastasPageAR(state) { - // Setup the buttons - const previousButton = new MessageButton() + }, + pastasPageAR(state) { + // Setup the buttons + const previousButton = new MessageButton() .setCustomId('prevPastasPage') .setLabel('⬅️') .setStyle('SECONDARY'); - - const nextButton = new MessageButton() + + const nextButton = new MessageButton() .setCustomId('nextPastasPage') .setLabel('➡️') .setStyle('SECONDARY'); - - switch (state) { - case 'first': + + switch (state) { + case 'first': previousButton.setDisabled(true); break; - case 'last': + case 'last': nextButton.setDisabled(true); break; - } - - // Put the buttons into an ActionRow - return new MessageActionRow() + } + + // Put the buttons into an ActionRow + return new MessageActionRow() .addComponents(previousButton, nextButton); - }, - jointsPageAR(state) { - // Setup the buttons - const previousButton = new MessageButton() + }, + jointsPageAR(state) { + // Setup the buttons + const previousButton = new MessageButton() .setCustomId('prevJointsPage') .setLabel('⬅️') .setStyle('SECONDARY'); - - const nextButton = new MessageButton() + + const nextButton = new MessageButton() .setCustomId('nextJointsPage') .setLabel('➡️') .setStyle('SECONDARY'); - - switch (state) { - case 'first': + + switch (state) { + case 'first': previousButton.setDisabled(true); break; - case 'last': + case 'last': nextButton.setDisabled(true); break; - } - - // Put the buttons into an ActionRow - return new MessageActionRow() + } + + // Put the buttons into an ActionRow + return new MessageActionRow() .addComponents(previousButton, nextButton); + } + }, + core: { + gifSearch(commandData, indexedGifs) { + return new MessageEmbed() + .setColor('#0099ff') + .setTitle('GIF Search') + .setImage(indexedGifs.thisPage[0].media_formats.gif.url) + .setFooter({ text: `Page ${indexedGifs.pagesString}` }) + .addFields( + { name: 'Query', value: `"${indexedGifs.query}"`, inline: true }, + { name: 'Saving As', value: `${indexedGifs.gifName}.gif`, inline: true }, + ); + } } } \ No newline at end of file diff --git a/functions.js b/functions.js index 7d8a1b2..8f74288 100644 --- a/functions.js +++ b/functions.js @@ -270,7 +270,7 @@ const functions = { .setFooter({text: `Page: ${indexedPastas.pagesString}`}) .setDescription(indexedPastas.pastasString); - const pastasPageAR = customEmbeds.pastasPageAR(indexedPastas.state); + const pastasPageAR = customEmbeds.actionRows.pastasPageAR(indexedPastas.state); return { embeds: [pastasEmbed], components: [pastasPageAR], ephemeral: true }; }, gifs(commandData, indexedGifs) { @@ -280,7 +280,7 @@ const functions = { .setFooter({text: `Page: ${indexedGifs.pagesString}`}) .setDescription(indexedGifs.gifsString); - const gifsPageAR = customEmbeds.gifsPageAR(indexedGifs.state); + const gifsPageAR = customEmbeds.actionRows.gifsPageAR(indexedGifs.state); return { embeds: [gifsEmbed], components: [gifsPageAR], ephemeral: true }; }, joints(commandData, indexedJoints) { @@ -290,7 +290,7 @@ const functions = { .setFooter({text: `Page: ${indexedJoints.pagesString}`}) .setDescription(indexedJoints.jointsString); - const jointsPageAR = customEmbeds.jointsPageAR(indexedJoints.state); + const jointsPageAR = customEmbeds.actionRows.jointsPageAR(indexedJoints.state); return { embeds: [jointsEmbed], components: [jointsPageAR], ephemeral: true }; }, text(commandData) { @@ -307,7 +307,7 @@ const functions = { .setFooter({text: `Page: ${indexedRequests.pagesString}`}) .setDescription(indexedRequests.requestsString); - const requestsPageAR = customEmbeds.requestsPageAR(indexedRequests.state); + const requestsPageAR = customEmbeds.actionRows.requestsPageAR(indexedRequests.state); return { embeds: [requestsEmbed], components: [requestsPageAR], ephemeral: true }; }, strain(strainInfo, interaction) { diff --git a/main.js b/main.js index 147f500..c97a05d 100644 --- a/main.js +++ b/main.js @@ -76,117 +76,7 @@ client.on('interactionCreate', async interaction => { if (interaction.isButton()) { if (isDev) console.log('Origin Interaction ID: ' + interaction.message.interaction.id); if (isDev) console.log('Button ID: ' + interaction.component.customId); - // 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, - // url: strings.temp.gifs[strings.temp.gifIndex].embed_url, - // }; - const gifData = new GifData().setInfo(strings.temp.gifName, 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: - ButtonHandlers.baseEvent(interaction); - break; - } + ButtonHandlers.baseEvent(interaction); } // Handle autocomplete requests diff --git a/slash-commands/save.js b/slash-commands/save.js index 28f7533..fdc990b 100644 --- a/slash-commands/save.js +++ b/slash-commands/save.js @@ -7,11 +7,13 @@ const tenor = require('tenorjs').client({ }); const { SlashCommandBuilder } = require('@discordjs/builders'); -const { MessageActionRow, MessageButton } = require('discord.js'); +const { Collection } = require('discord.js'); const fn = require('../functions.js'); const strings = require('../strings.json'); const { GifData } = require('../CustomModules/NodBot.js'); const customEmbeds = require('../CustomModules/Embeds.js'); +const Indexer = require('../CustomModules/Indexer.js'); +const Embeds = require('../CustomModules/Embeds.js'); const { emoji } = strings; module.exports = { @@ -142,15 +144,21 @@ module.exports = { switch (subcommand) { // GIF Search case "gifsearch": - // TODO Check on option names - const actionRow = customEmbeds.gifSearchAR(); - - // Get the query + // Grab the inputs from the command const query = interaction.options.getString('query'); - strings.temp.gifName = interaction.options.getString('name').toLowerCase(); + const gifName = interaction.options.getString('name').toLowerCase(); + + const iStorage = interaction.client.iStorage.get(interaction.id); + iStorage.page = 0; + iStorage.gifsCollection = new Collection(); + iStorage.gifName = gifName; + iStorage.query = query; + + // Search Tenor for the GIF - tenor.Search.Query(query, '10').then(res => { + tenor.Search.Query(query, '20').then(res => { + strings.temp.gifs = []; strings.temp.gifIndex = 0; strings.temp.gifLimit = res.length - 1; @@ -161,11 +169,18 @@ module.exports = { return; } for (const row of res) { - strings.temp.gifs.push({ - embed_url: row.media_formats.gif.url, - }); + iStorage.gifsCollection.set(row.id, row); } - interaction.editReply({ content: strings.temp.gifs[0].embed_url, components: [actionRow], ephemeral: true }); + + // Generate the initial action row + const actionRow = customEmbeds.actionRows.gifSearchAR('first'); + // Get the index built + const gifPage = Indexer(iStorage.gifsCollection, 0, 1); + gifPage.query = query; + gifPage.gifName = gifName; + // Generate the embed + const gifEmbed = Embeds.core.gifSearch({ author: interaction.member.displayName }, gifPage); + interaction.editReply({ embeds: [gifEmbed], components: [actionRow], ephemeral: true }); }); break; // GIF URL -- 2.45.2 From 326d5a15f29ad07d6de49010c38b08919913af39 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 19:37:35 -0400 Subject: [PATCH 08/21] Might need to pull after checking out, oops --- .gitea/workflows/production-docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/production-docker.yml b/.gitea/workflows/production-docker.yml index c524d9b..f824157 100644 --- a/.gitea/workflows/production-docker.yml +++ b/.gitea/workflows/production-docker.yml @@ -28,6 +28,7 @@ jobs: git pull fi git checkout ${{ gitea.head_ref }} + git pull - name: Build the Docker image run: | cd /var/lib/act_runner/nodbot -- 2.45.2 From e0c0dff82d13485201b1589e9acc5c67954edf92 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 19:39:19 -0400 Subject: [PATCH 09/21] v3.4.0-b --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b969d8..34b3e20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## v3.4.x #### v3.4.0 (#25) * Added nested commands, enclose a command in brackets, braces, or parenthesis inside a longer message: `You really don't get it do you? [that's the joke.gif] You're so dense` would return the results for just `that's the joke.gif` +* Improved the `/save gifsearch` interface and the code behind the scenes ## v3.3.x #### v3.3.3 (#20) -- 2.45.2 From 28bd2f46cb63b2840e415a93abadb181d93b5379 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 26 Sep 2024 19:55:12 -0400 Subject: [PATCH 10/21] added a response for when nothing gets returned from the API --- dot-commands/metar.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dot-commands/metar.js b/dot-commands/metar.js index 33207e9..b5333e3 100644 --- a/dot-commands/metar.js +++ b/dot-commands/metar.js @@ -10,6 +10,10 @@ module.exports = { // Also checks for validity of ICAOs const icaoList = fn.avWx.parseICAOs(commandData); const metarData = await fn.avWx.metar.getData(icaoList); + if (metarData.length === 0) { + message.reply('No METAR data found for the provided ICAOs.'); + return; + } const messages = fn.avWx.metar.parseData(metarData); messages.forEach(messagePayload => { message.reply(messagePayload); -- 2.45.2 From e843275ba1efd1ae2a45a7548fe6bbbb806a6ed9 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 12:17:07 -0400 Subject: [PATCH 11/21] Fix references to guild names when not needed --- CustomModules/ButtonHandlers.js | 10 +-- slash-commands/gifs.js | 2 +- slash-commands/joints.js | 2 +- slash-commands/pastas.js | 2 +- slash-commands/requests.js | 2 +- slash-commands/save.js | 2 +- slash-commands/view.js | 114 ++++++++++++++++++++++++++++++++ 7 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 slash-commands/view.js diff --git a/CustomModules/ButtonHandlers.js b/CustomModules/ButtonHandlers.js index 610bbf0..81aa980 100644 --- a/CustomModules/ButtonHandlers.js +++ b/CustomModules/ButtonHandlers.js @@ -81,7 +81,7 @@ module.exports = { indexedGifs.gifsString += `[${gif.name}.gif](${gif.url})\n`; } - interaction.update(fn.embeds.gifs({command: "/gifs", author: interaction.member.displayName}, indexedGifs)); + interaction.update(fn.embeds.gifs({command: "/gifs", author: interaction.user.username}, indexedGifs)); }, pastasPage(interaction) { const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id); @@ -107,7 +107,7 @@ module.exports = { indexedPastas.pastasString += `${pasta.name}.pasta\n`; } - interaction.update(fn.embeds.pastas({command: "/pastas", author: interaction.member.displayName}, indexedPastas)); + interaction.update(fn.embeds.pastas({command: "/pastas", author: interaction.user.username}, indexedPastas)); }, requestsPage(interaction) { const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id); @@ -133,7 +133,7 @@ module.exports = { indexedRequests.requestsString += `[${request.id}]: ${request.request} (submitted by ${request.author})\n`; } - interaction.update(fn.embeds.requests({command: "/requests", author: interaction.member.displayName}, indexedRequests)); + interaction.update(fn.embeds.requests({command: "/requests", author: interaction.user.username}, indexedRequests)); }, jointsPage(interaction) { const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id); @@ -159,7 +159,7 @@ module.exports = { indexedJoints.jointsString += `${joint.content}\n`; } - interaction.update(fn.embeds.joints({command: "/joints", author: interaction.member.displayName}, indexedJoints)); + interaction.update(fn.embeds.joints({command: "/joints", author: interaction.user.username}, indexedJoints)); }, gifSearchPage(interaction) { const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id); @@ -197,7 +197,7 @@ module.exports = { indexedGifs.query = iStorage.query; indexedGifs.gifName = iStorage.gifName; // Generate the embed - const gifEmbed = customEmbeds.core.gifSearch({ author: interaction.member.displayName }, indexedGifs); + const gifEmbed = customEmbeds.core.gifSearch({ author: interaction.user.username }, indexedGifs); // Update the interaction interaction.update({ embeds: [gifEmbed], components: [gifSearchAR], ephemeral: true }); } diff --git a/slash-commands/gifs.js b/slash-commands/gifs.js index c372cc0..d44847e 100644 --- a/slash-commands/gifs.js +++ b/slash-commands/gifs.js @@ -23,7 +23,7 @@ module.exports = { } const commandData = { command: "/gifs", - author: interaction.member.displayName + author: interaction.user.username }; interaction.reply(fn.embeds.gifs(commandData, indexedGifs)); } diff --git a/slash-commands/joints.js b/slash-commands/joints.js index bca4490..8bcb435 100644 --- a/slash-commands/joints.js +++ b/slash-commands/joints.js @@ -22,7 +22,7 @@ module.exports = { } const commandData = { command: "/joints", - author: interaction.member.displayName + author: interaction.user.username }; interaction.reply(fn.embeds.joints(commandData, indexedJoints)); }, diff --git a/slash-commands/pastas.js b/slash-commands/pastas.js index 8d43578..5a5c6f4 100644 --- a/slash-commands/pastas.js +++ b/slash-commands/pastas.js @@ -23,7 +23,7 @@ module.exports = { } const commandData = { command: "/pastas", - author: interaction.member.displayName + author: interaction.user.username }; interaction.reply(fn.embeds.pastas(commandData, indexedPastas)); }, diff --git a/slash-commands/requests.js b/slash-commands/requests.js index fbc8b3b..18ec28b 100644 --- a/slash-commands/requests.js +++ b/slash-commands/requests.js @@ -24,7 +24,7 @@ module.exports = { const commandData = { command: "/requests", - author: interaction.member.displayName + author: interaction.user.username }; interaction.reply(fn.embeds.requests(commandData, indexedRequests)); }, diff --git a/slash-commands/save.js b/slash-commands/save.js index fdc990b..a4f8cae 100644 --- a/slash-commands/save.js +++ b/slash-commands/save.js @@ -179,7 +179,7 @@ module.exports = { gifPage.query = query; gifPage.gifName = gifName; // Generate the embed - const gifEmbed = Embeds.core.gifSearch({ author: interaction.member.displayName }, gifPage); + const gifEmbed = Embeds.core.gifSearch({ author: interaction.user.username }, gifPage); interaction.editReply({ embeds: [gifEmbed], components: [actionRow], ephemeral: true }); }); break; diff --git a/slash-commands/view.js b/slash-commands/view.js new file mode 100644 index 0000000..f31c2b4 --- /dev/null +++ b/slash-commands/view.js @@ -0,0 +1,114 @@ +const tenor = require('tenorjs').client({ + 'Key': process.env.tenorAPIKey, // https://tenor.com/developer/keyregistration + 'Filter': 'off', // "off", "low", "medium", "high", not case sensitive + 'Locale': 'en_US', + 'MediaFilter': 'minimal', + 'DateFormat': 'D/MM/YYYY - H:mm:ss A', +}); + +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { Collection } = require('discord.js'); +const fn = require('../functions.js'); +const strings = require('../strings.json'); +const { GifData } = require('../CustomModules/NodBot.js'); +const customEmbeds = require('../CustomModules/Embeds.js'); +const Indexer = require('../CustomModules/Indexer.js'); +const Embeds = require('../CustomModules/Embeds.js'); +const { emoji } = strings; + +module.exports = { + data: new SlashCommandBuilder() + .setName('view') + .setDescription('View content saved in Nodbot\'s database.') +// GIFs + .addSubcommand(subcommand => + subcommand + .setName('gifs') + .setDescription('Display all saved GIFs.') + ) +// Joints + .addSubcommand(subcommand => + subcommand + .setName('joints') + .setDescription('Display all saved joints.') + ) +// Pastas + .addSubcommand(subcommand => + subcommand + .setName('pastas') + .setDescription('Display all saved copypastas.') + ) +// Requests + .addSubcommand(subcommand => + subcommand + .setName('requests') + .setDescription('Display all saved requests.') + ), + async execute(interaction) { + await interaction.deferReply({ ephemeral: true }); + try { + // Code Here... + const subcommand = interaction.options.getSubcommand(); + const iStorage = interaction.client.iStorage.get(interaction.id); + let commandData = { + author: interaction.user.username + } + switch (subcommand) { +// GIFs + case "gifs": + if (!interaction.client.gifs) { + interaction.reply('For some reason I don\'t have access to the collection of gifs. Sorry about that!'); + return; + } + let indexedGifs = Indexer(interaction.client.gifs, 0); + indexedGifs.gifsString = new String(); + + iStorage.page = 0; + + for (const gif of indexedGifs.thisPage) { + indexedGifs.gifsString += `[${gif.name}.gif](${gif.url})\n`; + } + const commandData = { + command: "/gifs", + author: interaction.user.username + }; + interaction.reply(fn.embeds.gifs(commandData, indexedGifs)); + break; +// Joints + case "joints": + if (!interaction.client.joints) { + interaction.reply('For some reason I don\'t have access to the collection of joints. Sorry about that!'); + return; + } + let iStorage = interaction.client.iStorage.get(interaction.id); + let indexedJoints = indexer(interaction.client.joints, 0); + indexedJoints.jointsString = new String(); + + iStorage.page = 0; + + for (const joint of indexedJoints.thisPage) { + indexedJoints.jointsString += `${joint.content}\n`; + } + const commandData = { + command: "/joints", + author: interaction.user.username + }; + interaction.reply(fn.embeds.joints(commandData, indexedJoints)); + break; +// Pastas + case "pastas": + break; +// Requests + case "requests": + break; +// Default + default: + break; + } + } catch (err) { + const errorId = fn.generateErrorId(); + console.error(`${errorId}: err`); + await interaction.editReply(`Sorry, an error has occured. Error ID: ${errorId}`); + } + } +}; \ No newline at end of file -- 2.45.2 From 0e34a0a4bb4f20db956f993f4d98bfed6faba9a5 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 12:28:29 -0400 Subject: [PATCH 12/21] Move to /view --- CustomModules/ButtonHandlers.js | 1 - slash-commands/{gifs.js => gifs.js.bak} | 0 slash-commands/{joints.js => joints.js.bak} | 0 slash-commands/{pastas.js => pastas.js.bak} | 0 .../{requests.js => requests.js.bak} | 0 slash-commands/view.js | 54 ++++++++++++------- 6 files changed, 36 insertions(+), 19 deletions(-) rename slash-commands/{gifs.js => gifs.js.bak} (100%) rename slash-commands/{joints.js => joints.js.bak} (100%) rename slash-commands/{pastas.js => pastas.js.bak} (100%) rename slash-commands/{requests.js => requests.js.bak} (100%) diff --git a/CustomModules/ButtonHandlers.js b/CustomModules/ButtonHandlers.js index 81aa980..f059370 100644 --- a/CustomModules/ButtonHandlers.js +++ b/CustomModules/ButtonHandlers.js @@ -2,7 +2,6 @@ const customEmbeds = require('../CustomModules/Embeds.js'); const InteractionStorage = require('../CustomModules/InteractionStorage.js'); const indexer = require('../CustomModules/Indexer.js'); const fn = require('../functions.js'); -const requests = require('../slash-commands/requests.js'); const { GifData } = require('./NodBot.js'); module.exports = { diff --git a/slash-commands/gifs.js b/slash-commands/gifs.js.bak similarity index 100% rename from slash-commands/gifs.js rename to slash-commands/gifs.js.bak diff --git a/slash-commands/joints.js b/slash-commands/joints.js.bak similarity index 100% rename from slash-commands/joints.js rename to slash-commands/joints.js.bak diff --git a/slash-commands/pastas.js b/slash-commands/pastas.js.bak similarity index 100% rename from slash-commands/pastas.js rename to slash-commands/pastas.js.bak diff --git a/slash-commands/requests.js b/slash-commands/requests.js.bak similarity index 100% rename from slash-commands/requests.js rename to slash-commands/requests.js.bak diff --git a/slash-commands/view.js b/slash-commands/view.js index f31c2b4..798394d 100644 --- a/slash-commands/view.js +++ b/slash-commands/view.js @@ -50,14 +50,15 @@ module.exports = { // Code Here... const subcommand = interaction.options.getSubcommand(); const iStorage = interaction.client.iStorage.get(interaction.id); - let commandData = { - author: interaction.user.username - } + const commandData = { + author: interaction.user.username, + command: `/${interaction.commandName} ${subcommand}` + }; switch (subcommand) { // GIFs case "gifs": if (!interaction.client.gifs) { - interaction.reply('For some reason I don\'t have access to the collection of gifs. Sorry about that!'); + interaction.editReply('For some reason I don\'t have access to the collection of gifs. Sorry about that!'); return; } let indexedGifs = Indexer(interaction.client.gifs, 0); @@ -68,20 +69,15 @@ module.exports = { for (const gif of indexedGifs.thisPage) { indexedGifs.gifsString += `[${gif.name}.gif](${gif.url})\n`; } - const commandData = { - command: "/gifs", - author: interaction.user.username - }; - interaction.reply(fn.embeds.gifs(commandData, indexedGifs)); + interaction.editReply(fn.embeds.gifs(commandData, indexedGifs)); break; // Joints case "joints": if (!interaction.client.joints) { - interaction.reply('For some reason I don\'t have access to the collection of joints. Sorry about that!'); + interaction.editReply('For some reason I don\'t have access to the collection of joints. Sorry about that!'); return; } - let iStorage = interaction.client.iStorage.get(interaction.id); - let indexedJoints = indexer(interaction.client.joints, 0); + let indexedJoints = Indexer(interaction.client.joints, 0); indexedJoints.jointsString = new String(); iStorage.page = 0; @@ -89,17 +85,39 @@ module.exports = { for (const joint of indexedJoints.thisPage) { indexedJoints.jointsString += `${joint.content}\n`; } - const commandData = { - command: "/joints", - author: interaction.user.username - }; - interaction.reply(fn.embeds.joints(commandData, indexedJoints)); + interaction.editReply(fn.embeds.joints(commandData, indexedJoints)); break; // Pastas case "pastas": + if (!interaction.client.pastas) { + interaction.editReply({ content: 'For some reason I don\'t have access to the collection of copypastas. Sorry about that!', ephemeral: true }); + return; + } + let indexedPastas = Indexer(interaction.client.pastas, 0); + indexedPastas.pastasString = new String(); + + iStorage.page = 0; + + for (const pasta of indexedPastas.thisPage) { + indexedPastas.pastasString += `${pasta.name}.pasta\n`; + } + interaction.editReply(fn.embeds.pastas(commandData, indexedPastas)); break; -// Requests case "requests": + if (!interaction.client.requests) { + interaction.editReply('For some reason I don\'t have access to the collection of requests. Sorry about that!'); + return; + } + let indexedRequests = Indexer(interaction.client.requests, 0); + indexedRequests.requestsString = new String(); + + iStorage.page = 0; + + for (const request of indexedRequests.thisPage) { + indexedRequests.requestsString += `[${request.id}]: ${request.request} (submitted by ${request.author})\n`; + } + + interaction.editReply(fn.embeds.requests(commandData, indexedRequests)); break; // Default default: -- 2.45.2 From e6936a5364887d4e6d4694fd8e02458a05bbb9de Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 12:40:54 -0400 Subject: [PATCH 13/21] Update to run on tag push only --- .gitea/workflows/pe-docker.yml | 8 ++++---- .gitea/workflows/production-docker.yml | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/pe-docker.yml b/.gitea/workflows/pe-docker.yml index 9e13c26..3fee87d 100644 --- a/.gitea/workflows/pe-docker.yml +++ b/.gitea/workflows/pe-docker.yml @@ -2,8 +2,8 @@ name: NodBot PE Dockerization on: push: - branches: - - pe + tags: + - 'v*-pe' env: DHUB_UNAME: ${{ secrets.DHUB_UNAME }} @@ -15,7 +15,7 @@ jobs: steps: - name: Pull latest from Git run: | - echo "Branch: ${{ gitea.head_ref }}" + echo "Branch: ${{ gitea.ref_name }}" pwd whoami mkdir -p /var/lib/act_runner/ @@ -27,7 +27,7 @@ jobs: cd nodbot git pull fi - git checkout ${{ gitea.head_ref }} + git checkout ${{ gitea.ref_name }} - name: Build the Docker image run: | cd /var/lib/act_runner/nodbot diff --git a/.gitea/workflows/production-docker.yml b/.gitea/workflows/production-docker.yml index f824157..543e779 100644 --- a/.gitea/workflows/production-docker.yml +++ b/.gitea/workflows/production-docker.yml @@ -1,9 +1,9 @@ name: NodBot Production Dockerization on: - pull_request: - branches: - - main + push: + tags: + - 'v*' env: DHUB_UNAME: ${{ secrets.DHUB_UNAME }} @@ -15,7 +15,7 @@ jobs: steps: - name: Pull latest from Git run: | - echo "Branch: ${{ gitea.head_ref }}" + echo "Branch: ${{ gitea.ref_name }}" pwd whoami mkdir -p /var/lib/act_runner/ @@ -27,7 +27,7 @@ jobs: cd nodbot git pull fi - git checkout ${{ gitea.head_ref }} + git checkout ${{ gitea.ref_name }} git pull - name: Build the Docker image run: | -- 2.45.2 From 0381272d7dbbf93b8a84fcbcf00ce6e595cfa1d7 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 12:41:16 -0400 Subject: [PATCH 14/21] Remove now defunct slash commands --- slash-commands/gifs.js.bak | 30 ------------------------------ slash-commands/joints.js.bak | 29 ----------------------------- slash-commands/pastas.js.bak | 30 ------------------------------ slash-commands/requests.js.bak | 31 ------------------------------- 4 files changed, 120 deletions(-) delete mode 100644 slash-commands/gifs.js.bak delete mode 100644 slash-commands/joints.js.bak delete mode 100644 slash-commands/pastas.js.bak delete mode 100644 slash-commands/requests.js.bak diff --git a/slash-commands/gifs.js.bak b/slash-commands/gifs.js.bak deleted file mode 100644 index d44847e..0000000 --- a/slash-commands/gifs.js.bak +++ /dev/null @@ -1,30 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { config } = require('dotenv'); -const fn = require('../functions.js'); -const indexer = require('../CustomModules/Indexer.js'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('gifs') - .setDescription('Get a list of currently saved GIFs.'), - execute(interaction) { - if (!interaction.client.gifs) { - interaction.reply('For some reason I don\'t have access to the collection of gifs. Sorry about that!'); - return; - } - let iStorage = interaction.client.iStorage.get(interaction.id); - let indexedGifs = indexer(interaction.client.gifs, 0); - indexedGifs.gifsString = new String(); - - iStorage.page = 0; - - for (const gif of indexedGifs.thisPage) { - indexedGifs.gifsString += `[${gif.name}.gif](${gif.url})\n`; - } - const commandData = { - command: "/gifs", - author: interaction.user.username - }; - interaction.reply(fn.embeds.gifs(commandData, indexedGifs)); - } -}; \ No newline at end of file diff --git a/slash-commands/joints.js.bak b/slash-commands/joints.js.bak deleted file mode 100644 index 8bcb435..0000000 --- a/slash-commands/joints.js.bak +++ /dev/null @@ -1,29 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const fn = require('../functions.js'); -const indexer = require('../CustomModules/Indexer.js'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('joints') - .setDescription('Send a list of all the /joint phrases.'), - async execute(interaction) { - if (!interaction.client.joints) { - interaction.reply('For some reason I don\'t have access to the collection of joints. Sorry about that!'); - return; - } - let iStorage = interaction.client.iStorage.get(interaction.id); - let indexedJoints = indexer(interaction.client.joints, 0); - indexedJoints.jointsString = new String(); - - iStorage.page = 0; - - for (const joint of indexedJoints.thisPage) { - indexedJoints.jointsString += `${joint.content}\n`; - } - const commandData = { - command: "/joints", - author: interaction.user.username - }; - interaction.reply(fn.embeds.joints(commandData, indexedJoints)); - }, -}; \ No newline at end of file diff --git a/slash-commands/pastas.js.bak b/slash-commands/pastas.js.bak deleted file mode 100644 index 5a5c6f4..0000000 --- a/slash-commands/pastas.js.bak +++ /dev/null @@ -1,30 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { config } = require('dotenv'); -const fn = require('../functions.js'); -const indexer = require('../CustomModules/Indexer.js'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('pastas') - .setDescription('Get a list of currently saved copypastas.'), - async execute(interaction) { - if (!interaction.client.pastas) { - interaction.reply({ content: 'For some reason I don\'t have access to the collection of copypastas. Sorry about that!', ephemeral: true }); - return; - } - let iStorage = interaction.client.iStorage.get(interaction.id); - let indexedPastas = indexer(interaction.client.pastas, 0); - indexedPastas.pastasString = new String(); - - iStorage.page = 0; - - for (const pasta of indexedPastas.thisPage) { - indexedPastas.pastasString += `${pasta.name}.pasta\n`; - } - const commandData = { - command: "/pastas", - author: interaction.user.username - }; - interaction.reply(fn.embeds.pastas(commandData, indexedPastas)); - }, -}; \ No newline at end of file diff --git a/slash-commands/requests.js.bak b/slash-commands/requests.js.bak deleted file mode 100644 index 18ec28b..0000000 --- a/slash-commands/requests.js.bak +++ /dev/null @@ -1,31 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { config } = require('dotenv'); -const fn = require('../functions.js'); -const indexer = require('../CustomModules/Indexer.js'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('requests') - .setDescription('Get a list of Active requests from the database'), - async execute(interaction) { - if (!interaction.client.requests) { - interaction.reply('For some reason I don\'t have access to the collection of requests. Sorry about that!'); - return; - } - let iStorage = interaction.client.iStorage.get(interaction.id); - let indexedRequests = indexer(interaction.client.requests, 0); - indexedRequests.requestsString = new String(); - - iStorage.page = 0; - - for (const request of indexedRequests.thisPage) { - indexedRequests.requestsString += `[${request.id}]: ${request.request} (submitted by ${request.author})\n`; - } - - const commandData = { - command: "/requests", - author: interaction.user.username - }; - interaction.reply(fn.embeds.requests(commandData, indexedRequests)); - }, -}; \ No newline at end of file -- 2.45.2 From 7f876f4555d0a88e07ec80987251e03464f03bb8 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 13:01:25 -0400 Subject: [PATCH 15/21] Add a dev workflow --- .gitea/workflows/dev-docker | 45 +++++++++++++++++++++++++++++++++ CustomModules/ButtonHandlers.js | 8 ++++++ CustomModules/Embeds.js | 27 +++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/dev-docker diff --git a/.gitea/workflows/dev-docker b/.gitea/workflows/dev-docker new file mode 100644 index 0000000..37e96fb --- /dev/null +++ b/.gitea/workflows/dev-docker @@ -0,0 +1,45 @@ +name: NodBot PE Dockerization + +on: + push: + tags: + - 'v*-dev*' + +env: + DHUB_UNAME: ${{ secrets.DHUB_UNAME }} + DHUB_PWORD: ${{ secrets.DHUB_PWORD }} + +jobs: + build: + runs-on: self-hosted + steps: + - name: Pull latest from Git + run: | + echo "Branch: ${{ gitea.ref_name }}" + pwd + whoami + mkdir -p /var/lib/act_runner/ + cd /var/lib/act_runner/ + if [ ! -d "nodbot" ]; then + git clone https://git.vfsh.dev/voidf1sh/nodbot-dev + cd nodbot-dev + else + cd nodbot-dev + git pull + fi + git checkout ${{ gitea.ref_name }} + - name: Build the Docker image + run: | + cd /var/lib/act_runner/nodbot-dev + docker build . --file Dockerfile --tag v0idf1sh/nodbot-dev + - name: Log into Docker Hub + run: docker login -u $DHUB_UNAME -p $DHUB_PWORD + - name: Push image to Docker Hub + run: | + cd /var/lib/act_runner/nodbot-dev + docker push v0idf1sh/nodbot-dev + - name: Restart the container + run: | + cd /srv/docker/nodbot-dev + docker-compose down + docker-compose up -d \ No newline at end of file diff --git a/CustomModules/ButtonHandlers.js b/CustomModules/ButtonHandlers.js index f059370..57db6d6 100644 --- a/CustomModules/ButtonHandlers.js +++ b/CustomModules/ButtonHandlers.js @@ -52,6 +52,9 @@ module.exports = { case 'cancelGif': module.exports.gifSearchPage(interaction); break; + case 'closeRequests': + module.exports.closeRequests(interaction); + break; default: return; } @@ -199,5 +202,10 @@ module.exports = { const gifEmbed = customEmbeds.core.gifSearch({ author: interaction.user.username }, indexedGifs); // Update the interaction interaction.update({ embeds: [gifEmbed], components: [gifSearchAR], ephemeral: true }); + }, + closeRequests(interaction) { + const closeRequestModal = customEmbeds.modals.closeRequestsModal(); + interaction.showModal(closeRequestModal); + interaction.update({ content: 'The requests menu has been closed.', components: [] }); } } \ No newline at end of file diff --git a/CustomModules/Embeds.js b/CustomModules/Embeds.js index 95f40cb..4a76665 100644 --- a/CustomModules/Embeds.js +++ b/CustomModules/Embeds.js @@ -1,4 +1,4 @@ -const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js'); +const { MessageActionRow, MessageButton, MessageEmbed, TextInputComponent } = require('discord.js'); module.exports = { actionRows: { @@ -73,6 +73,11 @@ module.exports = { .setCustomId('nextRequestsPage') .setLabel('➡️') .setStyle('SECONDARY'); + + const closeButton = new MessageButton() + .setCustomId('closeRequests') + .setLabel('Close Requests') + .setStyle('DANGER'); switch (state) { case 'first': @@ -138,6 +143,26 @@ module.exports = { .addComponents(previousButton, nextButton); } }, + modals: { + closeRequestsModal() { + const requestNumberInput = new TextInputComponent() + .setCustomId('requestNumber') + .setLabel('Request Number') + .setPlaceholder('420') + .setMinLength(1) + .setMaxLength(5) + .setStyle('SHORT') + .setRequired(true); + + const actionRow = new MessageActionRow() + .addComponents([requestNumberInput]); + + return new Modal() + .setTitle('Close Request') + .setDescription('Please enter the number of the request you would like to close.') + .addComponents([actionRow]); + } + }, core: { gifSearch(commandData, indexedGifs) { return new MessageEmbed() -- 2.45.2 From 37d1d9ce1fb4c666ac7cead4ed6202179157adde Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 13:11:03 -0400 Subject: [PATCH 16/21] Fix CI --- .gitea/workflows/dev-docker | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/dev-docker b/.gitea/workflows/dev-docker index 37e96fb..13cfef8 100644 --- a/.gitea/workflows/dev-docker +++ b/.gitea/workflows/dev-docker @@ -25,6 +25,7 @@ jobs: cd nodbot-dev else cd nodbot-dev + git checkout main git pull fi git checkout ${{ gitea.ref_name }} -- 2.45.2 From 43cfb5a7fe6bb85bacea0e819775241c124f1b38 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 13:12:52 -0400 Subject: [PATCH 17/21] Update CI, oops --- .gitea/workflows/{dev-docker => dev-docker.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .gitea/workflows/{dev-docker => dev-docker.yml} (100%) diff --git a/.gitea/workflows/dev-docker b/.gitea/workflows/dev-docker.yml similarity index 100% rename from .gitea/workflows/dev-docker rename to .gitea/workflows/dev-docker.yml -- 2.45.2 From 3bdc03f55326ba20aa3490065321034663f6328a Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 13:19:52 -0400 Subject: [PATCH 18/21] Fix tag calls --- .gitea/workflows/dev-docker.yml | 4 ++-- .gitea/workflows/production-docker.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/dev-docker.yml b/.gitea/workflows/dev-docker.yml index 13cfef8..11ea27e 100644 --- a/.gitea/workflows/dev-docker.yml +++ b/.gitea/workflows/dev-docker.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Pull latest from Git run: | - echo "Branch: ${{ gitea.ref_name }}" + echo "Branch: tags/${{ gitea.ref_name }}" pwd whoami mkdir -p /var/lib/act_runner/ @@ -28,7 +28,7 @@ jobs: git checkout main git pull fi - git checkout ${{ gitea.ref_name }} + git checkout tags/${{ gitea.ref_name }} - name: Build the Docker image run: | cd /var/lib/act_runner/nodbot-dev diff --git a/.gitea/workflows/production-docker.yml b/.gitea/workflows/production-docker.yml index 543e779..5208f73 100644 --- a/.gitea/workflows/production-docker.yml +++ b/.gitea/workflows/production-docker.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Pull latest from Git run: | - echo "Branch: ${{ gitea.ref_name }}" + echo "Branch: tags/${{ gitea.ref_name }}" pwd whoami mkdir -p /var/lib/act_runner/ @@ -27,7 +27,7 @@ jobs: cd nodbot git pull fi - git checkout ${{ gitea.ref_name }} + git checkout tags/${{ gitea.ref_name }} git pull - name: Build the Docker image run: | -- 2.45.2 From a0dc9a5cf5a547b328ecf77eb61bbb7a502b391e Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 13:22:36 -0400 Subject: [PATCH 19/21] Stop prod running on dev --- .gitea/workflows/production-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/production-docker.yml b/.gitea/workflows/production-docker.yml index 5208f73..2dda0bc 100644 --- a/.gitea/workflows/production-docker.yml +++ b/.gitea/workflows/production-docker.yml @@ -3,7 +3,7 @@ name: NodBot Production Dockerization on: push: tags: - - 'v*' + - 'v*-prod*' env: DHUB_UNAME: ${{ secrets.DHUB_UNAME }} -- 2.45.2 From 70fa5aa892070ad384456bb03095783c8c3cc7d8 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 13:23:19 -0400 Subject: [PATCH 20/21] Can't pull on a tag --- .gitea/workflows/production-docker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitea/workflows/production-docker.yml b/.gitea/workflows/production-docker.yml index 2dda0bc..f76f0e6 100644 --- a/.gitea/workflows/production-docker.yml +++ b/.gitea/workflows/production-docker.yml @@ -28,7 +28,6 @@ jobs: git pull fi git checkout tags/${{ gitea.ref_name }} - git pull - name: Build the Docker image run: | cd /var/lib/act_runner/nodbot -- 2.45.2 From 340551fbb2fc22e7f1de759b1e6c77870f924f8a Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sun, 29 Sep 2024 13:25:58 -0400 Subject: [PATCH 21/21] Anoter fix --- .gitea/workflows/dev-docker.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/dev-docker.yml b/.gitea/workflows/dev-docker.yml index 11ea27e..e7908ba 100644 --- a/.gitea/workflows/dev-docker.yml +++ b/.gitea/workflows/dev-docker.yml @@ -21,23 +21,23 @@ jobs: mkdir -p /var/lib/act_runner/ cd /var/lib/act_runner/ if [ ! -d "nodbot" ]; then - git clone https://git.vfsh.dev/voidf1sh/nodbot-dev - cd nodbot-dev + git clone https://git.vfsh.dev/voidf1sh/nodbot + cd nodbot else - cd nodbot-dev + cd nodbot git checkout main git pull fi git checkout tags/${{ gitea.ref_name }} - name: Build the Docker image run: | - cd /var/lib/act_runner/nodbot-dev + cd /var/lib/act_runner/nodbot docker build . --file Dockerfile --tag v0idf1sh/nodbot-dev - name: Log into Docker Hub run: docker login -u $DHUB_UNAME -p $DHUB_PWORD - name: Push image to Docker Hub run: | - cd /var/lib/act_runner/nodbot-dev + cd /var/lib/act_runner/nodbot docker push v0idf1sh/nodbot-dev - name: Restart the container run: | -- 2.45.2