Gacha game centered around vore.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
vore-gacha/src/commands/game/DailyCommand.ts

47 lines
2.0 KiB

import {CommandContext, SlashCommand, SlashCreator} from "slash-create";
import {Snowflake} from "discord-api-types";
import {Pool} from "pg";
import {sendErrorMessage} from "../../queries/ErrorCodes.js";
import {singleRowQueryResult} from "../../queries/QueryHelpers.js";
export class DailyCommand extends SlashCommand {
readonly pool: Pool
constructor(creator: SlashCreator, {pool, gameGuildIds}: {
pool: Pool,
gameGuildIds: Snowflake[]
}) {
super(creator, {
name: "daily",
guildIDs: gameGuildIds,
description: "Gathers your daily currency once per day, resetting at midnight UTC.",
options: []
});
this.pool = pool
}
async run(ctx: CommandContext): Promise<any> {
try {
const result = singleRowQueryResult(await this.pool.query<{ newlastdaily: Date, newnextdaily: Date, newcurrency: number, bonus: number }>({
text: `SELECT *
FROM Command_Daily($1, $2, $3, $4, $5)`,
values: [ctx.channelID, ctx.guildID, ctx.user.id, ctx.user.username, ctx.user.discriminator],
}))
if (result === undefined) {
await ctx.send({
content: "Unexpectedly got no results!!",
ephemeral: true,
})
console.log("Unexpectedly empty Command_Join result!")
return;
}
return ctx.send({
content: `Nice! You reap ${result.bonus} currency from the void, leaving you with a total of ${result.newcurrency}!\n\nYou collected your currency now at <t:${Math.floor(result.newlastdaily.getTime() / 1000)}> and can gather it again in <t:${Math.floor(result.newnextdaily.getTime() / 1000)}:R> at <t:${Math.floor(result.newnextdaily.getTime() / 1000)}>.`,
ephemeral: true,
})
} catch (e) {
await sendErrorMessage(ctx, e)
}
}
}