feat: Can learn duplicate

This commit is contained in:
Siwoo Jeon 2024-06-11 21:11:09 +09:00
parent ba2fd54e6d
commit 54688e1db6
Signed by: migan
GPG key ID: C4151385FFD2082A
3 changed files with 18 additions and 18 deletions

View file

@ -1,6 +1,6 @@
{
"name": "muffinbot",
"version": "2.1.0-oreo.d240609a",
"version": "2.1.0-oreo.b240611a",
"main": "dist/index.js",
"private": true,
"dependencies": {

View file

@ -30,15 +30,15 @@ export default class extends Command {
const db = msg.client.chatBot.db
const data = await db.learn.findOne(command)
if (data[0]) {
if (msg.author.id !== data[0].user_id) {
return msg.channel.send(
`해ㄷ당 단어는 이미 ${
(await msg.client.users.fetch(data[0].user_id)).username
} .`,
)
}
}
// if (data[0]) {
// if (msg.author.id !== data[0].user_id) {
// return msg.channel.send(
// `해ㄷ당 단어는 이미 ${
// (await msg.client.users.fetch(data[0].user_id)).username
// }님에게서 배웠어요.`,
// )
// }
// }
for (const ig of ignore) {
if (command.includes(ig)) {

View file

@ -3,6 +3,8 @@ import { MaaDatabase } from './database'
import { TextChannel } from 'discord.js'
import config from '../../config.json'
import { NODE_ENV } from '.'
import learn from '../Commands/learn'
import learning_data from '../Commands/learning_data'
export default class ChatBot {
get db() {
@ -12,21 +14,19 @@ export default class ChatBot {
const prefix = msg.client.prefix
const data = await this.db.statement.all()
const args = msg.content.slice(prefix.length).trim().split(/ +/g).join(' ')
const learnData = await this.db.learn.findOne(args)
const learn = await this.db.learn.findOne(args)
const learnData = learn[Math.floor(Math.random() * learn.length)]
const randomNumber = Math.round(Math.random() * (2 - 1) + 1)
if (NODE_ENV === 'development') {
console.log(randomNumber)
console.log(learnData)
console.log(args)
}
if (
randomNumber === 1 &&
learnData[0] &&
args.startsWith(learnData[0].command)
) {
return `${learnData[0].result}\n\`${
(await msg.client.users.fetch(learnData[0].user_id)).username
if (randomNumber === 1 && learnData && args.startsWith(learnData.command)) {
return `${learnData.result}\n\`${
(await msg.client.users.fetch(learnData.user_id)).username
} .\``
}