fix: Too Many Connections
This commit is contained in:
parent
25262ada9f
commit
c107f1d7d9
4 changed files with 25 additions and 37 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "muffinbot",
|
"name": "muffinbot",
|
||||||
"version": "2.0.0-oreo.r240616b",
|
"version": "2.0.0-oreo.r240618a",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -14,22 +14,14 @@ import Dokdo from 'dokdo'
|
||||||
const prefix = '머핀아 '
|
const prefix = '머핀아 '
|
||||||
|
|
||||||
export default class MuffinBot extends Client {
|
export default class MuffinBot extends Client {
|
||||||
get chatBot() {
|
public chatBot = new ChatBot()
|
||||||
return new ChatBot()
|
public dokdo = new Dokdo(this, {
|
||||||
}
|
aliases: ['dokdo', 'dok'],
|
||||||
|
owners: [config.bot.owner_ID],
|
||||||
get dokdo() {
|
noPerm,
|
||||||
return new Dokdo(this, {
|
prefix,
|
||||||
aliases: ['dokdo', 'dok'],
|
})
|
||||||
owners: [config.bot.owner_ID],
|
public modules: Collection<string, Command> = new Collection()
|
||||||
noPerm,
|
|
||||||
prefix,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
get modules(): Collection<string, Command> {
|
|
||||||
return this.#modules
|
|
||||||
}
|
|
||||||
#modules: Collection<string, Command> = new Collection()
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super({
|
super({
|
||||||
intents: [
|
intents: [
|
||||||
|
@ -98,7 +90,7 @@ export default class MuffinBot extends Client {
|
||||||
|
|
||||||
declare module 'discord.js' {
|
declare module 'discord.js' {
|
||||||
interface Client {
|
interface Client {
|
||||||
get chatBot(): ChatBot
|
chatBot: ChatBot
|
||||||
get modules(): Collection<string, Command>
|
modules: Collection<string, Command>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import type { Client, Message } from 'discord.js'
|
import type { Client, Message, TextChannel } from 'discord.js'
|
||||||
import { MaaDatabase } from './database'
|
import { MaaDatabase } from './database'
|
||||||
import { TextChannel } from 'discord.js'
|
|
||||||
import config from '../../config.json'
|
import config from '../../config.json'
|
||||||
import { NODE_ENV } from '.'
|
import { NODE_ENV } from '.'
|
||||||
|
|
||||||
export default class ChatBot {
|
export default class ChatBot {
|
||||||
get db() {
|
public db = new MaaDatabase()
|
||||||
return new MaaDatabase()
|
|
||||||
}
|
|
||||||
public async getResponse(msg: Message): Promise<string> {
|
public async getResponse(msg: Message): Promise<string> {
|
||||||
const data = await this.db.statement.all()
|
const data = await this.db.statement.all()
|
||||||
const args = msg.content
|
const args = msg.content
|
||||||
|
|
|
@ -1,27 +1,25 @@
|
||||||
import { createPool } from 'mysql2/promise'
|
import { createPool } from 'mysql2/promise'
|
||||||
import { LearnTable, NSFWContentTable, StatementTable } from './model'
|
import { LearnTable, NSFWContentTable, StatementTable } from './model'
|
||||||
import config from '../../../config.json'
|
import config from '../../../config.json'
|
||||||
|
import run from './run'
|
||||||
|
|
||||||
export class MaaDatabase {
|
export class MaaDatabase {
|
||||||
private _database = createPool({
|
private _database = createPool({
|
||||||
...config.mysql,
|
...config.mysql,
|
||||||
keepAliveInitialDelay: 10000,
|
keepAliveInitialDelay: 10000,
|
||||||
enableKeepAlive: true,
|
enableKeepAlive: true,
|
||||||
|
}).on('release', conn => {
|
||||||
|
console.log(`${conn.threadId} released.`)
|
||||||
})
|
})
|
||||||
|
public statement = new StatementTable(this._database)
|
||||||
public get statement() {
|
public nsfwContent = new NSFWContentTable(this._database)
|
||||||
return new StatementTable(this._database)
|
public learn = new LearnTable(this._database)
|
||||||
}
|
|
||||||
|
|
||||||
public get nsfwContent() {
|
|
||||||
return new NSFWContentTable(this._database)
|
|
||||||
}
|
|
||||||
|
|
||||||
public get learn() {
|
|
||||||
return new LearnTable(this._database)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ping() {
|
public async ping() {
|
||||||
this._database.ping()
|
const db = await this._database.getConnection()
|
||||||
|
|
||||||
|
await run(db, async () => {
|
||||||
|
await db.ping()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue