From 0fb8358a86ddfb146f4a4f0496a6fc6fe71205ba Mon Sep 17 00:00:00 2001 From: Hexugory Date: Wed, 29 Mar 2023 14:33:44 -0500 Subject: [PATCH] better naming --- src/commandclient.ts | 4 ++-- src/commands/gblacklist.ts | 6 +++--- src/database.ts | 12 ++++++------ src/models/blacklistuser.ts | 5 +++++ src/models/blacklistusers.ts | 5 ----- src/models/{players.ts => player.ts} | 2 +- src/slash/init.ts | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 src/models/blacklistuser.ts delete mode 100644 src/models/blacklistusers.ts rename src/models/{players.ts => player.ts} (67%) diff --git a/src/commandclient.ts b/src/commandclient.ts index c9b1fb2..076f149 100644 --- a/src/commandclient.ts +++ b/src/commandclient.ts @@ -4,7 +4,7 @@ import strings from "./clientstrings.json"; import { Sequelize } from "sequelize"; import { CommandList } from "./commands/commandlist"; import { Command } from "./commands/command"; -import { BlacklistUsers } from "./models/blacklistusers"; +import { BlacklistUser } from "./models/blacklistuser"; import { CommandBlacklist } from "./models/commandblacklist"; import { SlashCommand } from "./slash/slash"; import { SlashCommandList } from "./slash/commandlist"; @@ -30,7 +30,7 @@ export class CommandClient extends Client { this.on('messageCreate', async (msg: Message) => { if (!msg.content.startsWith(config.prefix) || msg.author.bot) return; - if (!config.owners.includes(msg.author.id) && (await BlacklistUsers.findOne({ where: { user_id: msg.author.id } }))) return; + if (!config.owners.includes(msg.author.id) && (await BlacklistUser.findOne({ where: { user_id: msg.author.id } }))) return; this.parseCommand(msg); }); diff --git a/src/commands/gblacklist.ts b/src/commands/gblacklist.ts index 7dabd52..1298130 100644 --- a/src/commands/gblacklist.ts +++ b/src/commands/gblacklist.ts @@ -1,7 +1,7 @@ import { Message, User } from "discord.js" import { Command } from "./command" import { UserArgument } from "../types/user" -import { BlacklistUsers } from "../models/blacklistusers" +import { BlacklistUser } from "../models/blacklistuser" interface GlobalBlacklistArguments { users: User[] @@ -29,14 +29,14 @@ export class GlobalBlacklistCommand implements Command { let replystr = ''; for (const user of args.users){ - const row = (await BlacklistUsers.findOne({ where: { user_id: user.id } })); + const row = (await BlacklistUser.findOne({ where: { user_id: user.id } })); if (row) { row.destroy() replystr += `${user.tag}: removed\n` } else { - await BlacklistUsers.create({ user_id: user.id }); + await BlacklistUser.create({ user_id: user.id }); replystr += `${user.tag}: added\n` } } diff --git a/src/database.ts b/src/database.ts index 10a2d6a..4d9a42b 100644 --- a/src/database.ts +++ b/src/database.ts @@ -1,7 +1,7 @@ import { DataTypes, Sequelize } from "sequelize"; -import { BlacklistUsers } from "./models/blacklistusers"; +import { BlacklistUser } from "./models/blacklistuser"; import { CommandBlacklist } from "./models/commandblacklist"; -import { Players } from "./models/players"; +import { Player } from "./models/player"; export const db = new Sequelize({ dialect: 'sqlite', @@ -9,14 +9,14 @@ export const db = new Sequelize({ logging: false }); -BlacklistUsers.init({ +BlacklistUser.init({ user_id: { type: DataTypes.TEXT, primaryKey: true } }, { - tableName: 'BlacklistUsers', + tableName: 'BlacklistUser', sequelize: db }); @@ -33,7 +33,7 @@ CommandBlacklist.init({ sequelize: db }); -Players.init({ +Player.init({ user_id: { type: DataTypes.TEXT, primaryKey: true @@ -47,7 +47,7 @@ Players.init({ } }, { - tableName: 'Players', + tableName: 'Player', sequelize: db }); diff --git a/src/models/blacklistuser.ts b/src/models/blacklistuser.ts new file mode 100644 index 0000000..272547a --- /dev/null +++ b/src/models/blacklistuser.ts @@ -0,0 +1,5 @@ +import { InferAttributes, InferCreationAttributes, Model } from "sequelize"; + +export class BlacklistUser extends Model, InferCreationAttributes> { + declare readonly user_id: string +} \ No newline at end of file diff --git a/src/models/blacklistusers.ts b/src/models/blacklistusers.ts deleted file mode 100644 index 8f36102..0000000 --- a/src/models/blacklistusers.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { InferAttributes, InferCreationAttributes, Model } from "sequelize"; - -export class BlacklistUsers extends Model, InferCreationAttributes> { - declare readonly user_id: string -} \ No newline at end of file diff --git a/src/models/players.ts b/src/models/player.ts similarity index 67% rename from src/models/players.ts rename to src/models/player.ts index 1b42e70..ebcf58f 100644 --- a/src/models/players.ts +++ b/src/models/player.ts @@ -1,6 +1,6 @@ import { CreationOptional, InferAttributes, InferCreationAttributes, Model } from "sequelize"; -export class Players extends Model, InferCreationAttributes> { +export class Player extends Model, InferCreationAttributes> { declare readonly user_id: string declare start: number declare spent: CreationOptional diff --git a/src/slash/init.ts b/src/slash/init.ts index f0db2a2..4bdae71 100644 --- a/src/slash/init.ts +++ b/src/slash/init.ts @@ -1,5 +1,5 @@ import { ApplicationCommandOptionData, ApplicationCommandOptionType, CommandInteraction } from "discord.js" -import { Players } from "../models/players" +import { Player } from "../models/player" import { SlashCommand } from "./slash" export class InitCommand implements SlashCommand { @@ -11,7 +11,7 @@ export class InitCommand implements SlashCommand { args: ApplicationCommandOptionData[] = [] async execute(int: CommandInteraction) { - const player = await Players.findOne({ + const player = await Player.findOne({ where: { user_id: int.user.id } @@ -22,7 +22,7 @@ export class InitCommand implements SlashCommand { ephemeral: true }); - Players.create({ + Player.create({ user_id: int.user.id, start: Math.floor(Date.now()/1000) });