fix: random system
This commit is contained in:
parent
78cba77b35
commit
28787a8803
4 changed files with 14 additions and 30 deletions
|
@ -5,7 +5,6 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"array-shuffle": "^3.0.0",
|
|
||||||
"discord.js": "^14.7.1",
|
"discord.js": "^14.7.1",
|
||||||
"dokdo": "^0.6.2",
|
"dokdo": "^0.6.2",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import sqlite3 from 'sqlite3'
|
import sqlite3 from 'sqlite3'
|
||||||
import { ResponseData } from './types.js'
|
|
||||||
import type { Client, Message } from 'discord.js'
|
import type { Client, Message } from 'discord.js'
|
||||||
import arrayShuffle from 'array-shuffle'
|
|
||||||
|
|
||||||
export default class ChatBot {
|
export default class ChatBot {
|
||||||
private db: sqlite3.Database
|
private db: sqlite3.Database
|
||||||
|
@ -10,19 +8,21 @@ export default class ChatBot {
|
||||||
}
|
}
|
||||||
|
|
||||||
public getResponse(msg: Message, sendMsg?: boolean): ChatBot {
|
public getResponse(msg: Message, sendMsg?: boolean): ChatBot {
|
||||||
this.db.all('SELECT * FROM statement;', [], (err, rows: ResponseData[]) => {
|
this.db.all(
|
||||||
if (err) throw err
|
'SELECT text FROM statement;',
|
||||||
const a = msg.content.replace('머핀아', '')
|
(err, rows: Array<{ text: string }>) => {
|
||||||
const data = arrayShuffle([...rows])
|
if (err) throw err
|
||||||
let r = data[0].text
|
const a = msg.content.replace('머핀아', '')
|
||||||
if (!r) r = '살ㄹ려주세요'
|
let r = rows[Math.floor(Math.random() * rows.length)].text
|
||||||
console.log(`⌨️ㅣ${a}`)
|
if (!r) r = '살ㄹ려주세요'
|
||||||
console.log(`🍰ㅣ${r}`)
|
console.log(`⌨️ ㅣ${a}`)
|
||||||
if (sendMsg) {
|
console.log(`🍰ㅣ${r}`)
|
||||||
msg.channel.sendTyping()
|
if (sendMsg) {
|
||||||
setTimeout(() => msg.channel.send(r), 1000)
|
msg.channel.sendTyping()
|
||||||
|
setTimeout(() => msg.channel.send(r), 1000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/types.ts
10
src/types.ts
|
@ -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
|
|
||||||
}
|
|
|
@ -278,11 +278,6 @@ arg@^4.1.0:
|
||||||
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
|
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
|
||||||
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
|
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:
|
array-union@^2.1.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
|
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
|
||||||
|
|
Loading…
Reference in a new issue