From 91537e48eb345092075f3a3a9885e7ba9818b792 Mon Sep 17 00:00:00 2001 From: Migan178 Date: Wed, 25 Jan 2023 14:42:09 +0900 Subject: [PATCH] feat: turn on/off user train --- src/ChatBot.ts | 7 ++++--- src/Client.ts | 37 ++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/ChatBot.ts b/src/ChatBot.ts index ba6f158..89fdcad 100644 --- a/src/ChatBot.ts +++ b/src/ChatBot.ts @@ -26,7 +26,7 @@ export default class ChatBot { return this } - public train(client: Client): ChatBot { + public train(client: Client, user?: boolean): ChatBot { client.on('messageCreate', msg => { if (msg.author.bot) return if (msg.author.id === '1026185545837191238') { @@ -38,10 +38,11 @@ export default class ChatBot { } ) } else { + if (!user) return if (!msg.content.startsWith('머핀아 ')) return - const sql = `INSERT INTO statement(text) VALUES('${msg.content + const sql = `INSERT INTO statement(text, persona) VALUES('${msg.content .replace('머핀아 ', '') - .replaceAll("'", '')}');` + .replaceAll("'", '')}', 'user');` this.db.run(sql, err => { if (err) throw err }) diff --git a/src/Client.ts b/src/Client.ts index be34d7b..e2f38bf 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,10 +1,22 @@ -import { ActivityType, Client, GatewayIntentBits } from 'discord.js' +import { ActivityType, Client, GatewayIntentBits, Message } from 'discord.js' import ChatBot from './ChatBot.js' import { join, dirname } from 'node:path' import { fileURLToPath } from 'node:url' import Dokdo from 'dokdo' import 'dotenv/config' +function noPerm(msg: Message) { + msg.reply({ + content: '당신은 내 남자친구가 아니야!', + allowedMentions: { + repliedUser: false, + parse: [], + users: [], + roles: [], + }, + }) +} + export default class MuffinAI extends Client { private chatBot = new ChatBot( join(dirname(fileURLToPath(import.meta.url)), '..', 'db', 'db.sqlite3') @@ -20,7 +32,7 @@ export default class MuffinAI extends Client { } public override login(): Promise { - this.chatBot.train(this) + this.chatBot.train(this, true) this.once('ready', client => { client.user!.setActivity({ type: ActivityType.Playing, @@ -31,31 +43,14 @@ export default class MuffinAI extends Client { if (msg.author.bot) return new Dokdo(this, { prefix: '멒힌아 ', - noPerm: msg => - msg.reply({ - content: '당신은 내 남자친구가 아니야!', - allowedMentions: { - repliedUser: false, - parse: [], - users: [], - roles: [], - }, - }), + noPerm, aliases: ['테스트'], owners: ['415135882006495242'], }).run(msg) if (msg.content.startsWith('머핀아 ')) this.chatBot.getResponse(msg, true) else if (msg.content.startsWith('멒힌아 봇꺼')) { if (msg.author.id !== '415135882006495242') { - msg.reply({ - content: '당신은 내 남자친구가 아니야!', - allowedMentions: { - repliedUser: false, - parse: [], - users: [], - roles: [], - }, - }) + noPerm(msg) return } this.destroy()