Collection: Add options to filter by name,band and quality

This commit is contained in:
2023-01-19 23:57:04 +01:00
parent 98d4f5c2ac
commit 9661c65b27
2 changed files with 116 additions and 36 deletions

View File

@@ -1,6 +1,6 @@
const { InteractionType } = require('discord.js');
const { UserUtils } = require('../util');
const { Card, Character, User } = require('../models');
const { Card, Character, User, Band } = require('../models');
const Sequelize = require('sequelize');
const { QUALITY_NAMES } = require('../config/constants');
const { TestStore } = require('../stores');
@@ -53,6 +53,48 @@ module.exports = {
break;
}
}
if (interaction.commandName === 'collection') {
const character = interaction.options.getString('character');
const band = interaction.options.getString('band');
const quality = interaction.options.getString('quality');
//TODO: avoid duplicate code hehe
switch (focusedOption.name) {
case 'character':
if(focusedOption.value.length < 3) break;
const characters = await Character.findAll({
where: {
name: {
[Sequelize.Op.like]: `%${focusedOption.value}%`
}
},
limit: 10
});
for (let i = 0; i < characters.length; i++) {
choices.push({
name: characters[i].name,
value: `${characters[i].id}`
});
}
break;
case 'band':
if(focusedOption.value.length < 3) break;
const bands = await Band.findAll({
where: {
name: {
[Sequelize.Op.like]: `%${focusedOption.value}%`
}
},
limit: 10
});
for (let i = 0; i < bands.length; i++) {
choices.push({
name: bands[i].name,
value: `${bands[i].id}`
});
}
break;
}
}
if (choices.length > 0) {
console.log(choices);
await interaction.respond(choices);