feat: add delete learn

This commit is contained in:
Siwoo Jeon 2023-11-24 12:40:27 +09:00
parent aa53e98130
commit a4fd2390c5
Signed by: migan
GPG key ID: C4151385FFD2082A
3 changed files with 43 additions and 3 deletions

32
src/deleteLearn.ts Normal file
View file

@ -0,0 +1,32 @@
import { Message } from 'discord.js'
import { Command, LearnData } from './modules'
export default class extends Command {
public constructor() {
super('삭제')
}
public async execute(msg: Message, args: string[]) {
const db = await msg.client.chatBot.db.getConnection()
const command = args[0]
const [rows] = await db.execute<LearnData[]>('SELECT * FROM learn WHERE command = ?;', [command])
if (!rows[0]) {
await msg.channel.send('해당하는 걸 찾ㅈ을 수 없어요.')
}
if (rows[0].user_id !== msg.author.id) {
await msg.channel.send('당신ㄴ은 해당 지식을 안가르ㄹ쳐 주셨ㅅ는데요?')
}
try {
await db.beginTransaction()
await db.execute('DELETE FROM learn WHERE command = ?;', [command])
await msg.channel.send('해당 단어를 삭ㄱ제했어요.')
await db.commit()
} catch (err) {
console.error(err)
} finally {
db.release()
}
}
}

View file

@ -1,5 +1,6 @@
import { RowDataPacket, createPool } from 'mysql2/promise' import { type RowDataPacket, createPool } from 'mysql2/promise'
import config from '../../config.json' import config from '../../config.json'
import { type Snowflake } from 'discord.js'
export interface BaseData extends RowDataPacket { export interface BaseData extends RowDataPacket {
id: number id: number
@ -15,6 +16,13 @@ export interface ResponseData extends BaseData {
search_in_response_to: string search_in_response_to: string
} }
export interface LearnData extends RowDataPacket {
command: string
result: string
user_id: Snowflake
created_at: string
}
export { BaseData as NSFWData } export { BaseData as NSFWData }
const database = createPool({ const database = createPool({

View file

@ -1,6 +1,6 @@
import ChatBot from './ChatBot' import ChatBot from './ChatBot'
import Command from './Command' import Command from './Command'
import database, { ResponseData, NSFWData } from './database' import database, { ResponseData, NSFWData, LearnData } from './database'
import noPerm from './noPerm' import noPerm from './noPerm'
import { NODE_ENV } from './env' import { NODE_ENV } from './env'
export { ChatBot, Command, database, noPerm, ResponseData, NODE_ENV, NSFWData } export { ChatBot, Command, database, noPerm, ResponseData, NODE_ENV, NSFWData, LearnData }