.
This commit is contained in:
parent
15bae86915
commit
e50a348686
2 changed files with 50 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { Command } from '../modules'
|
import { Command, LearnData } from '../modules'
|
||||||
import { Message } from 'discord.js'
|
import { Message } from 'discord.js'
|
||||||
|
|
||||||
export default class extends Command {
|
export default class extends Command {
|
||||||
|
@ -20,26 +20,50 @@ export default class extends Command {
|
||||||
]
|
]
|
||||||
const disallowed = ['@everyone', '@here']
|
const disallowed = ['@everyone', '@here']
|
||||||
const db = await msg.client.chatBot.db.getConnection()
|
const db = await msg.client.chatBot.db.getConnection()
|
||||||
|
const [learn] = await db.execute<LearnData[]>(
|
||||||
|
'SELECT * FROM learn WHERE command = ?;',
|
||||||
|
[command],
|
||||||
|
)
|
||||||
|
|
||||||
ignore.forEach(ig => {
|
if (learn[0]) {
|
||||||
if (result.includes(ig)) {
|
if (msg.author.id !== learn[0].user_id) {
|
||||||
|
return msg.channel.send(
|
||||||
|
`해ㄷ당 단어는 이미 ${
|
||||||
|
(await msg.client.users.fetch(learn[0].user_id)).username
|
||||||
|
}님에게서 배웠어요.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const ig of ignore) {
|
||||||
|
if (command.includes(ig)) {
|
||||||
return msg.channel.send('해ㄷ당 단어는 배울ㄹ 수 없어요.')
|
return msg.channel.send('해ㄷ당 단어는 배울ㄹ 수 없어요.')
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
disallowed.forEach(di => {
|
for (const di of disallowed) {
|
||||||
if (result.includes(di)) {
|
if (result.includes(di)) {
|
||||||
return msg.channel.send('해당 단ㅇ어는 금지되어 있ㅅ어요.')
|
return msg.channel.send('해당 단ㅇ어는 금지되어 있ㅅ어요.')
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await db.beginTransaction()
|
await db.beginTransaction()
|
||||||
db.execute(
|
|
||||||
'INSERT INTO learn (command, result, user_id) VALUES (?, ?, ?);',
|
if (learn[0] && msg.author.id === learn[0].user_id) {
|
||||||
[command, result, msg.author.id],
|
await db.execute('UPDATE learn SET result = ? WHERE command = ?;', [
|
||||||
)
|
result,
|
||||||
await msg.channel.send(`${command}을/를 배웠ㅇ어요.`)
|
command,
|
||||||
|
])
|
||||||
|
await msg.channel.send(`${command}을/를 다시 배ㅂ웠어요.`)
|
||||||
|
} else {
|
||||||
|
await db.execute(
|
||||||
|
'INSERT INTO learn (command, result, user_id) VALUES (?, ?, ?);',
|
||||||
|
[command, result, msg.author.id],
|
||||||
|
)
|
||||||
|
await msg.channel.send(`${command}을/를 배웠ㅇ어요.`)
|
||||||
|
}
|
||||||
|
|
||||||
await db.commit()
|
await db.commit()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|
|
@ -12,8 +12,15 @@ export default class ChatBot {
|
||||||
public async getResponse(msg: Message): Promise<string> {
|
public async getResponse(msg: Message): Promise<string> {
|
||||||
const db = await this.db.getConnection()
|
const db = await this.db.getConnection()
|
||||||
const [rows] = await db.execute<ResponseData[]>('SELECT * FROM statement;')
|
const [rows] = await db.execute<ResponseData[]>('SELECT * FROM statement;')
|
||||||
const args = msg.content.slice('머핀아 '.length).trim().split(/ +/g)
|
const args = msg.content
|
||||||
const [learn] = await db.execute<LearnData[]>('SELECT * from learn;')
|
.slice('머핀아 '.length)
|
||||||
|
.trim()
|
||||||
|
.split(/ +/g)
|
||||||
|
.join(' ')
|
||||||
|
const [learn] = await db.execute<LearnData[]>(
|
||||||
|
'SELECT * from learn WHERE command = ?;',
|
||||||
|
[args],
|
||||||
|
)
|
||||||
const a = Math.round(Math.random() * (2 - 1) + 1)
|
const a = Math.round(Math.random() * (2 - 1) + 1)
|
||||||
|
|
||||||
if (NODE_ENV === 'development') {
|
if (NODE_ENV === 'development') {
|
||||||
|
@ -22,9 +29,13 @@ export default class ChatBot {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a === 1) {
|
if (a === 1) {
|
||||||
if (args[0].startsWith(learn[0].command)) {
|
if (learn[0]) {
|
||||||
return `${learn[0].command}\n\`${(await msg.client.users.fetch(msg.author.id)).username}님이 알려주셨어요.\``
|
if (args.startsWith(learn[0].command)) {
|
||||||
|
return `${learn[0].result}\n\`${
|
||||||
|
(await msg.client.users.fetch(learn[0].user_id)).username
|
||||||
|
}님이 알려주셨어요.\``
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let response: string
|
let response: string
|
||||||
|
|
Loading…
Reference in a new issue