diff --git a/scripts/create_table.sql b/scripts/create_table.sql index 0111ab1..02fbfeb 100755 --- a/scripts/create_table.sql +++ b/scripts/create_table.sql @@ -18,4 +18,13 @@ CREATE TABLE `created_at` datetime DEFAULT current_timestamp(), `persona` varchar(50) NOT NULL DEFAULT '', PRIMARY KEY (`id`) + ); + +CREATE TABLE + learn ( + command varchar(255) NOT NULL, + result varchar(255) NOT NULL, + user_id varchar(255) NOT NULL, + created_at datetime NOT NULL current_timestamp(), + primary key(`command`) ); \ No newline at end of file diff --git a/src/Commands/learn.ts b/src/Commands/learn.ts new file mode 100644 index 0000000..3c2bdbb --- /dev/null +++ b/src/Commands/learn.ts @@ -0,0 +1,52 @@ +import { Command } from '../modules' +import { Message } from 'discord.js' + +export default class extends Command { + public constructor() { + super('배워') + } + + public async execute(msg: Message, args: string[]) { + const command = args[0] + const result = args[1].replaceAll('_', ' ') + const ignore = [ + '학습데이터량', + '봇꺼', + '테스트', + '미간', + 'Migan', + 'migan', + '간미', + ] + const disallowed = ['@everyone', '@here'] + const db = await msg.client.chatBot.db.getConnection() + + ignore.forEach(ig => { + if (result.includes(ig)) { + return msg.channel.send('해ㄷ당 단어는 배울ㄹ 수 없어요.') + } + }) + + disallowed.forEach(di => { + if (result.includes(di)) { + return msg.channel.send('해당 단ㅇ어는 금지되어 있ㅅ어요.') + } + }) + + try { + await db.beginTransaction() + db.execute( + 'INSERT INTO learn (command, result, user_id) VALUES (?, ?, ?);', + [command, result, msg.author.id], + ) + await msg.channel.send(`${command}을/를 배웠ㅇ어요.`) + await db.commit() + } catch (err) { + console.error(err) + await db.rollback() + await msg.channel.send('배우는데 오류ㄹ가 생겨서 배우지 못했어ㅇ요.') + } finally { + db.release() + } + } +}