.
This commit is contained in:
parent
81dc4367aa
commit
011467782d
5 changed files with 36 additions and 37 deletions
|
@ -2,4 +2,5 @@ DISCORD_TOKEN='BOT_TOKEN'
|
|||
MYSQL_USER='MYSQL_USER'
|
||||
MYSQL_HOST='MYSQL_HOST'
|
||||
MYSQL_PASSWORD='MYSQL_PASSWORD'
|
||||
MYSQL_DATABASE='MYSQL_DATABASE'
|
||||
MYSQL_DATABASE='MYSQL_DATABASE'
|
||||
MYSQL_PORT='MYSQL_PORT'
|
|
@ -35,8 +35,8 @@ export default class MuffinAI extends Client {
|
|||
this.#modules.set(b.name, b)
|
||||
})
|
||||
|
||||
this.once('ready', client => {
|
||||
client.user!.setActivity({
|
||||
this.once('ready', () => {
|
||||
this.user!.setActivity({
|
||||
type: ActivityType.Playing,
|
||||
name: 'ㅅ살려주세요..!',
|
||||
})
|
||||
|
|
|
@ -7,16 +7,13 @@ export default class extends Command {
|
|||
}
|
||||
public async execute(msg: Message, args: string[]) {
|
||||
const conn = await database.getConnection()
|
||||
await conn
|
||||
.query('SELECT * FROM statement;') //
|
||||
.then(rows => {
|
||||
const muffin: ResponseData[] = []
|
||||
;(rows[0] as ResponseData[]).forEach(row => {
|
||||
if (row.persona === 'muffin') muffin.push(row)
|
||||
else return
|
||||
})
|
||||
msg.channel.send(`머핀 데이터: ${muffin.length}개`)
|
||||
})
|
||||
const [rows] = await conn.query('SELECT * FROM statement;')
|
||||
const muffin: ResponseData[] = []
|
||||
;(rows as ResponseData[]).forEach(row => {
|
||||
if (row.persona === 'muffin') muffin.push(row)
|
||||
else return
|
||||
})
|
||||
msg.channel.send(`머핀 데이터: ${muffin.length}개`)
|
||||
conn.release()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,39 +5,39 @@ export default class ChatBot {
|
|||
public async getResponse(msg: Message): Promise<string> {
|
||||
const conn = await database.getConnection()
|
||||
const request = msg.content.replace('머핀아 ', '')
|
||||
const result = await conn.query('SELECT * FROM statement;')
|
||||
const rows = result[0] as ResponseData[]
|
||||
let response = rows[Math.floor(Math.random() * rows.length)].text
|
||||
if (!response) response = '살ㄹ려주세요'
|
||||
console.log(`⌨️ㅣ${request}`)
|
||||
const [rows] = await conn.query('SELECT * FROM statement;')
|
||||
let response = (rows as ResponseData[])[
|
||||
Math.floor(Math.random() * (rows as ResponseData[]).length)
|
||||
].text
|
||||
if (!response) response = '살ㄹ려주세요'
|
||||
|
||||
console.log(`🍰ㅣ${response}`)
|
||||
conn.release()
|
||||
return response
|
||||
}
|
||||
|
||||
public async train(client: Client): Promise<ChatBot> {
|
||||
const conn = await database.getConnection()
|
||||
client.on('messageCreate', msg => {
|
||||
client.on('messageCreate', async msg => {
|
||||
const conn = await database.getConnection()
|
||||
if (msg.author.bot) return
|
||||
if (msg.author.id !== '1026185545837191238') return
|
||||
this.getResponse(msg) //
|
||||
.then(async response => {
|
||||
const result = await conn.query('SELECT * FROM statement;')
|
||||
const rows = result[0] as ResponseData[]
|
||||
try {
|
||||
await conn.beginTransaction()
|
||||
await conn.execute(
|
||||
`INSERT INTO statement(id, text, persona, in_response_to) VALUES(?, ?, ?, ?);`,
|
||||
[++rows[rows.length - 1].id, msg.content, 'muffin', response]
|
||||
)
|
||||
await conn.commit()
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
await conn.rollback()
|
||||
} finally {
|
||||
conn.release()
|
||||
}
|
||||
})
|
||||
const response = this.getResponse(msg)
|
||||
const result = await conn.query('SELECT * FROM statement;')
|
||||
const rows = result[0] as ResponseData[]
|
||||
await conn.beginTransaction()
|
||||
try {
|
||||
await conn.execute(
|
||||
`INSERT INTO statement(id, text, persona, in_response_to) VALUES(?, ?, ?, ?);`,
|
||||
[++rows[rows.length - 1].id, msg.content, 'muffin', response]
|
||||
)
|
||||
await conn.commit()
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
await conn.rollback()
|
||||
} finally {
|
||||
conn.release()
|
||||
}
|
||||
})
|
||||
return this
|
||||
}
|
||||
|
|
|
@ -17,4 +17,5 @@ export default createPool({
|
|||
user: process.env.MYSQL_USER,
|
||||
password: process.env.MYSQL_PASSWORD,
|
||||
database: process.env.MYSQL_DATABASE,
|
||||
port: (process.env.MYSQL_PORT as unknown as number) || 3306,
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue