fix: array shuffle system
This commit is contained in:
parent
6ff9e2bef0
commit
7280ac7f35
1 changed files with 15 additions and 2 deletions
|
@ -2,6 +2,19 @@ import sqlite3 from 'sqlite3'
|
|||
import { ResponseData } from './types'
|
||||
import { Message } from 'discord.js'
|
||||
|
||||
function arrayShuffle<T>(array: T[]): T[] {
|
||||
array = [...array]
|
||||
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1))
|
||||
const temp = array[i]
|
||||
array[i] = array[j]
|
||||
array[j] = temp
|
||||
}
|
||||
|
||||
return array
|
||||
}
|
||||
|
||||
export default class ChatBot {
|
||||
private db: sqlite3.Database
|
||||
public constructor(dbPath: string) {
|
||||
|
@ -12,8 +25,8 @@ export default class ChatBot {
|
|||
this.db.all('select * from statement', [], (err, rows: ResponseData[]) => {
|
||||
if (err) throw err
|
||||
const a = msg.content.replace('머핀아', '')
|
||||
const data: ResponseData[] = [...rows]
|
||||
data.sort(() => Math.random() - 0.5)
|
||||
const data = arrayShuffle([...rows])
|
||||
console.log(data)
|
||||
let r = data[0].text
|
||||
if (!r) r = '살ㄹ려주세요'
|
||||
console.log(`⌨️ㅣ${a}`)
|
||||
|
|
Loading…
Reference in a new issue