players may now exist maybe

This commit is contained in:
Hexugory 2023-03-29 00:11:57 -05:00
parent a4d08f0696
commit 62920af0e3
5 changed files with 65 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import { CommandClient } from "./commandclient";
export class CBClient extends CommandClient {
}

View File

@ -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();
})();

7
src/models/players.ts Normal file
View File

@ -0,0 +1,7 @@
import { CreationOptional, InferAttributes, InferCreationAttributes, Model } from "sequelize";
export class Players extends Model<InferAttributes<Players>, InferCreationAttributes<Players>> {
declare readonly user_id: string
declare start: number
declare spent: CreationOptional<number>
}

View File

@ -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()
];

35
src/slash/init.ts Normal file
View File

@ -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
})
}
};