Skip to content

Commit

Permalink
feat(command): add daily and weely command
Browse files Browse the repository at this point in the history
  • Loading branch information
tinarskii committed Nov 13, 2022
1 parent b27a21a commit 12b2c3d
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/commands/Economic Category/daily.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Discord, Slash } from "discordx";
import { Category } from "@discordx/utilities";
import { Colors, CommandInteraction, EmbedBuilder } from "discord.js";
import { findTargetUser, saveNewUserData } from "../../lib/utils";
import ms from "ms";

@Discord()
@Category("Economic")
export class DailyCommand {
@Slash({ name: "daily", description: "Claim your daily reward" })
async daily(interaction: CommandInteraction): Promise<void> {
const data = await findTargetUser(interaction.user.id, interaction);
if (!data) return;

if (Date.now() - (<any>data.timeout).daily < ms("1d")) {
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle("❌ You have already claimed your daily reward")
.setDescription(
`You can claim your daily reward again in **${ms(ms("1d") - (Date.now() - (<any>data.timeout).daily), {
long: true,
})}**`,
)
.setColor(Colors.Red)
.setFooter({
text: `Requested by ${interaction.user.tag}`,
iconURL: interaction.user.displayAvatarURL(),
})
.setTimestamp(),
],
});
}

(<any>data.timeout).daily = Date.now();
data.coin! += 150;
await saveNewUserData(interaction.user.id, data);
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle("✅ Successfully claimed your daily reward")
.setDescription("You have successfully claimed your daily reward")
.setColor(Colors.Green)
.setFooter({
text: `Requested by ${interaction.user.tag}`,
iconURL: interaction.user.displayAvatarURL(),
})
.setTimestamp(),
],
});
}
}
52 changes: 52 additions & 0 deletions src/commands/Economic Category/weekly.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Discord, Slash } from "discordx";
import { Category } from "@discordx/utilities";
import { Colors, CommandInteraction, EmbedBuilder } from "discord.js";
import { findTargetUser, saveNewUserData } from "../../lib/utils";
import ms from "ms";

@Discord()
@Category("Economic")
export class DailyCommand {
@Slash({ name: "weekly", description: "Claim your weekly reward" })
async weekly(interaction: CommandInteraction): Promise<void> {
const data = await findTargetUser(interaction.user.id, interaction);
if (!data) return;

if (Date.now() - (<any>data.timeout).daily < ms("7d")) {
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle("❌ You have already claimed your weekly reward")
.setDescription(
`You can claim your daily reward again in **${ms(ms("7d") - (Date.now() - (<any>data.timeout).daily), {
long: true,
})}**`,
)
.setColor(Colors.Red)
.setFooter({
text: `Requested by ${interaction.user.tag}`,
iconURL: interaction.user.displayAvatarURL(),
})
.setTimestamp(),
],
});
}

(<any>data.timeout).daily = Date.now();
data.coin! += 1500;
await saveNewUserData(interaction.user.id, data);
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle("✅ Successfully claimed your weekly reward")
.setDescription("You have successfully claimed your weekly reward")
.setColor(Colors.Green)
.setFooter({
text: `Requested by ${interaction.user.tag}`,
iconURL: interaction.user.displayAvatarURL(),
})
.setTimestamp(),
],
});
}
}

0 comments on commit 12b2c3d

Please sign in to comment.