feat: turn on/off user train

This commit is contained in:
Siwoo Jeon 2023-01-25 14:42:09 +09:00
parent 28787a8803
commit 91537e48eb
Signed by: migan
GPG key ID: C4151385FFD2082A
2 changed files with 20 additions and 24 deletions

View file

@ -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
})

View file

@ -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<string> {
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()