History: Add details to drop history and split by type
that being 0 for drops and 1 for claims. Fixes #16
This commit is contained in:
@@ -92,6 +92,25 @@ module.exports = {
|
|||||||
|
|
||||||
const message = await interaction.editReply({ content: 'asd', components: [row], files: [file], fetchReply: true });
|
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 });
|
//const message = await interaction.editReply({ content: reply, components: [row], fetchReply: true });
|
||||||
//set users drop cooldown
|
//set users drop cooldown
|
||||||
await UserUtils.setCooldown(user, "drop", await GeneralUtils.getBotProperty("dropTimeout"));
|
await UserUtils.setCooldown(user, "drop", await GeneralUtils.getBotProperty("dropTimeout"));
|
||||||
@@ -119,6 +138,15 @@ module.exports = {
|
|||||||
cards[cardId].userId = claimUser.id;
|
cards[cardId].userId = claimUser.id;
|
||||||
await UserUtils.setCooldown(claimUser, "pull", await GeneralUtils.getBotProperty("pullTimeout"));
|
await UserUtils.setCooldown(claimUser, "pull", await GeneralUtils.getBotProperty("pullTimeout"));
|
||||||
await cards[cardId].save();
|
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);
|
await claimUser.addExperience(5);
|
||||||
//fetch character name from database given the character id
|
//fetch character name from database given the character id
|
||||||
let character = await Character.findOne({
|
let character = await Character.findOne({
|
||||||
@@ -139,7 +167,12 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
collector.on('end', async collected => {
|
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) {
|
for (reply of collectionReplies) {
|
||||||
//TODO: strings shouldn't be inlined. Needs refactoring
|
//TODO: strings shouldn't be inlined. Needs refactoring
|
||||||
let notableProps = [];
|
let notableProps = [];
|
||||||
@@ -149,23 +182,6 @@ module.exports = {
|
|||||||
reply.ref.edit({ content: `${reply.ref.content.replace('a card', reply.characterName)} ${notableProps.join()}` });
|
reply.ref.edit({ content: `${reply.ref.content.replace('a card', reply.characterName)} ${notableProps.join()}` });
|
||||||
}
|
}
|
||||||
console.log(`Collected ${collected.size} interactions.`);
|
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);
|
let deckImage = await Rendering.renderCardStack(cards);
|
||||||
|
|||||||
26
migrations/20220921111418-add-type-to-dropHistory.js
Normal file
26
migrations/20220921111418-add-type-to-dropHistory.js
Normal file
@@ -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');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -14,7 +14,8 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DropHistory.init({
|
DropHistory.init({
|
||||||
dropData: DataTypes.JSON
|
dropData: DataTypes.JSON,
|
||||||
|
type: DataTypes.INTEGER
|
||||||
}, {
|
}, {
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'DropHistory',
|
modelName: 'DropHistory',
|
||||||
|
|||||||
Reference in New Issue
Block a user