add basic character rolling

This commit is contained in:
Hexugory 2023-03-29 16:08:38 -05:00
parent 14a6170819
commit db289b3e49
5 changed files with 104 additions and 1 deletions

21
src/characters.ts Normal file
View File

@ -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<number, Character> = new Collection(charactersJSON.map((element, index) => {return [index, element]}));

View File

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

11
src/models/unit.ts Normal file
View File

@ -0,0 +1,11 @@
import { CreationOptional, InferAttributes, InferCreationAttributes, Model } from "sequelize";
export class Unit extends Model<InferAttributes<Unit>, InferCreationAttributes<Unit>> {
declare user_id: string
declare character_id: number
declare stat1: number
declare stat2: number
declare stat3: number
declare stat4: number
declare stat5: number
}

View File

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

40
src/slash/roll.ts Normal file
View File

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