Drop: Add drop history
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, AttachmentBuilder } = require("discord.js");
|
||||
const { Card, User, Character } = require("../models");
|
||||
const { Card, User, Character, DropHistory } = require("../models");
|
||||
const { customAlphabet } = require("nanoid");
|
||||
const { CardUtils, UserUtils, ReplyUtils, GeneralUtils, Rendering } = require("../util");
|
||||
const card = require("../models/card");
|
||||
@@ -109,13 +109,28 @@ module.exports = {
|
||||
});
|
||||
|
||||
collector.on('end', async collected => {
|
||||
let dropHistory = {};
|
||||
|
||||
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);
|
||||
message.edit({ components: [], files: [new AttachmentBuilder(deckImage)] });
|
||||
});
|
||||
|
||||
@@ -25,3 +25,5 @@ services:
|
||||
- MYSQL_DATABASE=${DB_DATABASE}
|
||||
- MYSQL_USER=${DB_USERNAME}
|
||||
- MYSQL_PASSWORD=${DB_PASSWORD}
|
||||
- LANG=C.UTF-8
|
||||
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
27
migrations/20220828194604-create-drop-history.js
Normal file
27
migrations/20220828194604-create-drop-history.js
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('DropHistories', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
dropData: {
|
||||
type: Sequelize.JSON
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.dropTable('DropHistories');
|
||||
}
|
||||
};
|
||||
23
models/drophistory.js
Normal file
23
models/drophistory.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
const {
|
||||
Model
|
||||
} = require('sequelize');
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class DropHistory extends Model {
|
||||
/**
|
||||
* Helper method for defining associations.
|
||||
* This method is not a part of Sequelize lifecycle.
|
||||
* The `models/index` file will call this method automatically.
|
||||
*/
|
||||
static associate(models) {
|
||||
// define association here
|
||||
}
|
||||
}
|
||||
DropHistory.init({
|
||||
dropData: DataTypes.JSON
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'DropHistory',
|
||||
});
|
||||
return DropHistory;
|
||||
};
|
||||
Reference in New Issue
Block a user