Generalize labels and options
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const { SlashCommandBuilder, AttachmentBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } = require("discord.js");
|
||||
const { Card, User, Band, Character } = require("../models");
|
||||
const { Card, User, Group, Character } = require("../models");
|
||||
const { QUALITY_VALUES, QUALITY_NAMES, CURRENCY_SYMBOLS } = require("../config/constants");
|
||||
const { UserUtils } = require("../util");
|
||||
const fs = require("fs");
|
||||
@@ -26,7 +26,7 @@ module.exports = {
|
||||
identifier: interaction.options.getString("id")
|
||||
},
|
||||
include: [
|
||||
{ model: Character, include: [{ model: Band }] },
|
||||
{ model: Character, include: [{ model: Group }] },
|
||||
{ model: User}
|
||||
]
|
||||
});
|
||||
@@ -47,7 +47,7 @@ module.exports = {
|
||||
.setTitle(`${interaction.member.displayName} burned ${card.identifier}`)
|
||||
.setDescription(`+${QUALITY_VALUES[card.quality].value} ${CURRENCY_SYMBOLS[QUALITY_VALUES[card.quality].type]}`)
|
||||
.addFields(
|
||||
{ name: `${card.Character.name}`, value: `${card.Character.Band.name}` },
|
||||
{ name: `${card.Character.name}`, value: `${card.Character.Group.name}` },
|
||||
{ name: 'Print Number', value: `${card.printNr}`, inline: true },
|
||||
{ name: 'Quality', value: `${QUALITY_NAMES[card.quality]}`, inline: true }
|
||||
)
|
||||
|
||||
@@ -19,8 +19,8 @@ module.exports = {
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("band")
|
||||
.setDescription("Band to filter by")
|
||||
.setName("group")
|
||||
.setDescription("Group to filter by")
|
||||
.setRequired(false)
|
||||
.setAutocomplete(true)
|
||||
)
|
||||
@@ -57,7 +57,7 @@ module.exports = {
|
||||
|
||||
const filter = {
|
||||
character: interaction.options.getString("character"),
|
||||
band: interaction.options.getString("band"),
|
||||
group: interaction.options.getString("group"),
|
||||
quality: interaction.options.getString("quality")
|
||||
}
|
||||
|
||||
@@ -145,8 +145,8 @@ module.exports = {
|
||||
filter["where"]["characterId"] = filterParam["character"];
|
||||
}
|
||||
|
||||
if (filterParam["band"]) {
|
||||
filter["where"]['$Character.bandId$'] = filterParam["band"];
|
||||
if (filterParam["group"]) {
|
||||
filter["where"]['$Character.groupId$'] = filterParam["group"];
|
||||
}
|
||||
|
||||
if (filterParam["quality"]) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { SlashCommandBuilder, ComponentType, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder, TextInputStyle, TextInputBuilder } = require("discord.js");
|
||||
const { Character, Band, RecordHistory } = require("../models");
|
||||
const { Character, Group, RecordHistory } = require("../models");
|
||||
const { UserUtils, GeneralUtils } = require("../util");
|
||||
const axios = require("axios");
|
||||
const fs = require("fs");
|
||||
@@ -15,7 +15,7 @@ module.exports = {
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: 'character', value: 'character' },
|
||||
{ name: 'band', value: 'band' }
|
||||
{ name: 'group', value: 'group' }
|
||||
)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
@@ -39,14 +39,14 @@ module.exports = {
|
||||
let record;
|
||||
switch (interaction.options?.getString("type") ?? type) {
|
||||
case "character":
|
||||
record = await Character.findByPk(interaction.options?.getString("id") ?? id, { include: Band });
|
||||
record = await Character.findByPk(interaction.options?.getString("id") ?? id, { include: Group });
|
||||
if (!record) {
|
||||
interaction.editReply({ content: "Character not found" });
|
||||
return;
|
||||
}
|
||||
options = [ "name", "description", "imageIdentifier" ];
|
||||
break;
|
||||
case "band":
|
||||
case "group":
|
||||
options = [ "name", "description" ];
|
||||
break;
|
||||
default:
|
||||
@@ -102,7 +102,7 @@ module.exports = {
|
||||
await m.reply({ content: "An invalid image has been attached", ephemeral: true });
|
||||
return;
|
||||
}
|
||||
let identifier = `${record.Band.name.replace(" ", "_")}/${image.name}`;
|
||||
let identifier = `${record.Group.name.replace(" ", "_")}/${image.name}`;
|
||||
let path = `/app/assets/cards/${identifier}`;
|
||||
await this.downloadImage(image.attachment, path);
|
||||
await this.updateRecord(user, record, option, identifier);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { SlashCommandBuilder, AttachmentBuilder } = require("discord.js");
|
||||
const { Card, Character, Band } = require("../models");
|
||||
const { Card, Character, Group } = require("../models");
|
||||
|
||||
//fetch all cards owned by the user and list them
|
||||
module.exports = {
|
||||
@@ -11,7 +11,7 @@ module.exports = {
|
||||
.setDescription('Entity type')
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: 'Band', value: 'band' },
|
||||
{ name: 'Group', value: 'group' },
|
||||
{ name: 'Character', value: 'character' },
|
||||
{ name: 'DEBUG', value: 'debug' },
|
||||
)
|
||||
@@ -36,38 +36,38 @@ module.exports = {
|
||||
await interaction.deferReply();
|
||||
const type = interaction.options.getString('type');
|
||||
|
||||
if (type === 'band') {
|
||||
let band = await Band.findOne({
|
||||
if (type === 'group') {
|
||||
let group = await Group.findOne({
|
||||
where: {
|
||||
id: interaction.options.getInteger('id')
|
||||
}
|
||||
});
|
||||
if (!band) {
|
||||
if (!group) {
|
||||
interaction.editReply({
|
||||
content: "Band not found",
|
||||
content: "Group not found",
|
||||
ephemeral: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
await band.update({
|
||||
await group.update({
|
||||
enabled: interaction.options.getBoolean('enabled')
|
||||
});
|
||||
|
||||
if (interaction.options.getBoolean('include_children')) {
|
||||
let characters = await Character.findAll({
|
||||
where: {
|
||||
bandId: band.id
|
||||
groupId: group.id
|
||||
}
|
||||
});
|
||||
Character.update({
|
||||
enabled: (interaction.options.getBoolean('enabled') ? 1 : 0)}, {
|
||||
where: { bandId: band.id }
|
||||
where: { groupId: group.id }
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
content: `${band.name} is now `
|
||||
content: `${group.name} is now `
|
||||
+ `${(interaction.options.getBoolean('enabled') ? 'active' : 'inactive')} `
|
||||
+ `(Including children: ${(interaction.options.getBoolean('include_children') ? 'yes' : 'no')})`
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { SlashCommandBuilder, AttachmentBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } = require("discord.js");
|
||||
const { Card, User, Band, Character } = require("../models");
|
||||
const { Card, User, Group, Character } = require("../models");
|
||||
const { Rendering, UserUtils } = require("../util");
|
||||
const { QUALITY_NAMES } = require("../config/constants");
|
||||
const fs = require("fs");
|
||||
@@ -18,7 +18,7 @@ module.exports = {
|
||||
.addChoices(
|
||||
{ name: 'card', value: 'card' },
|
||||
{ name: 'character', value: 'character' },
|
||||
{ name: 'band', value: 'band' }
|
||||
{ name: 'group', value: 'group' }
|
||||
)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
@@ -39,8 +39,8 @@ module.exports = {
|
||||
case "character":
|
||||
this.viewCharacter(interaction, interaction.options.getString("id"));
|
||||
break;
|
||||
case "band":
|
||||
interaction.editReply({ content: "Band view is not yet implemented" });
|
||||
case "group":
|
||||
interaction.editReply({ content: "Group view is not yet implemented" });
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -52,7 +52,7 @@ module.exports = {
|
||||
identifier: cardIdentifier
|
||||
},
|
||||
include: [
|
||||
{ model: Character, include: [{ model: Band }] },
|
||||
{ model: Character, include: [{ model: Group }] },
|
||||
{ model: User}
|
||||
]
|
||||
});
|
||||
@@ -83,10 +83,10 @@ module.exports = {
|
||||
.setTitle(`${card.Character.name}`)
|
||||
.setDescription(description)
|
||||
.setImage(`attachment://${filename}`)
|
||||
.setThumbnail(card.Character.Band.imageURL)
|
||||
.setThumbnail(card.Character.Group.imageURL)
|
||||
.addFields(
|
||||
{ name: "Owned by", value: `<@${card.User.discordId}>` },
|
||||
{ name: "Band", value: `${card.Character.Band.name}` },
|
||||
{ name: "Group", value: `${card.Character.Group.name}` },
|
||||
{ name: "Character ID", value: `${card.Character.id}` },
|
||||
{ name: 'Print Number', value: `${card.printNr}`, inline: true },
|
||||
{ name: 'Quality', value: `${QUALITY_NAMES[card.quality]} ${(card.quality === 6 ? '<a:sparklu:1019505245572837428>':'')}`, inline: true }
|
||||
@@ -105,7 +105,7 @@ module.exports = {
|
||||
let isAdmin = await UserUtils.getPermissionLevel(interaction.member) == 2;
|
||||
let character = await Character.findOne({
|
||||
where: { id: characterId },
|
||||
include: [Band]
|
||||
include: [Group]
|
||||
});
|
||||
if (!character) {
|
||||
interaction.editReply({ content: "Character not found" });
|
||||
@@ -139,9 +139,9 @@ module.exports = {
|
||||
.setTitle(`${character.name}`)
|
||||
.setDescription(description)
|
||||
.setImage(`attachment://${filename}`)
|
||||
.setThumbnail(character.Band.imageURL)
|
||||
.setThumbnail(character.Group.imageURL)
|
||||
.addFields(
|
||||
{ name: "Band", value: `${character.Band.name}` },
|
||||
{ name: "Group", value: `${character.Group.name}` },
|
||||
{ name: "Character ID", value: `${character.id}` },
|
||||
)
|
||||
.setColor(0x00ff00)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { InteractionType } = require('discord.js');
|
||||
const { UserUtils } = require('../util');
|
||||
const { Card, Character, User, Band } = require('../models');
|
||||
const { Card, Character, User, Group } = require('../models');
|
||||
const Sequelize = require('sequelize');
|
||||
const { QUALITY_NAMES } = require('../config/constants');
|
||||
const { TestStore } = require('../stores');
|
||||
@@ -49,13 +49,13 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'band':
|
||||
case 'group':
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (interaction.commandName === 'collection') {
|
||||
const character = interaction.options.getString('character');
|
||||
const band = interaction.options.getString('band');
|
||||
const group = interaction.options.getString('group');
|
||||
const quality = interaction.options.getString('quality');
|
||||
//TODO: avoid duplicate code hehe
|
||||
switch (focusedOption.name) {
|
||||
@@ -76,9 +76,9 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'band':
|
||||
case 'group':
|
||||
if(focusedOption.value.length < 3) break;
|
||||
const bands = await Band.findAll({
|
||||
const groups = await Group.findAll({
|
||||
where: {
|
||||
name: {
|
||||
[Sequelize.Op.like]: `%${focusedOption.value}%`
|
||||
@@ -86,10 +86,10 @@ module.exports = {
|
||||
},
|
||||
limit: 10
|
||||
});
|
||||
for (let i = 0; i < bands.length; i++) {
|
||||
for (let i = 0; i < groups.length; i++) {
|
||||
choices.push({
|
||||
name: bands[i].name,
|
||||
value: `${bands[i].id}`
|
||||
name: groups[i].name,
|
||||
value: `${groups[i].id}`
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
46
import.js
46
import.js
@@ -2,7 +2,7 @@ require("dotenv").config();
|
||||
const { Console } = require("console");
|
||||
const fs = require("fs");
|
||||
const dbUtil = require("./util/db")
|
||||
const { Band, Character } = require("./models");
|
||||
const { Group, Character } = require("./models");
|
||||
|
||||
const logger = new Console({
|
||||
stdout: process.stdout,
|
||||
@@ -13,37 +13,37 @@ const logger = new Console({
|
||||
async function runImport() {
|
||||
dbUtil.syncDb();
|
||||
db = dbUtil.getDb();
|
||||
await importBands();
|
||||
await importGroups();
|
||||
await importCharacters();
|
||||
}
|
||||
|
||||
async function importBands() {
|
||||
const bandFiles = fs.readdirSync("./assets/import/bands").filter(file => file.endsWith(".json"));
|
||||
async function importGroups() {
|
||||
const groupFiles = fs.readdirSync("./assets/import/groups").filter(file => file.endsWith(".json"));
|
||||
//read json file and parse it into a javascript object
|
||||
for (const file of bandFiles) {
|
||||
let band = fs.readFileSync(`./assets/import/bands/${file}`);
|
||||
band = JSON.parse(band);
|
||||
logger.log(`Importing band: ${band.name}`);
|
||||
//check if band exists in database
|
||||
let existingBand = await db.Band.findOne({
|
||||
for (const file of groupFiles) {
|
||||
let group = fs.readFileSync(`./assets/import/groups/${file}`);
|
||||
group = JSON.parse(group);
|
||||
logger.log(`Importing group: ${group.name}`);
|
||||
//check if group exists in database
|
||||
let existingGroup = await db.Group.findOne({
|
||||
where: {
|
||||
name: band.name
|
||||
name: group.name
|
||||
}
|
||||
})
|
||||
|
||||
if (existingBand) {
|
||||
logger.log(`Band ${band.name} already exists in database`);
|
||||
if (existingGroup) {
|
||||
logger.log(`Group ${group.name} already exists in database`);
|
||||
continue;
|
||||
} else {
|
||||
//create band in database
|
||||
await db.Band.create({
|
||||
id: band.id,
|
||||
name: band.name,
|
||||
description: band.description,
|
||||
imageURL: band.imageURL,
|
||||
enabled: band.enabled
|
||||
//create group in database
|
||||
await db.Group.create({
|
||||
id: group.id,
|
||||
name: group.name,
|
||||
description: group.description,
|
||||
imageURL: group.imageURL,
|
||||
enabled: group.enabled
|
||||
});
|
||||
logger.log(`Created band ${band.name} in database`);
|
||||
logger.log(`Created group ${group.name} in database`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,10 +67,10 @@ async function importCharacters() {
|
||||
logger.log(`Character ${character.name} already exists in database`);
|
||||
continue;
|
||||
} else {
|
||||
//create band in database
|
||||
//create group in database
|
||||
await db.Character.create({
|
||||
id: character.id,
|
||||
bandId: character.bandId,
|
||||
groupId: character.groupId,
|
||||
name: character.name,
|
||||
description: character.description,
|
||||
imageIdentifier: character.imageIdentifier,
|
||||
|
||||
Reference in New Issue
Block a user