Daily: Implement daily rewards command
This commit is contained in:
49
commands/daily.js
Normal file
49
commands/daily.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { UserUtils } = require('../util');
|
||||
const { DAILY_REWARDS, CURRENCY_SYMBOLS } = require('../config/constants');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("daily")
|
||||
.setDescription("Claim you daily rewards"),
|
||||
permissionLevel: 0,
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply();
|
||||
let discordUser = interaction.options.getUser("user") ? interaction.options.getUser("user") : interaction.member.user;
|
||||
let user = await UserUtils.getUserByDiscordId(discordUser.id);
|
||||
|
||||
|
||||
let embed = new EmbedBuilder()
|
||||
.setTitle(`Daily claim`);
|
||||
|
||||
const cooldowns = await UserUtils.getCooldowns(user);
|
||||
if (cooldowns.nextDaily > 0) {
|
||||
embed.addFields(
|
||||
{ name: "Next daily reward:", value: `${cooldowns.nextDailyFormatted}` }
|
||||
)
|
||||
.setColor(0xFF0000);
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
return; //Return daily on cooldown
|
||||
}
|
||||
|
||||
let patreonModifier = (await UserUtils.getPatreonPerks(interaction.client, user))['perks']?.['modifiers']['daily'];
|
||||
if(!patreonModifier) { patreonModifier = 1 }
|
||||
|
||||
let rewardPrimary = DAILY_REWARDS['primary_currency'] * patreonModifier;
|
||||
let rewardSecondary = DAILY_REWARDS['secondary_currency'] * patreonModifier;
|
||||
let rewardExp = DAILY_REWARDS['experience'] * patreonModifier;
|
||||
|
||||
user.addCurrency(rewardPrimary, 1, "daily");
|
||||
user.addCurrency(rewardSecondary, 2, "daily");
|
||||
user.addExperience(rewardExp, "daily");
|
||||
|
||||
UserUtils.actionHandler(user, "daily");
|
||||
embed.addFields(
|
||||
{ name: 'Patreon bonus', value: (patreonModifier > 1 ? `${patreonModifier}x modifier` : `No Patreon bonus`) },
|
||||
{ name: "You claimed your daily rewards!", value: `${CURRENCY_SYMBOLS[1]} ${rewardPrimary}\n${CURRENCY_SYMBOLS[2]} ${rewardSecondary}\nXP ${rewardExp}` }
|
||||
)
|
||||
.setColor(0x00FF00);
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,12 @@ const QUALITY_VALUES = {
|
||||
}
|
||||
}
|
||||
|
||||
const DAILY_REWARDS = {
|
||||
primary_currency : 250,
|
||||
secondary_currency : 5,
|
||||
experience : 50
|
||||
}
|
||||
|
||||
const PATREON = {
|
||||
roleServer : '441300798819794944',
|
||||
tiers : {
|
||||
@@ -119,4 +125,5 @@ exports.CURRENCY_SYMBOLS = CURRENCY_SYMBOLS;
|
||||
exports.QUALITY_SYMBOLS = QUALITY_SYMBOLS;
|
||||
exports.CURRENCY_NAMES = CURRENCY_NAMES;
|
||||
exports.QUALITY_VALUES = QUALITY_VALUES;
|
||||
exports.DAILY_REWARDS = DAILY_REWARDS;
|
||||
exports.PATREON = PATREON;
|
||||
@@ -69,7 +69,7 @@ module.exports = {
|
||||
reply['nextDaily'] = Math.max(user['nextDaily'].getTime() - reply['now'], 0);
|
||||
reply['nextDailyTStamp'] = user['nextDaily'].getTime();
|
||||
|
||||
reply[`nextDailyFormatted`] = reply['nextDaily'] > 0 ? `Resets <t:${parseInt(reply['nextDailyTStamp'] / 1000)}>` : `Ready!`;
|
||||
reply[`nextDailyFormatted`] = reply['nextDaily'] > 0 ? `<t:${parseInt(reply['nextDailyTStamp'] / 1000)}>` : `Ready!`;
|
||||
for (key of cooldownKeys) {
|
||||
reply[`${key}Timestamp`] = user[key].getTime();
|
||||
let cooldown = reply[key]
|
||||
@@ -122,6 +122,11 @@ module.exports = {
|
||||
console.log(`Claim for user ${user.id} persisting with value ${user['remainingClaims']} next claim at ${user['nextClaimReset']}`);
|
||||
await user.save();
|
||||
break;
|
||||
case "daily":
|
||||
let dailyTimeout = 86400000; //24 Hours
|
||||
user['nextDaily'] = new Date(new Date().getTime() + dailyTimeout);
|
||||
await user.save();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -177,6 +182,11 @@ module.exports = {
|
||||
* tier: 0 if not subscribed
|
||||
* 1-n as per role mapping in the DB (e.g. {"1083018874263453868":1,"1083018984921759744":2})
|
||||
* perks: modifiers associated with the tier
|
||||
* modifiers: {
|
||||
* drops: 0,
|
||||
* claims: 1,
|
||||
* [...]
|
||||
* }
|
||||
*/
|
||||
|
||||
let patreonRoles = await GeneralUtils.getBotProperty("patreonTierRoles");
|
||||
|
||||
Reference in New Issue
Block a user