3.0.0-Cake #5

Merged
migan merged 33 commits from release/3.0.0 into main 2024-08-14 14:16:30 +00:00
7 changed files with 63 additions and 10 deletions
Showing only changes of commit 38810a3f1b - Show all commits

View file

@ -1,6 +1,6 @@
{
"name": "muffinbot",
"version": "2.1.0-oreo.b240611a",
"version": "2.1.0-oreo.b240618a",
"main": "dist/index.js",
"private": true,
"dependencies": {

View file

@ -1,5 +1,5 @@
import { Message } from 'discord.js'
import { Command } from '../modules'
import { Command, type LearnData } from '../modules'
export default class extends Command {
public constructor() {
@ -9,21 +9,43 @@ export default class extends Command {
if (!args[0]) {
return await msg.channel.send('```머핀아 삭제 (지울 단어)```')
}
const command = args[0]
const db = msg.client.chatBot.db
const data = await db.learn.findOne(command)
const [data] = await db.learn.execute<LearnData[]>(
'SELECT * FROM learn WHERE command = ? AND user_id = ?;',
[command, msg.author.id],
)
console.log(data)
if (!data[0]) {
return await msg.channel.send('해당하는 걸 찾ㅈ을 수 없어요.')
}
if (data[0].user_id !== msg.author.id) {
return await msg.channel.send(
'어라 당ㅅ신은 언제 가르쳐 주셨죠?',
)
console.log(data.length)
if (data.length > 1) {
console.log('a')
} else {
// await db.learn.delete(command)
// await msg.reply('어라 이제 그ㄱ게 기억이 안나요. 뭐ㅇ였죠?')
console.log('b')
}
await db.learn.delete(command)
await msg.reply('어라 이제 그ㄱ게 기억이 안나요.')
await msg.reply('현재 이 기능은 재작성 중입니다.')
// if (!data[0]) {
// return await msg.channel.send('해당하는 걸 찾ㅈ을 수 없어요.')
// }
//
// if (data[0].user_id !== msg.author.id) {
// return await msg.channel.send(
// '어라 당ㅅ신은 언제 가르쳐 주셨죠?',
// )
// }
//
// await db.learn.delete(command)
// await msg.reply('어라 이제 그ㄱ게 기억이 안나요.')
}
}

View file

@ -69,4 +69,14 @@ export class LearnTable implements BaseTable<LearnData, string> {
)
return rows
}
public async execute<W>(sql: string, values?: any): Promise<W> {
const db = await this._database.getConnection()
let data: any
await run(db, async () => {
data = await db.execute(sql, [...values])
})
return data
}
}

View file

@ -61,4 +61,14 @@ export class NSFWContentTable implements BaseTable<NSFWData, number> {
)
return rows
}
public async execute<W>(sql: string, values?: any): Promise<W> {
const db = await this._database.getConnection()
let data: any
await run(db, async () => {
data = await db.execute(sql, [...values])
})
return data
}
}

View file

@ -73,4 +73,14 @@ export class StatementTable implements BaseTable<ResponseData, number> {
)
return rows
}
public async execute<W>(sql: string, values?: any): Promise<W> {
const db = await this._database.getConnection()
let data: any
await run(db, async () => {
data = await db.execute(sql, [...values])
})
return data
}
}

View file

@ -1,6 +1,6 @@
import { type PoolConnection } from 'mysql2/promise'
export default async function run(db: PoolConnection, fn: () => Promise<void>) {
export default async function run(db: PoolConnection, fn: () => Promise<any>) {
try {
await db.beginTransaction()
await fn()

View file

@ -33,4 +33,5 @@ export interface BaseTable<T, V> {
update(data: any): Promise<void>
delete(key: V): Promise<void>
findOneAnotherKey(key: string, data: any): Promise<T[]>
execute<W>(sql: string, values?: any): Promise<W>
}