-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command): add daily and weely command
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
], | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
], | ||
}); | ||
} | ||
} |