diff --git a/commands/drop.js b/commands/drop.js index 585f9d5..49d374b 100644 --- a/commands/drop.js +++ b/commands/drop.js @@ -92,6 +92,25 @@ module.exports = { const message = await interaction.editReply({ content: 'asd', components: [row], files: [file], fetchReply: true }); + let dropHistory = { + dropper: user.id, + guild: interaction.guild.id, + channel: interaction.channel.id, + messageId: message.id, + }; + for (let card of cards) { + let historyEntry = { + cardData: JSON.stringify(card) + }; + dropHistory[card.identifier] = historyEntry; + } + + //create new drop history entry + let history = await DropHistory.create({ + dropData: JSON.stringify(dropHistory), + type: 0 + }); + //const message = await interaction.editReply({ content: reply, components: [row], fetchReply: true }); //set users drop cooldown await UserUtils.setCooldown(user, "drop", await GeneralUtils.getBotProperty("dropTimeout")); @@ -119,6 +138,15 @@ module.exports = { cards[cardId].userId = claimUser.id; await UserUtils.setCooldown(claimUser, "pull", await GeneralUtils.getBotProperty("pullTimeout")); await cards[cardId].save(); + let historyEntry = { + userId: claimUser.id, + cardId: cards[cardId].id, + dropMessageId: message.id + } + await DropHistory.create({ + dropData: JSON.stringify(historyEntry), + type: 1 + }); await claimUser.addExperience(5); //fetch character name from database given the character id let character = await Character.findOne({ @@ -139,7 +167,12 @@ module.exports = { }); collector.on('end', async collected => { - let dropHistory = {}; + for (let card of cards) { + if (!card.userId) { + card.userId = 1; + await card.save(); + } + } for (reply of collectionReplies) { //TODO: strings shouldn't be inlined. Needs refactoring let notableProps = []; @@ -149,23 +182,6 @@ module.exports = { reply.ref.edit({ content: `${reply.ref.content.replace('a card', reply.characterName)} ${notableProps.join()}` }); } console.log(`Collected ${collected.size} interactions.`); - for (let card of cards) { - if (!card.userId) { - card.userId = 1; - await card.save(); - } - let historyEntry = { - cardData: JSON.stringify(card), - ogUserId: card.userId, - }; - dropHistory[card.identifier] = historyEntry; - } - - //create new drop history entry - let history = await DropHistory.create({ - dropData: JSON.stringify(dropHistory), - }); - let deckImage = await Rendering.renderCardStack(cards); diff --git a/migrations/20220921111418-add-type-to-dropHistory.js b/migrations/20220921111418-add-type-to-dropHistory.js new file mode 100644 index 0000000..38b30bc --- /dev/null +++ b/migrations/20220921111418-add-type-to-dropHistory.js @@ -0,0 +1,26 @@ +'use strict'; + +module.exports = { + async up (queryInterface, Sequelize) { + /** + * Add altering commands here. + * + * Example: + * await queryInterface.createTable('users', { id: Sequelize.INTEGER }); + */ + await queryInterface.addColumn('DropHistories', 'type', { + type: Sequelize.INTEGER, + allowNull: true + }); + }, + + async down (queryInterface, Sequelize) { + /** + * Add reverting commands here. + * + * Example: + * await queryInterface.dropTable('users'); + */ + await queryInterface.removeColumn('DropHistories', 'type'); + } +}; diff --git a/models/drophistory.js b/models/drophistory.js index c84e0ad..4680e0b 100644 --- a/models/drophistory.js +++ b/models/drophistory.js @@ -14,7 +14,8 @@ module.exports = (sequelize, DataTypes) => { } } DropHistory.init({ - dropData: DataTypes.JSON + dropData: DataTypes.JSON, + type: DataTypes.INTEGER }, { sequelize, modelName: 'DropHistory',