Drop: Add wishlist pings to drops

This commit is contained in:
2023-03-16 00:30:38 +01:00
parent ce55b1b45a
commit 92807bc4db

View File

@@ -1,8 +1,9 @@
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, AttachmentBuilder } = require("discord.js"); const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, AttachmentBuilder } = require("discord.js");
const { Card, User, Character, DropHistory, sequelize } = require("../models"); const { Card, User, Character, DropHistory, Wishlist, sequelize } = require("../models");
const { customAlphabet } = require("nanoid"); const { customAlphabet } = require("nanoid");
const { CardUtils, UserUtils, ReplyUtils, GeneralUtils, Rendering } = require("../util"); const { CardUtils, UserUtils, ReplyUtils, GeneralUtils, Rendering } = require("../util");
const { QUALITY } = require("../config/constants"); const { QUALITY } = require("../config/constants");
const Sequelize = require('sequelize');
const card = require("../models/card"); const card = require("../models/card");
module.exports = { module.exports = {
@@ -32,7 +33,8 @@ module.exports = {
const cards = []; const cards = [];
let characters = await Character.findAll({ let characters = await Character.findAll({
where: { where: {
enabled: true enabled: true,
[Sequelize.Op.or]: [ { id: 3 }, { id: 4 }, { id: 5 } ]
}, },
order: sequelize.random(), order: sequelize.random(),
limit: 3 limit: 3
@@ -80,6 +82,7 @@ module.exports = {
const row = new ActionRowBuilder(); const row = new ActionRowBuilder();
let deckImage = await Rendering.renderCardStack(cards); let deckImage = await Rendering.renderCardStack(cards);
let notableProps = []; let notableProps = [];
let pings = [];
for (let i = 0; i < cards.length; i++) { for (let i = 0; i < cards.length; i++) {
//Add claim button and notable prop text for each card //Add claim button and notable prop text for each card
row.addComponents( row.addComponents(
@@ -94,13 +97,37 @@ module.exports = {
if (cards[i].printNr == 1) { if (cards[i].printNr == 1) {
notableProps.push(`📦`); notableProps.push(`📦`);
} }
//send wishlist pings
let guildMembers = [...(await interaction.guild.members.fetch()).keys()];
let wishlists = await Wishlist.findAll({
attributes: ['id', 'UserId'],
include: [{
model: Character,
attributes: ['name'],
where: { id: cards[i].characterId },
},
{
model: User,
attributes: ['discordId']
}]
});
wishlists.forEach(wishlist => {
if(guildMembers.includes(wishlist.User.discordId)) {
pings.push(`<@${wishlist.User.discordId}>`);
}
});
if (wishlists.length > 0) {
let debug = wishlists[0];
pings.push(`your wishlisted character ${debug.Characters[0].name} is in this drop!\n`);
}
} }
//add 10 experience to the user //add 10 experience to the user
await user.addExperience(10, 'drop'); await user.addExperience(10, 'drop');
const file = new AttachmentBuilder(deckImage); const file = new AttachmentBuilder(deckImage);
const message = await interaction.editReply({ content: `${interaction.member} Dropped 3 cards.\n${notableProps.join(" ")}`, components: [row], files: [file], fetchReply: true }); const message = await interaction.editReply({ content: `${interaction.member} Dropped 3 cards.\n${notableProps.join(" ")} \n${pings.join(' ')}`, components: [row], files: [file], fetchReply: true });
let dropHistory = { let dropHistory = {
dropper: user.id, dropper: user.id,