User/Debug/Profile: Add primary and secondary currency
This commit is contained in:
@@ -21,6 +21,8 @@ module.exports = {
|
||||
{ name: 'bot', value: 'bot' },
|
||||
{ name: 'reset_cd', value: 'reset_cd' },
|
||||
{ name: 'add_xp', value: 'add_xp' },
|
||||
{ name: 'add_primary', value: 'add_primary' },
|
||||
{ name: 'add_secondary', value: 'add_secondary' },
|
||||
{ name: 'toggle_maintenance', value: 'toggle_maintenance' },
|
||||
)
|
||||
)
|
||||
@@ -120,6 +122,20 @@ module.exports = {
|
||||
ephemeral: false
|
||||
});
|
||||
break;
|
||||
case "add_primary":
|
||||
await extUser.addPrimaryCurrency(interaction.options.getString("value"), `Debug command ran by ${interaction.member.displayName}`);
|
||||
interaction.editReply({
|
||||
content: `Added ${interaction.options.getString("value")} Primary to <@${extUser.discordId}>`,
|
||||
ephemeral: false
|
||||
});
|
||||
break;
|
||||
case "add_secondary":
|
||||
await extUser.addSecondaryCurrency(interaction.options.getString("value"), `Debug command ran by ${interaction.member.displayName}`);
|
||||
interaction.editReply({
|
||||
content: `Added ${interaction.options.getString("value")} Secondary to <@${extUser.discordId}>`,
|
||||
ephemeral: false
|
||||
});
|
||||
break;
|
||||
case "toggle_maintenance":
|
||||
let maintenance = await GeneralUtils.getBotProperty("maintenance");
|
||||
await GeneralUtils.setBotProperty("maintenance", !maintenance);
|
||||
|
||||
@@ -3,6 +3,7 @@ const { Card, User, Character } = require("../models");
|
||||
const { UserUtils, Compositing, Rendering } = require("../util");
|
||||
const axios = require("axios");
|
||||
const sharp = require("sharp");
|
||||
const { CURRENCY_NAMES } = require("../config/constants");
|
||||
const fs = require('fs');
|
||||
|
||||
const pageSize = 8;
|
||||
@@ -34,6 +35,8 @@ module.exports = {
|
||||
profileTemplate = profileTemplate.replace(/{{HEADER_COLOR}}/g, '190,31,97');
|
||||
profileTemplate = profileTemplate.replace(/{{CC}}/g, await Card.count({where: {userId: user.id}}));
|
||||
profileTemplate = profileTemplate.replace(/{{LVL}}/g, await user.level().currentLevel);
|
||||
profileTemplate = profileTemplate.replace(/{{CUR_1}}/g, `${await user.primaryCurrency} ${CURRENCY_NAMES[1]}`);
|
||||
profileTemplate = profileTemplate.replace(/{{CUR_2}}/g, `${await user.secondaryCurrency} ${CURRENCY_NAMES[2]}`);
|
||||
|
||||
let userImageBuffer = await axios.get(discordUser.displayAvatarURL({format: 'png', size: 128}), { responseType: 'arraybuffer' });
|
||||
userImage = await sharp(userImageBuffer.data);
|
||||
|
||||
@@ -16,5 +16,17 @@ const QUALITY_NAMES = {
|
||||
6 : "Shiny"
|
||||
}
|
||||
|
||||
const CURRENCY_SYMBOLS = {
|
||||
1 : "🎶",
|
||||
2 : "💎"
|
||||
}
|
||||
|
||||
const CURRENCY_NAMES = {
|
||||
1 : "Notes",
|
||||
2 : "Gems"
|
||||
}
|
||||
|
||||
exports.QUALITY = QUALITY;
|
||||
exports.QUALITY_NAMES = QUALITY_NAMES;
|
||||
exports.QUALITY_NAMES = QUALITY_NAMES;
|
||||
exports.CURRENCY_SYMBOLS = CURRENCY_SYMBOLS;
|
||||
exports.CURRENCY_NAMES = CURRENCY_NAMES;
|
||||
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up (queryInterface, Sequelize) {
|
||||
/**
|
||||
* Add altering commands here.
|
||||
*
|
||||
* Example:
|
||||
* await queryInterface.createTable('users', { id: Sequelize.INTEGER });
|
||||
*/
|
||||
await queryInterface.addColumn('Users', 'primaryCurrency', {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0
|
||||
});
|
||||
await queryInterface.addColumn('Users', 'secondaryCurrency', {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0
|
||||
});
|
||||
},
|
||||
|
||||
async down (queryInterface, Sequelize) {
|
||||
/**
|
||||
* Add reverting commands here.
|
||||
*
|
||||
* Example:
|
||||
* await queryInterface.dropTable('users');
|
||||
*/
|
||||
await queryInterface.removeColumn('Users', 'primaryCurrency');
|
||||
await queryInterface.removeColumn('Users', 'secondaryCurrency');
|
||||
}
|
||||
};
|
||||
@@ -31,6 +31,31 @@ module.exports = (sequelize, DataTypes) => {
|
||||
experience: this.experience + parseInt(amount)
|
||||
});
|
||||
}
|
||||
async addCurrency(amount, type, source='unknown') {
|
||||
let typeStr = '';
|
||||
if (type == 1) {
|
||||
typeStr = `primaryCurrency`;
|
||||
}
|
||||
if (type == 2) {
|
||||
typeStr = `secondaryCurrency`;
|
||||
}
|
||||
console.log(`Adding ${amount} ${typeStr} to user ${this.id}`);
|
||||
await sequelize.models.CurrencyHistory.create({
|
||||
userId: this.id,
|
||||
currency: type,
|
||||
delta: amount,
|
||||
previous: this[typeStr],
|
||||
source: source
|
||||
});
|
||||
this[typeStr] += parseInt(amount);
|
||||
await this.save();
|
||||
}
|
||||
async addPrimaryCurrency(amount, source='unknown') {
|
||||
return await this.addCurrency(amount, 1, source);
|
||||
}
|
||||
async addSecondaryCurrency(amount, source='unknown') {
|
||||
return await this.addCurrency(amount, 2, source);
|
||||
}
|
||||
level() {
|
||||
let currentLevel = Math.floor(levelModifier * Math.sqrt(this.experience));
|
||||
let nextLevelExperience = Math.pow((currentLevel + 1) / levelModifier, 2);
|
||||
@@ -74,6 +99,8 @@ module.exports = (sequelize, DataTypes) => {
|
||||
active: DataTypes.INTEGER,
|
||||
privacy: DataTypes.INTEGER,
|
||||
experience: DataTypes.INTEGER,
|
||||
primaryCurrency: DataTypes.INTEGER,
|
||||
secondaryCurrency: DataTypes.INTEGER,
|
||||
nextDrop: DataTypes.DATE,
|
||||
nextPull: DataTypes.DATE,
|
||||
nextDaily: DataTypes.DATE
|
||||
|
||||
Reference in New Issue
Block a user