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.
78 lines
2.7 KiB
78 lines
2.7 KiB
import {CommandContext, CommandOptionType, SlashCommand, SlashCreator} from "slash-create";
|
|
import {Snowflake} from "discord-api-types";
|
|
import {Pool} from "pg";
|
|
import {sendErrorMessage} from "../../queries/ErrorCodes.js";
|
|
|
|
interface PullResult {
|
|
summonedunitinstanceid: number,
|
|
summonedunitid: number,
|
|
summonedunitname: string,
|
|
summonedunitsubtitle: string,
|
|
summonedunittierid: string,
|
|
summonedunittiername: string,
|
|
summoncost: number,
|
|
resultingcurrency: number,
|
|
firsttimepull: boolean,
|
|
wasalreadysummoned: boolean,
|
|
}
|
|
|
|
type PartialResult = Omit<PullResult, "summonedunitinstanceid" | "firsttimepull" | "wasalreadysummoned">
|
|
|
|
function formatPullResult(r: PullResult): string {
|
|
return `${r.wasalreadysummoned ? "deepened your bond with" :
|
|
r.firsttimepull ? "forged a **new bond** with" : "summoned forth"} ***${r.summonedunitname}***, ` +
|
|
`**${r.summonedunitsubtitle}**! _(${r.summonedunittiername})_`
|
|
}
|
|
|
|
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
|
|
const dbResult: PartialResult[] = (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],
|
|
})).rows
|
|
const textResult: string[] = dbResult.map((result) => ({
|
|
...result,
|
|
summonedunitinstanceid: 0,
|
|
firsttimepull: false,
|
|
wasalreadysummoned: false
|
|
})).map(formatPullResult)
|
|
return ctx.send({
|
|
content: `_${ctx.user.mention}_, you ${textResult.join("\n And you also ")}`,
|
|
ephemeral: false,
|
|
})
|
|
} catch (e) {
|
|
await sendErrorMessage(ctx, e)
|
|
}
|
|
}
|
|
} |