diff --git a/commands/drop.js b/commands/drop.js index 71fa7a2..5201fe4 100644 --- a/commands/drop.js +++ b/commands/drop.js @@ -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)] }); }); diff --git a/docker-compose.yml b/docker-compose.yml index 9c0907d..0200851 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,4 +24,6 @@ services: - MYSQL_ROOT_PASSWORD=${DB_PASSWORD} - MYSQL_DATABASE=${DB_DATABASE} - MYSQL_USER=${DB_USERNAME} - - MYSQL_PASSWORD=${DB_PASSWORD} \ No newline at end of file + - MYSQL_PASSWORD=${DB_PASSWORD} + - LANG=C.UTF-8 + command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci \ No newline at end of file diff --git a/migrations/20220828194604-create-drop-history.js b/migrations/20220828194604-create-drop-history.js new file mode 100644 index 0000000..66ea9bc --- /dev/null +++ b/migrations/20220828194604-create-drop-history.js @@ -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'); + } +}; \ No newline at end of file diff --git a/models/drophistory.js b/models/drophistory.js new file mode 100644 index 0000000..c84e0ad --- /dev/null +++ b/models/drophistory.js @@ -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; +}; \ No newline at end of file