.
This commit is contained in:
parent
56b3841592
commit
f19e307109
4 changed files with 25 additions and 34 deletions
|
@ -1,4 +1,10 @@
|
|||
import { ActivityType, Client, Collection, GatewayIntentBits } from 'discord.js'
|
||||
import {
|
||||
ActivityType,
|
||||
Client,
|
||||
Collection,
|
||||
GatewayIntentBits,
|
||||
TextChannel,
|
||||
} from 'discord.js'
|
||||
import { Command, noPerm, ChatBot } from './modules'
|
||||
import Dokdo from 'dokdo'
|
||||
import { readdirSync } from 'node:fs'
|
||||
|
@ -9,7 +15,7 @@ const prefix = '멒힌아 '
|
|||
|
||||
export default class MuffinAI extends Client {
|
||||
public chatBot = new ChatBot()
|
||||
private modules: Collection<string, Command> = new Collection()
|
||||
#modules: Collection<string, Command> = new Collection()
|
||||
public constructor() {
|
||||
super({
|
||||
intents: [
|
||||
|
@ -26,7 +32,7 @@ export default class MuffinAI extends Client {
|
|||
readdirSync(join(__dirname, 'Commands')).forEach(file => {
|
||||
const a = require(join(__dirname, 'Commands', file))
|
||||
const b: Command = new a.default()
|
||||
this.modules.set(b.name, b)
|
||||
this.#modules.set(b.name, b)
|
||||
})
|
||||
|
||||
this.once('ready', client => {
|
||||
|
@ -44,18 +50,21 @@ export default class MuffinAI extends Client {
|
|||
owners: ['415135882006495242'],
|
||||
}).run(msg)
|
||||
if (msg.content.startsWith('머핀아 ')) {
|
||||
msg.channel.sendTyping()
|
||||
setTimeout(
|
||||
async () => msg.channel.send(await this.chatBot.getResponse(msg)),
|
||||
1000
|
||||
)
|
||||
if (msg.channel instanceof TextChannel) {
|
||||
if (msg.channel.nsfw) return
|
||||
await msg.channel.sendTyping()
|
||||
setTimeout(
|
||||
async () => msg.channel.send(await this.chatBot.getResponse(msg)),
|
||||
1000
|
||||
)
|
||||
}
|
||||
} else if (msg.content.startsWith(prefix)) {
|
||||
const args: string[] = msg.content
|
||||
.slice(prefix.length)
|
||||
.trim()
|
||||
.split('/ +/g')
|
||||
|
||||
const command = this.modules.get(args.toString())
|
||||
const command = this.#modules.get(args.toString())
|
||||
if (!command) return
|
||||
if (command.noPerm && msg.author.id !== '415135882006495242')
|
||||
return await noPerm(msg)
|
||||
|
|
|
@ -4,15 +4,7 @@ import Database from './Database'
|
|||
type TrainType = 'muffinOnly' | 'All'
|
||||
|
||||
export default class ChatBot {
|
||||
get trainType(): TrainType {
|
||||
return this._trainType
|
||||
}
|
||||
|
||||
set trainType(value: TrainType) {
|
||||
this._trainType = value
|
||||
}
|
||||
public db = new Database(process.env.DB_PATH!)
|
||||
private _trainType: TrainType = 'muffinOnly'
|
||||
|
||||
public async getResponse(msg: Message): Promise<string> {
|
||||
const request = msg.content.replace('머핀아 ', '')
|
||||
|
@ -21,16 +13,6 @@ export default class ChatBot {
|
|||
if (!response) response = '살ㄹ려주세요'
|
||||
console.log(`⌨️ㅣ${request}`)
|
||||
console.log(`🍰ㅣ${response}`)
|
||||
// .then(rows => {
|
||||
// const request = msg.content.replace('머핀아 ', '')
|
||||
// response = rows[Math.floor(Math.random() * rows.length)].text
|
||||
// if (!response) response = '살ㄹ려주세요'
|
||||
// if (sendMsg) {
|
||||
// msg.channel.sendTyping()
|
||||
// setTimeout(() => msg.channel.send(response), 1000)
|
||||
// }
|
||||
// })
|
||||
// .catch(console.error)
|
||||
return response
|
||||
}
|
||||
|
||||
|
|
|
@ -12,16 +12,16 @@ interface ResponseData {
|
|||
}
|
||||
|
||||
export default class Database {
|
||||
private sqliteDB: sqlite3.Database
|
||||
#sqliteDB: sqlite3.Database
|
||||
public constructor(dbPath: string) {
|
||||
const a = sqlite3.verbose()
|
||||
this.sqliteDB = new a.Database(dbPath)
|
||||
this.#sqliteDB = new a.Database(dbPath)
|
||||
}
|
||||
|
||||
public all(): Promise<ResponseData[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.sqliteDB.serialize(() => {
|
||||
this.sqliteDB.all('SELECT * FROM statement;', (err, rows) => {
|
||||
this.#sqliteDB.serialize(() => {
|
||||
this.#sqliteDB.all('SELECT * FROM statement;', (err, rows) => {
|
||||
if (err) reject(err)
|
||||
resolve([...rows])
|
||||
})
|
||||
|
@ -34,10 +34,10 @@ export default class Database {
|
|||
params: any[],
|
||||
callBack: (err: Error | null) => void
|
||||
) {
|
||||
this.sqliteDB.run(sql, params, callBack)
|
||||
this.#sqliteDB.run(sql, params, callBack)
|
||||
}
|
||||
|
||||
public close() {
|
||||
this.sqliteDB.close()
|
||||
this.#sqliteDB.close()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2021",
|
||||
"target": "es2022",
|
||||
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
|
|
Loading…
Reference in a new issue