Compare commits

..

4 Commits
v3.4.0 ... main

17 changed files with 342 additions and 465 deletions

View File

@ -21,23 +21,23 @@ jobs:
mkdir -p /var/lib/act_runner/ mkdir -p /var/lib/act_runner/
cd /var/lib/act_runner/ cd /var/lib/act_runner/
if [ ! -d "nodbot" ]; then if [ ! -d "nodbot" ]; then
git clone https://git.vfsh.dev/voidf1sh/nodbot git clone https://git.vfsh.dev/voidf1sh/nodbot-dev
cd nodbot cd nodbot-dev
else else
cd nodbot cd nodbot-dev
git checkout main git checkout main
git pull git pull
fi fi
git checkout tags/${{ gitea.ref_name }} git checkout tags/${{ gitea.ref_name }}
- name: Build the Docker image - name: Build the Docker image
run: | run: |
cd /var/lib/act_runner/nodbot cd /var/lib/act_runner/nodbot-dev
docker build . --file Dockerfile --tag v0idf1sh/nodbot-dev docker build . --file Dockerfile --tag v0idf1sh/nodbot-dev
- name: Log into Docker Hub - name: Log into Docker Hub
run: docker login -u $DHUB_UNAME -p $DHUB_PWORD run: docker login -u $DHUB_UNAME -p $DHUB_PWORD
- name: Push image to Docker Hub - name: Push image to Docker Hub
run: | run: |
cd /var/lib/act_runner/nodbot cd /var/lib/act_runner/nodbot-dev
docker push v0idf1sh/nodbot-dev docker push v0idf1sh/nodbot-dev
- name: Restart the container - name: Restart the container
run: | run: |

View File

@ -2,8 +2,8 @@ name: NodBot PE Dockerization
on: on:
push: push:
tags: branches:
- 'v*-pe' - pe
env: env:
DHUB_UNAME: ${{ secrets.DHUB_UNAME }} DHUB_UNAME: ${{ secrets.DHUB_UNAME }}
@ -15,7 +15,7 @@ jobs:
steps: steps:
- name: Pull latest from Git - name: Pull latest from Git
run: | run: |
echo "Branch: ${{ gitea.ref_name }}" echo "Branch: ${{ gitea.head_ref }}"
pwd pwd
whoami whoami
mkdir -p /var/lib/act_runner/ mkdir -p /var/lib/act_runner/
@ -27,7 +27,7 @@ jobs:
cd nodbot cd nodbot
git pull git pull
fi fi
git checkout ${{ gitea.ref_name }} git checkout ${{ gitea.head_ref }}
- name: Build the Docker image - name: Build the Docker image
run: | run: |
cd /var/lib/act_runner/nodbot cd /var/lib/act_runner/nodbot

View File

@ -1,8 +1,3 @@
## 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.x
#### v3.3.3 (#20) #### v3.3.3 (#20)
* Fixed content-list slash commands `/gifs`, `/pastas`, `/joints`, `/requests` (#19) * Fixed content-list slash commands `/gifs`, `/pastas`, `/joints`, `/requests` (#19)

View File

@ -2,7 +2,7 @@ const customEmbeds = require('../CustomModules/Embeds.js');
const InteractionStorage = require('../CustomModules/InteractionStorage.js'); const InteractionStorage = require('../CustomModules/InteractionStorage.js');
const indexer = require('../CustomModules/Indexer.js'); const indexer = require('../CustomModules/Indexer.js');
const fn = require('../functions.js'); const fn = require('../functions.js');
const { GifData } = require('./NodBot.js'); const requests = require('../slash-commands/requests.js');
module.exports = { module.exports = {
baseEvent(interaction) { baseEvent(interaction) {
@ -40,21 +40,6 @@ module.exports = {
case 'nextJointsPage': case 'nextJointsPage':
module.exports.jointsPage(interaction); module.exports.jointsPage(interaction);
break; 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;
case 'closeRequests':
module.exports.closeRequests(interaction);
break;
default: default:
return; return;
} }
@ -83,7 +68,7 @@ module.exports = {
indexedGifs.gifsString += `[${gif.name}.gif](${gif.url})\n`; indexedGifs.gifsString += `[${gif.name}.gif](${gif.url})\n`;
} }
interaction.update(fn.embeds.gifs({command: "/gifs", author: interaction.user.username}, indexedGifs)); interaction.update(fn.embeds.gifs({command: "/gifs", author: interaction.member.displayName}, indexedGifs));
}, },
pastasPage(interaction) { pastasPage(interaction) {
const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id); const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id);
@ -109,7 +94,7 @@ module.exports = {
indexedPastas.pastasString += `${pasta.name}.pasta\n`; indexedPastas.pastasString += `${pasta.name}.pasta\n`;
} }
interaction.update(fn.embeds.pastas({command: "/pastas", author: interaction.user.username}, indexedPastas)); interaction.update(fn.embeds.pastas({command: "/pastas", author: interaction.member.displayName}, indexedPastas));
}, },
requestsPage(interaction) { requestsPage(interaction) {
const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id); const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id);
@ -135,7 +120,7 @@ module.exports = {
indexedRequests.requestsString += `[${request.id}]: ${request.request} (submitted by ${request.author})\n`; indexedRequests.requestsString += `[${request.id}]: ${request.request} (submitted by ${request.author})\n`;
} }
interaction.update(fn.embeds.requests({command: "/requests", author: interaction.user.username}, indexedRequests)); interaction.update(fn.embeds.requests({command: "/requests", author: interaction.member.displayName}, indexedRequests));
}, },
jointsPage(interaction) { jointsPage(interaction) {
const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id); const iStorage = interaction.client.iStorage.get(interaction.message.interaction.id);
@ -161,51 +146,6 @@ module.exports = {
indexedJoints.jointsString += `${joint.content}\n`; indexedJoints.jointsString += `${joint.content}\n`;
} }
interaction.update(fn.embeds.joints({command: "/joints", author: interaction.user.username}, indexedJoints)); 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.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: [] });
} }
} }

View File

@ -1,7 +1,6 @@
const { MessageActionRow, MessageButton, MessageEmbed, TextInputComponent } = require('discord.js'); const { MessageActionRow, MessageButton } = require('discord.js');
module.exports = { module.exports = {
actionRows: {
gifSearchAR(state) { gifSearchAR(state) {
// Setup the buttons // Setup the buttons
const previousButton = new MessageButton() const previousButton = new MessageButton()
@ -11,7 +10,7 @@ module.exports = {
const confirmButton = new MessageButton() const confirmButton = new MessageButton()
.setCustomId('confirmGif') .setCustomId('confirmGif')
.setLabel('Select') .setLabel('')
.setStyle('PRIMARY'); .setStyle('PRIMARY');
const nextButton = new MessageButton() const nextButton = new MessageButton()
@ -21,7 +20,7 @@ module.exports = {
const cancelButton = new MessageButton() const cancelButton = new MessageButton()
.setCustomId('cancelGif') .setCustomId('cancelGif')
.setLabel('Cancel') .setLabel('')
.setStyle('DANGER'); .setStyle('DANGER');
switch (state) { switch (state) {
@ -74,11 +73,6 @@ module.exports = {
.setLabel('➡️') .setLabel('➡️')
.setStyle('SECONDARY'); .setStyle('SECONDARY');
const closeButton = new MessageButton()
.setCustomId('closeRequests')
.setLabel('Close Requests')
.setStyle('DANGER');
switch (state) { switch (state) {
case 'first': case 'first':
previousButton.setDisabled(true); previousButton.setDisabled(true);
@ -142,38 +136,4 @@ module.exports = {
return new MessageActionRow() return new MessageActionRow()
.addComponents(previousButton, nextButton); .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()
.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 },
);
}
}
} }

View File

@ -1,5 +1,5 @@
module.exports = (collection, page, qty) => { module.exports = (collection, page) => {
const itemsPerPage = qty ? qty : 10; const itemsPerPage = 10;
const index = page * itemsPerPage; const index = page * itemsPerPage;
const totalPages = Math.ceil(collection.size / itemsPerPage); const totalPages = Math.ceil(collection.size / itemsPerPage);
let state = page === 0 ? 'first' : 'middle'; let state = page === 0 ? 'first' : 'middle';

View File

@ -8,7 +8,6 @@ module.exports = {
this.args = message.content.slice(0,this.finalPeriod).toLowerCase(); // Grab everything leading up to the final period 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.command = message.content.slice(this.finalPeriod + 1).toLowerCase(); // Grab everything after the final period
this.author = message.author.username; this.author = message.author.username;
this.message = message;
return this; return this;
} }
@ -17,110 +16,14 @@ module.exports = {
if (this.args.startsWith('http')) return false; if (this.args.startsWith('http')) return false;
if (this.args.startsWith('www')) 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 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;
}
}
}
}
for (const [key, value] of dotCommands) { for (const [key, value] of dotCommands) {
if (key === this.command) { if (key === this.command) {
this.isValid = true; this.isValid = true;
return this; return this;
} else if (value.alias) { } else if (value.alias && value.alias.includes(this.command)) {
if (typeof value.alias === 'string' && value.alias === this.command) {
this.command = key; this.command = key;
this.isValid = true; this.isValid = true;
return this; return this;
} else if (typeof value.alias === 'object' && value.alias.includes(this.command)) {
this.command = key;
this.isValid = true;
return this;
}
} }
} }
return this; return this;

View File

@ -10,10 +10,6 @@ module.exports = {
// Also checks for validity of ICAOs // Also checks for validity of ICAOs
const icaoList = fn.avWx.parseICAOs(commandData); const icaoList = fn.avWx.parseICAOs(commandData);
const metarData = await fn.avWx.metar.getData(icaoList); 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); const messages = fn.avWx.metar.parseData(metarData);
messages.forEach(messagePayload => { messages.forEach(messagePayload => {
message.reply(messagePayload); message.reply(messagePayload);

View File

@ -270,7 +270,7 @@ const functions = {
.setFooter({text: `Page: ${indexedPastas.pagesString}`}) .setFooter({text: `Page: ${indexedPastas.pagesString}`})
.setDescription(indexedPastas.pastasString); .setDescription(indexedPastas.pastasString);
const pastasPageAR = customEmbeds.actionRows.pastasPageAR(indexedPastas.state); const pastasPageAR = customEmbeds.pastasPageAR(indexedPastas.state);
return { embeds: [pastasEmbed], components: [pastasPageAR], ephemeral: true }; return { embeds: [pastasEmbed], components: [pastasPageAR], ephemeral: true };
}, },
gifs(commandData, indexedGifs) { gifs(commandData, indexedGifs) {
@ -280,7 +280,7 @@ const functions = {
.setFooter({text: `Page: ${indexedGifs.pagesString}`}) .setFooter({text: `Page: ${indexedGifs.pagesString}`})
.setDescription(indexedGifs.gifsString); .setDescription(indexedGifs.gifsString);
const gifsPageAR = customEmbeds.actionRows.gifsPageAR(indexedGifs.state); const gifsPageAR = customEmbeds.gifsPageAR(indexedGifs.state);
return { embeds: [gifsEmbed], components: [gifsPageAR], ephemeral: true }; return { embeds: [gifsEmbed], components: [gifsPageAR], ephemeral: true };
}, },
joints(commandData, indexedJoints) { joints(commandData, indexedJoints) {
@ -290,7 +290,7 @@ const functions = {
.setFooter({text: `Page: ${indexedJoints.pagesString}`}) .setFooter({text: `Page: ${indexedJoints.pagesString}`})
.setDescription(indexedJoints.jointsString); .setDescription(indexedJoints.jointsString);
const jointsPageAR = customEmbeds.actionRows.jointsPageAR(indexedJoints.state); const jointsPageAR = customEmbeds.jointsPageAR(indexedJoints.state);
return { embeds: [jointsEmbed], components: [jointsPageAR], ephemeral: true }; return { embeds: [jointsEmbed], components: [jointsPageAR], ephemeral: true };
}, },
text(commandData) { text(commandData) {
@ -307,7 +307,7 @@ const functions = {
.setFooter({text: `Page: ${indexedRequests.pagesString}`}) .setFooter({text: `Page: ${indexedRequests.pagesString}`})
.setDescription(indexedRequests.requestsString); .setDescription(indexedRequests.requestsString);
const requestsPageAR = customEmbeds.actionRows.requestsPageAR(indexedRequests.state); const requestsPageAR = customEmbeds.requestsPageAR(indexedRequests.state);
return { embeds: [requestsEmbed], components: [requestsPageAR], ephemeral: true }; return { embeds: [requestsEmbed], components: [requestsPageAR], ephemeral: true };
}, },
strain(strainInfo, interaction) { strain(strainInfo, interaction) {

110
main.js
View File

@ -76,7 +76,117 @@ client.on('interactionCreate', async interaction => {
if (interaction.isButton()) { if (interaction.isButton()) {
if (isDev) console.log('Origin Interaction ID: ' + interaction.message.interaction.id); if (isDev) console.log('Origin Interaction ID: ' + interaction.message.interaction.id);
if (isDev) console.log('Button ID: ' + interaction.component.customId); 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); ButtonHandlers.baseEvent(interaction);
break;
}
} }
// Handle autocomplete requests // Handle autocomplete requests

View File

@ -1,7 +1,7 @@
{ {
"name": "nodbot", "name": "nodbot",
"version": "3.4.0", "version": "3.3.3",
"description": "Nods and Nod Accessories", "description": "Nods and Nod Accessories, now with ChatGPT!",
"main": "main.js", "main": "main.js",
"dependencies": { "dependencies": {
"@discordjs/builders": "^0.16.0", "@discordjs/builders": "^0.16.0",

30
slash-commands/gifs.js Normal file
View File

@ -0,0 +1,30 @@
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.member.displayName
};
interaction.reply(fn.embeds.gifs(commandData, indexedGifs));
}
};

29
slash-commands/joints.js Normal file
View File

@ -0,0 +1,29 @@
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.member.displayName
};
interaction.reply(fn.embeds.joints(commandData, indexedJoints));
},
};

30
slash-commands/pastas.js Normal file
View File

@ -0,0 +1,30 @@
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.member.displayName
};
interaction.reply(fn.embeds.pastas(commandData, indexedPastas));
},
};

View File

@ -0,0 +1,31 @@
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.member.displayName
};
interaction.reply(fn.embeds.requests(commandData, indexedRequests));
},
};

View File

@ -7,13 +7,11 @@ const tenor = require('tenorjs').client({
}); });
const { SlashCommandBuilder } = require('@discordjs/builders'); const { SlashCommandBuilder } = require('@discordjs/builders');
const { Collection } = require('discord.js'); const { MessageActionRow, MessageButton } = require('discord.js');
const fn = require('../functions.js'); const fn = require('../functions.js');
const strings = require('../strings.json'); const strings = require('../strings.json');
const { GifData } = require('../CustomModules/NodBot.js'); const { GifData } = require('../CustomModules/NodBot.js');
const customEmbeds = require('../CustomModules/Embeds.js'); const customEmbeds = require('../CustomModules/Embeds.js');
const Indexer = require('../CustomModules/Indexer.js');
const Embeds = require('../CustomModules/Embeds.js');
const { emoji } = strings; const { emoji } = strings;
module.exports = { module.exports = {
@ -144,21 +142,15 @@ module.exports = {
switch (subcommand) { switch (subcommand) {
// GIF Search // GIF Search
case "gifsearch": case "gifsearch":
// Grab the inputs from the command // TODO Check on option names
const actionRow = customEmbeds.gifSearchAR();
// Get the query
const query = interaction.options.getString('query'); const query = interaction.options.getString('query');
const gifName = interaction.options.getString('name').toLowerCase(); strings.temp.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 // Search Tenor for the GIF
tenor.Search.Query(query, '20').then(res => { tenor.Search.Query(query, '10').then(res => {
strings.temp.gifs = []; strings.temp.gifs = [];
strings.temp.gifIndex = 0; strings.temp.gifIndex = 0;
strings.temp.gifLimit = res.length - 1; strings.temp.gifLimit = res.length - 1;
@ -169,18 +161,11 @@ module.exports = {
return; return;
} }
for (const row of res) { for (const row of res) {
iStorage.gifsCollection.set(row.id, row); strings.temp.gifs.push({
embed_url: row.media_formats.gif.url,
});
} }
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.user.username }, gifPage);
interaction.editReply({ embeds: [gifEmbed], components: [actionRow], ephemeral: true });
}); });
break; break;
// GIF URL // GIF URL

View File

@ -1,132 +0,0 @@
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);
const commandData = {
author: interaction.user.username,
command: `/${interaction.commandName} ${subcommand}`
};
switch (subcommand) {
// GIFs
case "gifs":
if (!interaction.client.gifs) {
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);
indexedGifs.gifsString = new String();
iStorage.page = 0;
for (const gif of indexedGifs.thisPage) {
indexedGifs.gifsString += `[${gif.name}.gif](${gif.url})\n`;
}
interaction.editReply(fn.embeds.gifs(commandData, indexedGifs));
break;
// Joints
case "joints":
if (!interaction.client.joints) {
interaction.editReply('For some reason I don\'t have access to the collection of joints. Sorry about that!');
return;
}
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`;
}
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;
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:
break;
}
} catch (err) {
const errorId = fn.generateErrorId();
console.error(`${errorId}: err`);
await interaction.editReply(`Sorry, an error has occured. Error ID: ${errorId}`);
}
}
};