diff --git a/src/cbclient.ts b/src/cbclient.ts index a845231..ce6a741 100644 --- a/src/cbclient.ts +++ b/src/cbclient.ts @@ -1,5 +1,5 @@ import { CommandClient } from "./commandclient"; export class CBClient extends CommandClient { - + } \ No newline at end of file diff --git a/src/database.ts b/src/database.ts index f69a214..10a2d6a 100644 --- a/src/database.ts +++ b/src/database.ts @@ -1,6 +1,7 @@ import { DataTypes, Sequelize } from "sequelize"; import { BlacklistUsers } from "./models/blacklistusers"; import { CommandBlacklist } from "./models/commandblacklist"; +import { Players } from "./models/players"; export const db = new Sequelize({ dialect: 'sqlite', @@ -32,6 +33,24 @@ CommandBlacklist.init({ sequelize: db }); +Players.init({ + user_id: { + type: DataTypes.TEXT, + primaryKey: true + }, + start: { + type: DataTypes.BIGINT + }, + spent: { + type: DataTypes.BIGINT, + defaultValue: 0 + } +}, +{ + tableName: 'Players', + sequelize: db +}); + (async () => { await db.sync(); })(); diff --git a/src/models/players.ts b/src/models/players.ts new file mode 100644 index 0000000..1b42e70 --- /dev/null +++ b/src/models/players.ts @@ -0,0 +1,7 @@ +import { CreationOptional, InferAttributes, InferCreationAttributes, Model } from "sequelize"; + +export class Players extends Model, InferCreationAttributes> { + declare readonly user_id: string + declare start: number + declare spent: CreationOptional +} \ No newline at end of file diff --git a/src/slash/commandlist.ts b/src/slash/commandlist.ts index ebba093..cacbe0f 100644 --- a/src/slash/commandlist.ts +++ b/src/slash/commandlist.ts @@ -1,6 +1,8 @@ +import { InitCommand } from "./init"; import { RandomCaseCommand } from "./randomcase"; import { SlashCommand } from "./slash"; export const SlashCommandList: SlashCommand[] = [ - new RandomCaseCommand() + new RandomCaseCommand(), + new InitCommand() ]; \ No newline at end of file diff --git a/src/slash/init.ts b/src/slash/init.ts new file mode 100644 index 0000000..8b8cce3 --- /dev/null +++ b/src/slash/init.ts @@ -0,0 +1,35 @@ +import { ApplicationCommandOptionData, ApplicationCommandOptionType, CommandInteraction } from "discord.js" +import { Players } from "../models/players" +import { SlashCommand } from "./slash" + +export class InitCommand implements SlashCommand { + name = 'init' + description = 'Adds you as a player' + permission = [] + ownerOnly = false + guildOnly = true + args: ApplicationCommandOptionData[] = [] + + async execute(int: CommandInteraction) { + const player = await Players.findOne({ + where: { + user_id: int.user.id + } + }); + + if (player) return int.reply({ + content: "You're already in the game.", + ephemeral: true + }); + + Players.create({ + user_id: int.user.id, + start: Date.now()/1000 + }); + + return int.reply({ + content: "You've been added to the game.", + ephemeral: true + }) + } +};