feat: add delete learn
This commit is contained in:
parent
aa53e98130
commit
a4fd2390c5
3 changed files with 43 additions and 3 deletions
32
src/deleteLearn.ts
Normal file
32
src/deleteLearn.ts
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import { RowDataPacket, createPool } from 'mysql2/promise'
|
||||
import { type RowDataPacket, createPool } from 'mysql2/promise'
|
||||
import config from '../../config.json'
|
||||
import { type Snowflake } from 'discord.js'
|
||||
|
||||
export interface BaseData extends RowDataPacket {
|
||||
id: number
|
||||
|
@ -15,6 +16,13 @@ export interface ResponseData extends BaseData {
|
|||
search_in_response_to: string
|
||||
}
|
||||
|
||||
export interface LearnData extends RowDataPacket {
|
||||
command: string
|
||||
result: string
|
||||
user_id: Snowflake
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export { BaseData as NSFWData }
|
||||
|
||||
const database = createPool({
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import ChatBot from './ChatBot'
|
||||
import Command from './Command'
|
||||
import database, { ResponseData, NSFWData } from './database'
|
||||
import database, { ResponseData, NSFWData, LearnData } from './database'
|
||||
import noPerm from './noPerm'
|
||||
import { NODE_ENV } from './env'
|
||||
export { ChatBot, Command, database, noPerm, ResponseData, NODE_ENV, NSFWData }
|
||||
export { ChatBot, Command, database, noPerm, ResponseData, NODE_ENV, NSFWData, LearnData }
|
||||
|
|
Loading…
Reference in a new issue