Add drop and pull cooldowns
This commit is contained in:
31
commands/cooldowns.js
Normal file
31
commands/cooldowns.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const { SlashCommandBuilder } = require("discord.js");
|
||||
const { Card, User, Character } = require("../models");
|
||||
const { UserUtils } = require("../util");
|
||||
|
||||
//fetch all cards owned by the user and list them
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("cooldowns")
|
||||
.setDescription("List cooldowns"),
|
||||
async execute(interaction) {
|
||||
//fetch the user given the userID and include his cards
|
||||
const user = await UserUtils.getUserByDiscordId(interaction.member.id);
|
||||
|
||||
//get user cooldowns using user utils
|
||||
const cooldowns = await UserUtils.getCooldowns(user);
|
||||
|
||||
let reply = "Cooldowns:\n";
|
||||
for (cooldown in cooldowns) {
|
||||
//if cooldown contains the string formatted
|
||||
if (cooldown.includes("Formatted")) {
|
||||
reply += `${cooldowns[cooldown]}\n`;
|
||||
}
|
||||
}
|
||||
|
||||
interaction.reply({
|
||||
content: reply,
|
||||
ephemeral: false
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
const { SlashCommandBuilder, ComponentType, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
|
||||
const { customAlphabet } = require("nanoid");
|
||||
const { Card, User, Character } = require("../models");
|
||||
const Util = require("../util/cards");
|
||||
const { Card, User } = require("../models");
|
||||
const { UserUtils, CardUtils, GeneralUtils } = require("../util");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
@@ -15,8 +15,8 @@ module.exports = {
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const identifier = Util.generateIdentifier();
|
||||
|
||||
const identifier = CardUtils.generateIdentifier();
|
||||
let user = await UserUtils.getUserByDiscordId(interaction.member.id);
|
||||
switch (interaction.options.getString("feature")) {
|
||||
case "ping":
|
||||
interaction.reply({
|
||||
@@ -45,6 +45,31 @@ module.exports = {
|
||||
content: `Cleared ${cards.length} cards`,
|
||||
ephemeral: false
|
||||
});
|
||||
break;
|
||||
case "cooldowns":
|
||||
const timeouts = await UserUtils.getCooldowns(user);
|
||||
console.log(`UserTimeouts: ${JSON.stringify(timeouts)}`);
|
||||
let timeoutInMinutes = 0;
|
||||
interaction.reply({
|
||||
content: `\`\`\`${JSON.stringify(timeouts, null, 2)}\`\`\` `,
|
||||
ephemeral: false
|
||||
});
|
||||
break;
|
||||
case "bot":
|
||||
let botProperties = await GeneralUtils.getBotProperty(null);
|
||||
interaction.reply({
|
||||
content: `\`\`\`${JSON.stringify(botProperties, null, 2)}\`\`\` `,
|
||||
ephemeral: false
|
||||
});
|
||||
break;
|
||||
case "reset_cd":
|
||||
await UserUtils.setCooldown(user, "pull", 1);
|
||||
await UserUtils.setCooldown(user, "drop", 1);
|
||||
await UserUtils.setCooldown(user, "daily", 1);
|
||||
interaction.reply({
|
||||
content: `Reset cooldowns`,
|
||||
ephemeral: false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } = require("discord.js");
|
||||
const { Card, User, Character } = require("../models");
|
||||
const { customAlphabet } = require("nanoid");
|
||||
const { CardUtils, UserUtils, ReplyUtils } = require("../util");
|
||||
const { CardUtils, UserUtils, ReplyUtils, GeneralUtils } = require("../util");
|
||||
const card = require("../models/card");
|
||||
|
||||
module.exports = {
|
||||
@@ -10,11 +10,16 @@ module.exports = {
|
||||
.setDescription("Drop a card"),
|
||||
|
||||
async execute(interaction) {
|
||||
const user = await User.findOne({
|
||||
where: {
|
||||
discordId: interaction.member.id
|
||||
}
|
||||
});
|
||||
const user = await UserUtils.getUserByDiscordId(interaction.member.id);
|
||||
|
||||
const cooldowns = await UserUtils.getCooldowns(user);
|
||||
if (cooldowns.dropCooldown > 0) {
|
||||
interaction.reply({
|
||||
content: `You can't drop cards for another ${cooldowns.dropCooldown} milliseconds`,
|
||||
ephemeral: false
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//Generate 3 cards, each is persisted with an initial userId of NULL
|
||||
const cards = [];
|
||||
@@ -55,6 +60,8 @@ module.exports = {
|
||||
}
|
||||
|
||||
const message = await interaction.reply({ content: reply, components: [row], fetchReply: true });
|
||||
//set users drop cooldown
|
||||
await UserUtils.setCooldown(user, "drop", await GeneralUtils.getBotProperty("dropTimeout"));
|
||||
|
||||
const filter = m => m.author.id === interaction.user.id;
|
||||
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button, time: 15000 });
|
||||
@@ -64,10 +71,21 @@ module.exports = {
|
||||
if (await cards[cardId].userId) { i.reply({ content: "This card has already been claimed!", ephemeral: true }); return; }
|
||||
|
||||
let claimUser = await UserUtils.getUserByDiscordId(i.user.id);
|
||||
const cooldowns = await UserUtils.getCooldowns(user);
|
||||
if (cooldowns.pullCooldown > 0) {
|
||||
i.reply({
|
||||
content: `You can't claim cards for another ${cooldowns.dropCooldown} milliseconds`,
|
||||
ephemeral: false
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (claimUser) {
|
||||
//Update card with the user id
|
||||
cards[cardId].userId = claimUser.id;
|
||||
await UserUtils.setCooldown(user, "pull", await GeneralUtils.getBotProperty("pullTimeout"));
|
||||
await cards[cardId].save();
|
||||
|
||||
//fetch character name from database given the character id
|
||||
let character = await Character.findOne({
|
||||
attributes: ["name"],
|
||||
@@ -87,7 +105,7 @@ module.exports = {
|
||||
|
||||
collector.on('end', collected => {
|
||||
console.log(`Collected ${collected.size} interactions.`);
|
||||
message.interaction.editReply({ components: [], deferred: true });
|
||||
message.edit({ components: [] });
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user