edit: db path

This commit is contained in:
Siwoo Jeon 2023-01-31 18:05:27 +09:00
parent 7250a6ddb5
commit 8d1b44a82a
Signed by: migan
GPG key ID: C4151385FFD2082A
2 changed files with 6 additions and 5 deletions

2
example.env Normal file
View file

@ -0,0 +1,2 @@
DISCORD_TOKEN='BOT_TOKEN'
DB_PATH='DB_PATH'

View file

@ -1,5 +1,5 @@
import type { Client, Message } from 'discord.js' import type { Client, Message } from 'discord.js'
import { join } from 'node:path' // import { join } from 'node:path'
import Database from './Database' import Database from './Database'
type TrainType = 'muffinOnly' | 'All' type TrainType = 'muffinOnly' | 'All'
@ -12,18 +12,17 @@ export default class ChatBot {
set trainType(value: TrainType) { set trainType(value: TrainType) {
this._trainType = value this._trainType = value
} }
public db = new Database(join(__dirname, '..', 'db', 'db.sqlite3')) public db = new Database(process.env.DB_PATH!)
private _trainType: TrainType = 'All' private _trainType: TrainType = 'All'
public constructor() {}
public getResponse(msg: Message, sendMsg?: boolean): ChatBot { public getResponse(msg: Message, sendMsg?: boolean): ChatBot {
this.db this.db
.all() .all()
.then(rows => { .then(rows => {
const a = msg.content.replace('머핀아', '') const a = msg.content.replace('머핀아 ', '')
let r = rows[Math.floor(Math.random() * rows.length)].text let r = rows[Math.floor(Math.random() * rows.length)].text
if (!r) r = '살ㄹ려주세요' if (!r) r = '살ㄹ려주세요'
console.log(`⌨️ ${a}`) console.log(`⌨️${a}`)
console.log(`🍰ㅣ${r}`) console.log(`🍰ㅣ${r}`)
if (sendMsg) { if (sendMsg) {
msg.channel.sendTyping() msg.channel.sendTyping()