From 088079cc0ebbd5acdf5d17baad6bae2e98f5555e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Gro=C3=9F?= Date: Mon, 5 Jun 2023 17:56:48 +0200 Subject: [PATCH 1/6] Commands: Add core missing command --- commands/missing.js | 96 +++++++++++++++++++++++++++++++++++ events/autocompleteRequest.js | 6 +++ models/character.js | 1 + 3 files changed, 103 insertions(+) create mode 100644 commands/missing.js diff --git a/commands/missing.js b/commands/missing.js new file mode 100644 index 0000000..2270062 --- /dev/null +++ b/commands/missing.js @@ -0,0 +1,96 @@ +const { SlashCommandBuilder, AttachmentBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } = require("discord.js"); +const { Card, User, Group, Character, Badge } = require("../models"); +const { Rendering, UserUtils } = require("../util"); +const { QUALITY_NAMES } = require("../config/constants"); +const Sequelize = require("sequelize"); +const fs = require("fs"); +const edit = require("./edit"); + +//fetch all cards owned by the user and list them +module.exports = { + data: new SlashCommandBuilder() + .setName("missing") + .setDescription("View missing things") + .addStringOption((option) => + option + .setName("group_id") + .setDescription("Thing identifier") + .setRequired(false) + .setAutocomplete(true) + ), + permissionLevel: 0, + async execute(interaction) { + await interaction.deferReply(); + + let groupId = interaction.options.getString("group_id"); + let user = await UserUtils.getUserByDiscordId(interaction.member.user.id); + + if (groupId) { + try { + let missingCards = await this.FindMissingFromGroup(user.id, groupId); + await interaction.editReply(JSON.stringify(missingCards)); + return; + } catch (error) { + console.error('Error:', error); + throw error; + } + } + + let missingCount = await this.CountMissingFromGroup(user.id); + await interaction.editReply(JSON.stringify(missingCount)); + return; + }, + async CountMissingFromGroup(userId) { + try { + const groups = await Group.findAll({ + where: { enabled: 1 } + }); + + const missingCountByGroup = await Promise.all( + groups.map(async (group) => { + const characters = await Character.findAll({ + where: { groupId: group.id, enabled: 1 }, + include: [ + { + model: Card, + where: { userId: userId }, + required: false, + }, + ], + }); + + const missingCount = characters.reduce((total, character) => { + return total + (character.Cards.length === 0 ? 1 : 0); + }, 0); + + return { + groupId: group.id, + groupName: group.name, + missingCount: missingCount, + }; + }) + ); + + return missingCountByGroup; + } catch (error) { + console.error('Error:', error); + throw error; + } + }, + async FindMissingFromGroup(userId, groupId) { + const missingCards = await Character.findAll({ + attributes: ['groupId', 'id', 'name'], + include: [{ + model: Card, + attributes: [], + required: false, + where: { userId: userId, burned: 0 }, + }], + where: { groupId: groupId }, + having: Sequelize.literal('COUNT(Cards.id) = 0'), + group: ['Character.id'], + }); + + return missingCards; + } +} \ No newline at end of file diff --git a/events/autocompleteRequest.js b/events/autocompleteRequest.js index 8c4b4e8..abd729e 100644 --- a/events/autocompleteRequest.js +++ b/events/autocompleteRequest.js @@ -40,6 +40,12 @@ module.exports = { } } + if (interaction.commandName === 'missing') { + + choices = (await SearchUtils.findByName(Group, focusedOption.value))["choices"]; + + } + if (interaction.commandName === 'wishlist') { choices = (await SearchUtils.findByName(Character, focusedOption.value))["choices"]; } diff --git a/models/character.js b/models/character.js index e2dbb58..0507a23 100644 --- a/models/character.js +++ b/models/character.js @@ -13,6 +13,7 @@ module.exports = (sequelize, DataTypes) => { Character.belongsTo(models.Group, { foreignKey: 'groupId', }); // A character can belong to many badges Character.belongsToMany(models.Badge, { through: 'BadgeCharacter' }); + Character.hasMany(models.Card, { foreignKey: 'characterId' }); } } Character.init({ From d4caefc077608b6857237ee2844b17d9fc0205fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Gro=C3=9F?= Date: Tue, 6 Jun 2023 14:52:38 +0200 Subject: [PATCH 2/6] Missing: Use embeds --- commands/missing.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/commands/missing.js b/commands/missing.js index 2270062..b73629b 100644 --- a/commands/missing.js +++ b/commands/missing.js @@ -13,7 +13,7 @@ module.exports = { .setDescription("View missing things") .addStringOption((option) => option - .setName("group_id") + .setName("group") .setDescription("Thing identifier") .setRequired(false) .setAutocomplete(true) @@ -22,22 +22,36 @@ module.exports = { async execute(interaction) { await interaction.deferReply(); - let groupId = interaction.options.getString("group_id"); + let groupId = interaction.options.getString("group"); let user = await UserUtils.getUserByDiscordId(interaction.member.user.id); + let embed = new EmbedBuilder() + .setTitle(`Missing cards`); + let description = ""; + if (groupId) { try { - let missingCards = await this.FindMissingFromGroup(user.id, groupId); - await interaction.editReply(JSON.stringify(missingCards)); - return; + let missing = await this.FindMissingFromGroup(user.id, groupId); + missing.map((character) => { + description += `[${character.id}] ${character.name}\n`; + }); } catch (error) { console.error('Error:', error); throw error; } + + } else { + let missingCounts = await this.CountMissingFromGroup(user.id); + missingCounts.sort(({missingCount:a}, {missingCount:b}) => b-a); + missingCounts.map((group) => { + if (group.missingCount > 0) { + description += `${group.name}: ${group.missingCount}\n`; + } + }); } - let missingCount = await this.CountMissingFromGroup(user.id); - await interaction.editReply(JSON.stringify(missingCount)); + embed.setDescription(description); + await interaction.editReply({ embeds: [embed] }); return; }, async CountMissingFromGroup(userId) { @@ -64,8 +78,8 @@ module.exports = { }, 0); return { - groupId: group.id, - groupName: group.name, + id: group.id, + name: group.name, missingCount: missingCount, }; }) From 7e045df971acb2f26d963ea057e677d95e9ec50a Mon Sep 17 00:00:00 2001 From: Minz Date: Sun, 11 Jun 2023 20:56:05 +0200 Subject: [PATCH 3/6] Add Toho-Miku banner --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 837232c..a9acc1b 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ -# Toho Miku +![miku-banner](https://github.com/JanGross/toho-miku/assets/13641301/70ae153f-5e1d-4f49-9793-659ac3631403) + [![](https://dcbadge.vercel.app/api/server/uWFpsYnbPX)](https://discord.gg/uWFpsYnbPX) [![Support the project on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dtoho_miku%26type%3Dpatrons&style=for-the-badge)](https://patreon.com/toho_miku) Part of this project are - [Toho-Mon](https://github.com/JanGross/toho-mon) Bot status monitoring with webhook alerts -- [Toho-Reno](https://github.com/JanGross/toho-reno) Headless render node +- [Toho-Reno](https://github.com/JanGross/toho-reno) Godot render node - [Job-Server](https://github.com/JanGross/job-server) Jobserver managing render jobs ### Run dev container From e25d3bb2cbb8ec5aa4cbdc7bfe4b6485d8d66c43 Mon Sep 17 00:00:00 2001 From: Minz Date: Sun, 11 Jun 2023 20:56:53 +0200 Subject: [PATCH 4/6] Update toho-jose reference --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9acc1b..72a53c3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Part of this project are - [Toho-Mon](https://github.com/JanGross/toho-mon) Bot status monitoring with webhook alerts - [Toho-Reno](https://github.com/JanGross/toho-reno) Godot render node -- [Job-Server](https://github.com/JanGross/job-server) Jobserver managing render jobs +- [Toho-Jose](https://github.com/JanGross/toho-jose) Jobserver managing render jobs ### Run dev container From 646d1a61c069edd825125b520a30f40394ca0eba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Jun 2023 21:08:29 +0000 Subject: [PATCH 5/6] Bump dottie from 2.0.3 to 2.0.4 Bumps [dottie](https://github.com/mickhansen/dottie.js) from 2.0.3 to 2.0.4. - [Release notes](https://github.com/mickhansen/dottie.js/releases) - [Commits](https://github.com/mickhansen/dottie.js/compare/v2.0.3...v2.0.4) --- updated-dependencies: - dependency-name: dottie dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index c639a5c..4f4986b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -707,9 +707,9 @@ } }, "node_modules/dottie": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.3.tgz", - "integrity": "sha512-4liA0PuRkZWQFQjwBypdxPfZaRWiv5tkhMXY2hzsa2pNf5s7U3m9cwUchfNKe8wZQxdGPQQzO6Rm2uGe0rvohQ==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.4.tgz", + "integrity": "sha512-iz64WUOmp/ECQhWMJjTWFzJN/wQ7RJ5v/a6A2OiCwjaGCpNo66WGIjlSf+IULO9DQd0b4cFawLOTbiKSrpKodw==" }, "node_modules/editorconfig": { "version": "0.15.3", @@ -3292,9 +3292,9 @@ "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" }, "dottie": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.3.tgz", - "integrity": "sha512-4liA0PuRkZWQFQjwBypdxPfZaRWiv5tkhMXY2hzsa2pNf5s7U3m9cwUchfNKe8wZQxdGPQQzO6Rm2uGe0rvohQ==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.4.tgz", + "integrity": "sha512-iz64WUOmp/ECQhWMJjTWFzJN/wQ7RJ5v/a6A2OiCwjaGCpNo66WGIjlSf+IULO9DQd0b4cFawLOTbiKSrpKodw==" }, "editorconfig": { "version": "0.15.3", From 03c5153e59a4ed7a0ced319498f05c158f3a8ab1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 15:52:04 +0000 Subject: [PATCH 6/6] Bump semver from 5.7.1 to 5.7.2 Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md) - [Commits](https://github.com/npm/node-semver/compare/v5.7.1...v5.7.2) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 48 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index c639a5c..802f672 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1655,9 +1655,9 @@ } }, "node_modules/node-abi/node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -2029,9 +2029,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "bin": { "semver": "bin/semver" } @@ -2189,9 +2189,9 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/sequelize/node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -2244,9 +2244,9 @@ } }, "node_modules/sharp/node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -4031,9 +4031,9 @@ }, "dependencies": { "semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "requires": { "lru-cache": "^6.0.0" } @@ -4288,9 +4288,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==" }, "send": { "version": "0.18.0", @@ -4371,9 +4371,9 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "requires": { "lru-cache": "^6.0.0" } @@ -4431,9 +4431,9 @@ }, "dependencies": { "semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "requires": { "lru-cache": "^6.0.0" }