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.
62 lines
2.2 KiB
62 lines
2.2 KiB
import {CommandContext, CommandOptionType, SlashCommand, SlashCreator} from "slash-create";
|
|
import {Chance} from "chance";
|
|
import {Snowflake} from "discord-api-types";
|
|
import {Pool} from "pg";
|
|
import {sendErrorMessage} from "../../queries/ErrorCodes.js";
|
|
|
|
const rand = Chance()
|
|
|
|
export class PullCommand extends SlashCommand {
|
|
readonly pool: Pool
|
|
|
|
constructor(creator: SlashCreator, {pool, gameGuildIds}: {
|
|
pool: Pool,
|
|
gameGuildIds: Snowflake[]
|
|
}) {
|
|
super(creator, {
|
|
name: "pull",
|
|
guildIDs: gameGuildIds,
|
|
description: "Pulls one or more new heroines from the ether.",
|
|
options: [
|
|
{
|
|
name: "count",
|
|
description: "The number of heroines to pull.",
|
|
required: false,
|
|
max_value: 10,
|
|
min_value: 1,
|
|
type: CommandOptionType.NUMBER,
|
|
}
|
|
]
|
|
});
|
|
|
|
this.pool = pool
|
|
}
|
|
|
|
async run(ctx: CommandContext): Promise<any> {
|
|
try {
|
|
const count: number =
|
|
typeof ctx.options.count === "number"
|
|
&& ctx.options.count >= 1
|
|
&& ctx.options.count <= 10 ? Math.floor(ctx.options.count) : 1
|
|
await this.pool.query({
|
|
text: `SELECT *
|
|
FROM Command_Pull($1, $2, $3, $4, $5, $6)`,
|
|
values: [ctx.channelID, ctx.guildID, ctx.user.id, ctx.user.username, ctx.user.discriminator, count],
|
|
})
|
|
const results: string[] = []
|
|
for (let x = 0; x < count; x += 1) {
|
|
results.push(rand.weighted(["**Nicole**: D tier Predator Podcaster",
|
|
"**Herja**: C tier Viking Warrior",
|
|
"**Sharla**: B tier Skark Girl",
|
|
"**Melpomene**: A tier Muse of Tragedy",
|
|
"**Lady Bootstrap**: S tier Time Traveler"], [20, 15, 10, 5, 1]))
|
|
}
|
|
return ctx.send({
|
|
content: `_${ctx.user.mention}_, you pulled...\n \\* ${results.join("\n \\* ")}`,
|
|
ephemeral: false,
|
|
})
|
|
} catch (e) {
|
|
await sendErrorMessage(ctx, e)
|
|
}
|
|
}
|
|
} |