/edit pasta, setFooter, PastaData Classification

This commit is contained in:
Skylar Grant 2023-08-08 14:34:46 -04:00
parent cb834cb7ee
commit f3051ec944
4 changed files with 71 additions and 32 deletions

View File

@ -1,15 +1,52 @@
module.exports = {
GifData: class {
constructor() {
this.gifName = "";
this.gifUrl = "";
this.id = 0;
this.name = "";
this.url = "";
}
setInfo(name, url) {
if ((!name) || (!url)) throw `Expected a name and url, receieved {name: ${name}, url: ${url}}`;
this.name = name;
this.url = url;
return this;
// Initial GifData configuration
// Can also be used to update the data piecemeal
setInfo(name, url, id) {
// Check for existing or incoming name
if ((this.name === "") && (typeof name !== 'string')) throw `Error: This Gif doesn't have existing name, and no name is going to be set.`;
// Check for existing content or incoming content
if ((this.url === "") && (typeof url !== 'string')) throw `Error: This Gif doesn't have existing url, and no url is going to be set.`;
// Property is set if the variable is the right type,
// otherwise it keeps the existing property
this.id = typeof id === 'number' ? id : this.id;
this.name = typeof name === 'string' ? name : this.name;
this.url = typeof url === 'string' ? url : this.url;
return this; // For chaining
}
},
PastaData: class {
constructor() {
this.id = 0;
this.name = "";
this.content = "";
this.iconUrl = "";
}
// Initial PastaData configuration
// Can also be used to update the data piecemeal
setInfo(name, content, iconUrl, id) {
// Check for existing or incoming name
if ((this.name === "") && (typeof name !== 'string')) throw `Error: This Pasta doesn't have existing name, and no name is going to be set.`;
// Check for existing content or incoming content
if ((this.content === "") && (typeof content !== 'string')) throw `Error: This Pasta doesn't have existing content, and no content is going to be set.`;
// Property is set if the variable is the right type,
// otherwise it keeps the existing property
this.id = typeof id === 'number' ? id : this.id;
this.name = typeof name === 'string' ? name : this.name;
this.content = typeof content === 'string' ? content : this.content;
this.iconUrl = typeof iconUrl === 'string' ? iconUrl : this.iconUrl;
return this; // For chaining
}
}
}

View File

@ -6,14 +6,12 @@ module.exports = {
usage: '<Copypasta Name>.pasta',
execute(message, commandData) {
const client = message.client;
let replyBody = '';
let iconUrl;
let pastaData;
if (!client.pastas.has(commandData.args)) {
commandData.content = 'Sorry I couldn\'t find that pasta.';
} else {
commandData.content = client.pastas.get(commandData.args).content;
commandData.iconUrl = client.pastas.get(commandData.args).iconUrl;
pastaData = client.pastas.get(commandData.args);
}
message.reply(fn.embeds.pasta(commandData));
message.reply(fn.embeds.pasta(commandData, pastaData));
}
}

View File

@ -45,7 +45,7 @@ const dotCommandFiles = fs.readdirSync('./dot-commands/').filter(file => file.en
// MySQL database connection
const mysql = require('mysql');
const { GifData } = require('./CustomModules/NodBot');
const { GifData, PastaData } = require('./CustomModules/NodBot');
const db = new mysql.createPool({
connectionLimit: 10,
host: dbHost,
@ -129,13 +129,8 @@ const functions = {
if (!client.pastas) client.pastas = new Discord.Collection();
client.pastas.clear();
for (const row of rows) {
const pasta = {
id: row.id,
name: row.name,
content: row.content,
iconUrl: row.iconurl,
};
client.pastas.set(pasta.name, pasta);
const pastaData = new PastaData().setInfo(row.name, row.content, row.iconurl, row.id);
client.pastas.set(pastaData.name, pastaData);
}
if (isDev) console.log('Pastas Collection Built');
},
@ -183,7 +178,7 @@ const functions = {
const commandData = {};
// Split the message content at the final instance of a period
const finalPeriod = message.content.lastIndexOf('.');
if(isDev) console.log(message.content);
// if(isDev) console.log(message.content);
// If the final period is the last character, or doesn't exist
if (finalPeriod < 0) {
if (isDev) console.log(finalPeriod);
@ -195,7 +190,7 @@ const functions = {
commandData.args = message.content.slice(0,finalPeriod).toLowerCase();
// Get the last part of the message, everything after the final period
commandData.command = message.content.slice(finalPeriod).replace('.','').toLowerCase();
commandData.author = `${message.author.username}#${message.author.discriminator}`;
commandData.author = `${message.author.username}`;
return this.checkCommand(commandData);
},
checkCommand(commandData) {
@ -273,22 +268,22 @@ const functions = {
.setAuthor({name: `${commandData.args}.${commandData.command}`})
.setImage(commandData.embed_url)
.setTimestamp()
.setFooter(commandData.author)]};
.setFooter({text: commandData.author})]};
},
pasta(commandData) {
pasta(commandData, pastaData) {
return { embeds: [ new Discord.MessageEmbed()
.setAuthor({name: `${commandData.args}.${commandData.command}`})
.setDescription(commandData.content)
.setThumbnail(commandData.iconUrl)
.setDescription(pastaData.content)
.setThumbnail(pastaData.iconUrl)
.setTimestamp()
.setFooter(commandData.author)]};
.setFooter({text: commandData.author})]};
},
pastas(commandData) {
const pastasArray = [];
const pastasEmbed = new Discord.MessageEmbed()
.setAuthor({name: commandData.command})
.setTimestamp()
.setFooter(commandData.author);
.setFooter({text: commandData.author});
for (const row of commandData.pastas) {
pastasArray.push(`#${row.id} - ${row.name}.pasta`);
@ -303,7 +298,7 @@ const functions = {
const gifsEmbed = new Discord.MessageEmbed()
.setAuthor({name: commandData.command})
.setTimestamp()
.setFooter(commandData.author)
.setFooter({text: commandData.author})
.setDescription(gifList.join('\n'));
return { embeds: [gifsEmbed] };
@ -313,13 +308,13 @@ const functions = {
.setAuthor({name: commandData.command})
.setDescription(commandData.content)
.setTimestamp()
.setFooter(commandData.author)]};
.setFooter({text: commandData.author})]};
},
requests(commandData) {
const requestsEmbed = new Discord.MessageEmbed()
.setAuthor({name: commandData.command})
.setTimestamp()
.setFooter(commandData.author);
.setFooter({text: commandData.author});
const requestsArray = [];

View File

@ -8,7 +8,7 @@ const tenor = require('tenorjs').client({
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageActionRow, MessageButton } = require('discord.js');
const { GifData } = require('../CustomModules/NodBot');
const { GifData, PastaData } = require('../CustomModules/NodBot');
const fn = require('../functions.js');
const strings = require('../strings.json');
const { emoji } = strings;
@ -17,6 +17,7 @@ module.exports = {
data: new SlashCommandBuilder()
.setName('edit')
.setDescription('Edit content in Nodbot\'s database.')
// GIF
.addSubcommand(subcommand =>
subcommand
.setName('gif')
@ -35,6 +36,7 @@ module.exports = {
.setRequired(true)
)
)
// Pasta
.addSubcommand(subcommand =>
subcommand
.setName('pasta')
@ -75,6 +77,7 @@ module.exports = {
// Pasta
case "pasta":
//TODO
await this.editPasta(interaction, interaction.options.getString('name'), interaction.options.getString('content'));
break;
// Strain
case "strain":
@ -97,5 +100,11 @@ module.exports = {
await fn.upload.gif(gifData, interaction.client);
await fn.download.gifs(interaction.client);
await interaction.editReply(`I've updated ${gifData.name}.gif`);
},
async editPasta(interaction, name, content) {
const pastaData = new PastaData().setInfo(name, content);
await fn.upload.pasta(pastaData, interaction.client);
await fn.download.gifs(interaction.client);
await interaction.editReply(`I've updated ${name}.pasta`);
}
};