WIP basic card dropping

This commit is contained in:
2022-08-18 19:24:44 +02:00
parent 29e3e6de23
commit ae60732836
13 changed files with 265 additions and 58 deletions

23
util/cards.js Normal file
View File

@@ -0,0 +1,23 @@
const { customAlphabet } = require("nanoid");
const { Card, Character } = require("../models");
module.exports = {
name: "CardUtils",
generateIdentifier: function() {
const nanoid = customAlphabet('6789BCDFGHJKLMNPQRTW',6);
return nanoid();
},
getNextPrintNumber: async function(characterId) {
let count = await Card.count({
where: {
characterId: characterId
}
});
return count + 1;
},
getCharacterCount: async function(characterId) {
return await Character.count();
}
}

View File

@@ -14,7 +14,9 @@ async function syncDb() {
}
module.exports = {
name: "DbUtils",
getDb,
syncDb
}

25
util/index.js Normal file
View File

@@ -0,0 +1,25 @@
'use strict';
const fs = require('fs');
const path = require('path');
const basename = path.basename(__filename);
const utils = {};
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const util = require(path.join(__dirname, file));
utils[util.name] = util;
console.log(`Registered util: ${util.name}`);
});
Object.keys(utils).forEach(modelName => {
if (utils[modelName].associate) {
utils[modelName].associate(utils);
}
});
module.exports = utils;

27
util/reply.js Normal file
View File

@@ -0,0 +1,27 @@
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } = require("discord.js");
module.exports = {
name: "ReplyUtils",
recreateComponents: function(components) {
console.log("Recreating components");
for (let i = 0; i < components.length; i++) {
let row = new ActionRowBuilder();
for (let j = 0; j < components[i].components.length; j++) {
console.log(components[i].components[j]);
console.log(`Recreating button ${components[i].components[j].customId}`);
let button = new ButtonBuilder();
button.setCustomId(components[i].components[j].customId);
button.setLabel(components[i].components[j].label);
button.setStyle(components[i].components[j].style);
if (components[i].components[j].emoji) {
button.setEmoji(components[i].components[j].emoji);
}
if (components[i].components[j].disabled) {
button.setDisabled(components[i].components[j].disabled);
}
row.addComponents(button);
}
return row;
}
},
}

28
util/users.js Normal file
View File

@@ -0,0 +1,28 @@
const { User } = require("../models");
module.exports = {
name: "UserUtils",
getUserByDiscordId: async function(discordId) {
return await User.findOne({
where: {
discordId: discordId
}
});
},
registrationCheck: async function(interaction) {
let user = await this.getUserByDiscordId(interaction.member.id);
if (user) {
return true;
}
if (!interaction.isButton() && interaction.commandName === "register") {
return true;
}
interaction.reply({
content: `${interaction.member} You are not registered, use the /register command`,
ephemeral: false
});
return false;
}
}