This commit is contained in:
Siwoo Jeon 2023-12-02 23:33:55 +09:00
parent 3cd80e646f
commit 42519e6d46
Signed by: migan
GPG key ID: C4151385FFD2082A
6 changed files with 28 additions and 62 deletions

View file

@ -22,9 +22,10 @@ CREATE TABLE
CREATE TABLE
learn (
id int(11) NOT NULL,
command varchar(255) NOT NULL,
result varchar(255) NOT NULL,
user_id varchar(255) NOT NULL,
created_at datetime NOT NULL DEFAULT current_timestamp(),
primary key(`command`)
primary key(`id`)
);

View file

@ -1,40 +1,13 @@
import { Message } from 'discord.js'
import { Command, LearnData } from '../modules'
import { Command } from '../modules'
export default class extends Command {
public constructor() {
super('삭제')
}
public async execute(msg: Message, args: string[]) {
if (!args[0]) {
return await msg.channel.send('```멒힌아 삭제 (지울 단어)```')
}
const db = await msg.client.chatBot.db.getConnection()
const command = args[0]
const [rows] = await db.execute<LearnData[]>(
'SELECT * FROM learn WHERE command = ?;',
[command],
msg.channel.send(
'현재는 사용할 수 없는 기능이예요. 만약 삭제를 원할 경우 개발자에게 문의해주세요.',
)
if (!rows[0]) {
return await msg.channel.send('해당하는 걸 찾ㅈ을 수 없어요.')
}
if (rows[0].user_id !== msg.author.id) {
return 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

@ -33,16 +33,6 @@ export default class extends Command {
[command],
)
if (learn[0]) {
if (msg.author.id !== learn[0].user_id) {
return msg.channel.send(
`해ㄷ당 단어는 이미 ${
(await msg.client.users.fetch(learn[0].user_id)).username
} .`,
)
}
}
for (const ig of ignore) {
if (command.includes(ig)) {
return msg.channel.send('해ㄷ당 단어는 배울ㄹ 수 없어요.')
@ -57,21 +47,11 @@ export default class extends Command {
try {
await db.beginTransaction()
if (learn[0] && msg.author.id === learn[0].user_id) {
await db.execute('UPDATE learn SET result = ? WHERE command = ?;', [
result,
command,
])
await msg.channel.send(`${command}을/를 다시 배ㅂ웠어요.`)
} else {
await db.execute(
'INSERT INTO learn (command, result, user_id) VALUES (?, ?, ?);',
[command, result, msg.author.id],
)
await msg.channel.send(`${command}을/를 배웠ㅇ어요.`)
}
await db.execute(
'INSERT INTO learn (id, command, result, user_id) VALUES (?, ?, ?, ?);',
[++learn[learn.length - 1].id, command, result, msg.author.id],
)
await msg.channel.send(`${command}을/를 배웠ㅇ어요.`)
await db.commit()
} catch (err) {
console.error(err)

View file

@ -33,7 +33,7 @@ export default class extends Command {
list.map(item => `- ${item}`).join('\n'),
),
color: 0x0000ff,
timestamp: new Date().toISOString()
timestamp: new Date().toISOString(),
},
],
})

View file

@ -30,11 +30,22 @@ export default class ChatBot {
if (a === 1) {
if (learn[0]) {
if (args.startsWith(learn[0].command)) {
db.release()
return `${learn[0].result}\n\`${
(await msg.client.users.fetch(learn[0].user_id)).username
} .\``
if (learn[1]) {
if (args.startsWith(learn[0].command)) {
const response =
learn[Math.floor(Math.random() * learn.length)].result
db.release()
return `${response}\n\`${
(await msg.client.users.fetch(learn[0].user_id)).username
} .\``
}
} else {
if (args.startsWith(learn[0].command)) {
db.release()
return `${learn[0].result}\n\`${
(await msg.client.users.fetch(learn[0].user_id)).username
} .\``
}
}
}
}

View file

@ -17,6 +17,7 @@ export interface ResponseData extends BaseData {
}
export interface LearnData extends RowDataPacket {
id: number
command: string
result: string
user_id: Snowflake