diff --git a/src/characters.ts b/src/characters.ts new file mode 100644 index 0000000..fe3afbf --- /dev/null +++ b/src/characters.ts @@ -0,0 +1,21 @@ +import charactersJSON from './characters.json' +import { Collection } from 'discord.js' + +export enum Type { + Something +} + +interface Character { + id: number; + name: string; + nameShort: string; + type: Type; + img: string; + stat1: number; + stat2: number; + stat3: number; + stat4: number; + stat5: number; +} + +export const CHARACTERS: Collection = new Collection(charactersJSON.map((element, index) => {return [index, element]})); \ No newline at end of file diff --git a/src/database.ts b/src/database.ts index 4d9a42b..01ded09 100644 --- a/src/database.ts +++ b/src/database.ts @@ -2,6 +2,7 @@ import { DataTypes, Sequelize } from "sequelize"; import { BlacklistUser } from "./models/blacklistuser"; import { CommandBlacklist } from "./models/commandblacklist"; import { Player } from "./models/player"; +import { Unit } from "./models/unit"; export const db = new Sequelize({ dialect: 'sqlite', @@ -51,6 +52,34 @@ Player.init({ sequelize: db }); +Unit.init({ + user_id: { + type: DataTypes.TEXT + }, + character_id: { + type: DataTypes.INTEGER + }, + stat1: { + type: DataTypes.INTEGER + }, + stat2: { + type: DataTypes.INTEGER + }, + stat3: { + type: DataTypes.INTEGER + }, + stat4: { + type: DataTypes.INTEGER + }, + stat5: { + type: DataTypes.INTEGER + } +}, +{ + tableName: 'Unit', + sequelize: db +}); + (async () => { await db.sync(); })(); diff --git a/src/models/unit.ts b/src/models/unit.ts new file mode 100644 index 0000000..b759da6 --- /dev/null +++ b/src/models/unit.ts @@ -0,0 +1,11 @@ +import { CreationOptional, InferAttributes, InferCreationAttributes, Model } from "sequelize"; + +export class Unit extends Model, InferCreationAttributes> { + declare user_id: string + declare character_id: number + declare stat1: number + declare stat2: number + declare stat3: number + declare stat4: number + declare stat5: number +} \ No newline at end of file diff --git a/src/slash/commandlist.ts b/src/slash/commandlist.ts index cacbe0f..b747a54 100644 --- a/src/slash/commandlist.ts +++ b/src/slash/commandlist.ts @@ -1,8 +1,10 @@ import { InitCommand } from "./init"; import { RandomCaseCommand } from "./randomcase"; +import { RollCommand } from "./roll"; import { SlashCommand } from "./slash"; export const SlashCommandList: SlashCommand[] = [ new RandomCaseCommand(), - new InitCommand() + new InitCommand(), + new RollCommand() ]; \ No newline at end of file diff --git a/src/slash/roll.ts b/src/slash/roll.ts new file mode 100644 index 0000000..98ac8b1 --- /dev/null +++ b/src/slash/roll.ts @@ -0,0 +1,40 @@ +import { ApplicationCommandOptionData, ApplicationCommandOptionType, CommandInteraction } from "discord.js" +import { CBClient } from "../cbclient" +import { CHARACTERS } from "../characters" +import { Unit } from "../models/unit" +import { createArgumentsObject, SlashCommand } from "./slash" + +export class RollCommand implements SlashCommand { + name = 'roll' + description = 'Pull a random character' + permission = [] + ownerOnly = false + guildOnly = false + guildID = "739645806100873328" //for testing + args: ApplicationCommandOptionData[] = [] + + async execute(int: CommandInteraction) { + const client = int.client as CBClient; + const player = await client.findOrCreatePlayer(int.user.id); + + if (!(await client.spendOnPlayer(player, 0))) return int.reply({ + content: "You don't have the money!", + ephemeral: true + }); + + const character = CHARACTERS.random()!; + await Unit.create({ + user_id: int.user.id, + character_id: character.id, + stat1: character.stat1, + stat2: character.stat2, + stat3: character.stat3, + stat4: character.stat4, + stat5: character.stat5 + }); + + return int.reply({ + content: `You got **${character.name}**!` + }); + } +};