fix: random system

This commit is contained in:
Siwoo Jeon 2023-01-24 21:04:19 +09:00
parent 78cba77b35
commit 28787a8803
Signed by: migan
GPG key ID: C4151385FFD2082A
4 changed files with 14 additions and 30 deletions

View file

@ -5,7 +5,6 @@
"license": "MIT",
"type": "module",
"dependencies": {
"array-shuffle": "^3.0.0",
"discord.js": "^14.7.1",
"dokdo": "^0.6.2",
"dotenv": "^16.0.3",

View file

@ -1,7 +1,5 @@
import sqlite3 from 'sqlite3'
import { ResponseData } from './types.js'
import type { Client, Message } from 'discord.js'
import arrayShuffle from 'array-shuffle'
export default class ChatBot {
private db: sqlite3.Database
@ -10,19 +8,21 @@ export default class ChatBot {
}
public getResponse(msg: Message, sendMsg?: boolean): ChatBot {
this.db.all('SELECT * FROM statement;', [], (err, rows: ResponseData[]) => {
if (err) throw err
const a = msg.content.replace('머핀아', '')
const data = arrayShuffle([...rows])
let r = data[0].text
if (!r) r = '살ㄹ려주세요'
console.log(`⌨️ㅣ${a}`)
console.log(`🍰ㅣ${r}`)
if (sendMsg) {
msg.channel.sendTyping()
setTimeout(() => msg.channel.send(r), 1000)
this.db.all(
'SELECT text FROM statement;',
(err, rows: Array<{ text: string }>) => {
if (err) throw err
const a = msg.content.replace('머핀아', '')
let r = rows[Math.floor(Math.random() * rows.length)].text
if (!r) r = '살ㄹ려주세요'
console.log(`⌨️ ㅣ${a}`)
console.log(`🍰ㅣ${r}`)
if (sendMsg) {
msg.channel.sendTyping()
setTimeout(() => msg.channel.send(r), 1000)
}
}
})
)
return this
}

View file

@ -1,10 +0,0 @@
export interface ResponseData {
id: number
text: string
search_text: string
conversation: string
created_at: string
in_response_to: string | null
search_in_response_to: string
persona: string
}

View file

@ -278,11 +278,6 @@ arg@^4.1.0:
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
array-shuffle@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/array-shuffle/-/array-shuffle-3.0.0.tgz#9a927cc2ca4c8ef4d71cddef7c9ee7b3b733d54b"
integrity sha512-rogEGxHOQPhslOhpg12LJkB+bbAl484/s2AJq0BxtzQDQfKl76fS2u9zWgg3p3b9ENcuvE7K8A7l5ddiPjCRnw==
array-union@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"