diff --git a/package.json b/package.json index 1d5938e..95e4dc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffin-ai-arujak", - "version": "2.0.0-73-oreo", + "version": "2.0.0-74-oreo", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/modules/database/model/index.ts b/src/modules/database/model/index.ts index 3439c7b..9e10d1f 100644 --- a/src/modules/database/model/index.ts +++ b/src/modules/database/model/index.ts @@ -1 +1,3 @@ export * from './statement' +export * from './learn' +export * from './nsfwContent' diff --git a/src/modules/database/model/learn.ts b/src/modules/database/model/learn.ts new file mode 100644 index 0000000..57e7af9 --- /dev/null +++ b/src/modules/database/model/learn.ts @@ -0,0 +1,61 @@ +import { type Pool } from 'mysql2/promise' +import run from '../run' +import type { BaseTable, LearnData } from '../type' +import { Snowflake } from 'discord.js' + +export class LearnTable implements BaseTable { + public name = 'learn' + public constructor(private _database: Pool) {} + + public async all(): Promise { + const [rows] = await this._database.execute( + 'SELECT * FROM learn;', + ) + return rows + } + + public async findOne(key: string): Promise { + const [rows] = await this._database.execute( + 'SELECT * FROM learn WHERE command = ?;', + [key], + ) + return rows + } + + public async insert(data: { + command: string + result: string + user_id: Snowflake + }): Promise { + const db = await this._database.getConnection() + + await run(db, async () => { + await db.execute( + 'INSERT INTO learn (command, result, user_id) VALUES (?, ?, ?);', + [data.command, data.result, data.user_id], + ) + }) + } + + public async update(data: { + command: string + result: string + }): Promise { + const db = await this._database.getConnection() + + await run(db, async () => { + await db.execute('UPDATE learn SET result = ? WHERE command = ?;', [ + data.command, + data.result, + ]) + }) + } + + public async delete(key: string): Promise { + const db = await this._database.getConnection() + + await run(db, async () => { + await db.execute('DELETE FROM learn WHERE command = ?;', [key]) + }) + } +} diff --git a/src/modules/database/model/nsfwContent.ts b/src/modules/database/model/nsfwContent.ts new file mode 100644 index 0000000..fc40cd6 --- /dev/null +++ b/src/modules/database/model/nsfwContent.ts @@ -0,0 +1,57 @@ +import { type Pool } from 'mysql2/promise' +import run from '../run' +import type { BaseTable, NSFWData } from '../type' + +export class NsfwContentTable implements BaseTable { + public name = 'nsfw_content' + public constructor(private _database: Pool) {} + + public async all(): Promise { + const [rows] = await this._database.execute( + 'SELECT * FROM nsfw_content;', + ) + return rows + } + + public async findOne(key: number): Promise { + const [rows] = await this._database.execute( + 'SELECT * FROM nsfw_content WHERE id = ?;', + [key], + ) + return rows + } + + public async insert(data: { + id: number + text: string + persona: string + }): Promise { + const db = await this._database.getConnection() + + await run(db, async () => { + await db.execute( + 'INSERT INTO nsfw_content (id, text, persona) VALUES (?, ?, ?);', + [data.id, data.text, data.persona], + ) + }) + } + + public async update(data: { id: number; text: string }): Promise { + const db = await this._database.getConnection() + + await run(db, async () => { + await db.execute('UPDATE nsfw_content SET text = ? WHERE id = ?;', [ + data.text, + data.id, + ]) + }) + } + + public async delete(key: number): Promise { + const db = await this._database.getConnection() + + await run(db, async () => { + await db.execute('DELETE FROM nsfw_content WHERE id = ?;', [key]) + }) + } +}