feat: turn on/off user train
This commit is contained in:
parent
28787a8803
commit
91537e48eb
2 changed files with 20 additions and 24 deletions
|
@ -26,7 +26,7 @@ export default class ChatBot {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
public train(client: Client): ChatBot {
|
public train(client: Client, user?: boolean): ChatBot {
|
||||||
client.on('messageCreate', msg => {
|
client.on('messageCreate', msg => {
|
||||||
if (msg.author.bot) return
|
if (msg.author.bot) return
|
||||||
if (msg.author.id === '1026185545837191238') {
|
if (msg.author.id === '1026185545837191238') {
|
||||||
|
@ -38,10 +38,11 @@ export default class ChatBot {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
if (!user) return
|
||||||
if (!msg.content.startsWith('머핀아 ')) 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('머핀아 ', '')
|
.replace('머핀아 ', '')
|
||||||
.replaceAll("'", '')}');`
|
.replaceAll("'", '')}', 'user');`
|
||||||
this.db.run(sql, err => {
|
this.db.run(sql, err => {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
})
|
})
|
||||||
|
|
|
@ -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 ChatBot from './ChatBot.js'
|
||||||
import { join, dirname } from 'node:path'
|
import { join, dirname } from 'node:path'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
import Dokdo from 'dokdo'
|
import Dokdo from 'dokdo'
|
||||||
import 'dotenv/config'
|
import 'dotenv/config'
|
||||||
|
|
||||||
|
function noPerm(msg: Message) {
|
||||||
|
msg.reply({
|
||||||
|
content: '당신은 내 남자친구가 아니야!',
|
||||||
|
allowedMentions: {
|
||||||
|
repliedUser: false,
|
||||||
|
parse: [],
|
||||||
|
users: [],
|
||||||
|
roles: [],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default class MuffinAI extends Client {
|
export default class MuffinAI extends Client {
|
||||||
private chatBot = new ChatBot(
|
private chatBot = new ChatBot(
|
||||||
join(dirname(fileURLToPath(import.meta.url)), '..', 'db', 'db.sqlite3')
|
join(dirname(fileURLToPath(import.meta.url)), '..', 'db', 'db.sqlite3')
|
||||||
|
@ -20,7 +32,7 @@ export default class MuffinAI extends Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override login(): Promise<string> {
|
public override login(): Promise<string> {
|
||||||
this.chatBot.train(this)
|
this.chatBot.train(this, true)
|
||||||
this.once('ready', client => {
|
this.once('ready', client => {
|
||||||
client.user!.setActivity({
|
client.user!.setActivity({
|
||||||
type: ActivityType.Playing,
|
type: ActivityType.Playing,
|
||||||
|
@ -31,31 +43,14 @@ export default class MuffinAI extends Client {
|
||||||
if (msg.author.bot) return
|
if (msg.author.bot) return
|
||||||
new Dokdo(this, {
|
new Dokdo(this, {
|
||||||
prefix: '멒힌아 ',
|
prefix: '멒힌아 ',
|
||||||
noPerm: msg =>
|
noPerm,
|
||||||
msg.reply({
|
|
||||||
content: '당신은 내 남자친구가 아니야!',
|
|
||||||
allowedMentions: {
|
|
||||||
repliedUser: false,
|
|
||||||
parse: [],
|
|
||||||
users: [],
|
|
||||||
roles: [],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
aliases: ['테스트'],
|
aliases: ['테스트'],
|
||||||
owners: ['415135882006495242'],
|
owners: ['415135882006495242'],
|
||||||
}).run(msg)
|
}).run(msg)
|
||||||
if (msg.content.startsWith('머핀아 ')) this.chatBot.getResponse(msg, true)
|
if (msg.content.startsWith('머핀아 ')) this.chatBot.getResponse(msg, true)
|
||||||
else if (msg.content.startsWith('멒힌아 봇꺼')) {
|
else if (msg.content.startsWith('멒힌아 봇꺼')) {
|
||||||
if (msg.author.id !== '415135882006495242') {
|
if (msg.author.id !== '415135882006495242') {
|
||||||
msg.reply({
|
noPerm(msg)
|
||||||
content: '당신은 내 남자친구가 아니야!',
|
|
||||||
allowedMentions: {
|
|
||||||
repliedUser: false,
|
|
||||||
parse: [],
|
|
||||||
users: [],
|
|
||||||
roles: [],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.destroy()
|
this.destroy()
|
||||||
|
|
Loading…
Reference in a new issue