From 28787a8803fea7ac6513483745d348a2d6ef44ad Mon Sep 17 00:00:00 2001 From: Migan178 Date: Tue, 24 Jan 2023 21:04:19 +0900 Subject: [PATCH] fix: random system --- package.json | 1 - src/ChatBot.ts | 28 ++++++++++++++-------------- src/types.ts | 10 ---------- yarn.lock | 5 ----- 4 files changed, 14 insertions(+), 30 deletions(-) delete mode 100644 src/types.ts diff --git a/package.json b/package.json index 6f9a699..cccfb3e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/ChatBot.ts b/src/ChatBot.ts index 3ecfa0d..ba6f158 100644 --- a/src/ChatBot.ts +++ b/src/ChatBot.ts @@ -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 } diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index e0bcf4e..0000000 --- a/src/types.ts +++ /dev/null @@ -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 -} diff --git a/yarn.lock b/yarn.lock index 0f72791..1af0e43 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"