3.0.0-Cake #5

Merged
migan merged 33 commits from release/3.0.0 into main 2024-08-14 14:16:30 +00:00
14 changed files with 7350 additions and 5584 deletions
Showing only changes of commit 1bcd8d92ae - Show all commits

10225
.pnp.cjs generated

File diff suppressed because one or more lines are too long

2566
.pnp.loader.mjs generated

File diff suppressed because it is too large Load diff

1
.prettierrc Normal file
View file

@ -0,0 +1 @@
"@migan/prettier-config"

View file

@ -1,6 +1,3 @@
{ {
"recommendations": [ "recommendations": ["arcanis.vscode-zipfs", "esbenp.prettier-vscode"]
"arcanis.vscode-zipfs",
"esbenp.prettier-vscode"
]
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "muffinbot", "name": "muffinbot",
"version": "2.1.0-oreo.b240618a", "version": "3.0.0-cake.d240619a",
"main": "dist/index.js", "main": "dist/index.js",
"private": true, "private": true,
"dependencies": { "dependencies": {
@ -22,6 +22,5 @@
"dev": "cross-env NODE_ENV=development ts-node src", "dev": "cross-env NODE_ENV=development ts-node src",
"start": "cross-env NODE_ENV=production node dist" "start": "cross-env NODE_ENV=production node dist"
}, },
"packageManager": "yarn@4.2.2", "packageManager": "yarn@4.2.2"
"prettier": "@migan/prettier-config"
} }

View file

@ -1,33 +1,24 @@
import { import { ActivityType, Client, Collection, GatewayIntentBits } from 'discord.js'
ActivityType, import { type Command, noPerm, ChatBot, NODE_ENV, MaaDatabase } from './modules'
Client,
Collection,
GatewayIntentBits,
TextChannel,
} from 'discord.js'
import { type Command, noPerm, ChatBot, NODE_ENV } from './modules'
import { readdirSync } from 'node:fs' import { readdirSync } from 'node:fs'
import { join } from 'node:path'
import config from '../config.json' import config from '../config.json'
import { join } from 'node:path'
import Dokdo from 'dokdo' import Dokdo from 'dokdo'
const prefix = '머핀아 ' const prefix = '머핀아 '
export default class MuffinBot extends Client { export default class MuffinBot extends Client {
#modules: Collection<string, Command> = new Collection() public modules: Collection<string, Command> = new Collection()
get chatBot() { public database = new MaaDatabase()
return new ChatBot() public chatBot = new ChatBot(this.database)
} public prefix = prefix
get modules(): Collection<string, Command> {
return this.#modules
}
public dokdo: Dokdo = new Dokdo(this, { public dokdo: Dokdo = new Dokdo(this, {
aliases: ['dokdo', 'dok'], aliases: ['dokdo', 'dok'],
owners: [config.bot.owner_ID], owners: [config.bot.owner_ID],
noPerm, noPerm,
prefix, prefix,
}) })
public prefix = prefix
public constructor() { public constructor() {
super({ super({
intents: [ intents: [
@ -94,8 +85,8 @@ 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>
dokdo: Dokdo dokdo: Dokdo
prefix: string prefix: string
} }

View file

@ -7,12 +7,12 @@ export default class extends Command {
} }
public async execute(msg: Message, args: string[]) { public async execute(msg: Message, args: string[]) {
if (!args[0]) { if (!args[0]) {
return await msg.channel.send('```머핀아 삭제 (지울 단어)```') return await msg.channel.send('사용법: \n```머핀아 삭제 (지울 단어)```')
} }
const command = args[0] const command = args[0]
const db = msg.client.chatBot.db const db = msg.client.chatBot.db
const [data] = await db.learn.execute<LearnData[]>( const [data] = await db.execute<LearnData[]>(
'SELECT * FROM learn WHERE command = ? AND user_id = ?;', 'SELECT * FROM learn WHERE command = ? AND user_id = ?;',
[command, msg.author.id], [command, msg.author.id],
) )
@ -29,7 +29,7 @@ export default class extends Command {
console.log('a') console.log('a')
} else { } else {
// await db.learn.delete(command) // await db.learn.delete(command)
// await msg.reply('어라 이제 그ㄱ게 기억이 안나요. 뭐ㅇ였죠?') // await msg.reply('어라 이제 그ㄱ게 기억이 안나요. 그게 뭐ㅇ였죠?')
console.log('b') console.log('b')
} }

View file

@ -10,13 +10,16 @@ export default class extends Command {
const data = await db.statement.all() const data = await db.statement.all()
const nsfwData = await db.nsfwContent.all() const nsfwData = await db.nsfwContent.all()
const learnData = await db.learn.all() const learnData = await db.learn.all()
const userData = await db.learn.findOneAnotherKey('user_id', msg.author.id)
const muffin: ResponseData[] = [] const muffin: ResponseData[] = []
data.forEach(row => { data.forEach(row => {
if (row.persona === 'muffin') muffin.push(row) if (row.persona === 'muffin') muffin.push(row)
else return else return
}) })
await msg.reply(
`머핀 데이터: ${muffin.length}\nnsfw 데이터: ${nsfwData.length}\n지금까지 배운 단어: ${learnData.length}`, await msg.reply(`머핀 데이터: ${muffin.length}
) nsfw 데이터: ${nsfwData.length}
단어: ${learnData.length}
${msg.author.username} 단어: ${userData.length}`)
} }
} }

View file

@ -1,15 +1,15 @@
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 '.'
import learn from '../Commands/learn'
import learning_data from '../Commands/learning_data'
export default class ChatBot { export default class ChatBot {
get db() { public constructor(public db: MaaDatabase) {
return new MaaDatabase() setInterval(async () => {
this.db.ping()
}, 60000)
} }
public async getResponse(msg: Message): Promise<string> { public async getResponse(msg: Message): Promise<string> {
const prefix = msg.client.prefix const prefix = msg.client.prefix
const data = await this.db.statement.all() const data = await this.db.statement.all()
@ -64,10 +64,6 @@ export default class ChatBot {
}) })
} }
}) })
setInterval(async () => {
await this.db.ping()
}, 60000)
return this return this
} }
} }

View file

@ -1,6 +1,7 @@
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({
@ -8,23 +9,24 @@ export class MaaDatabase {
keepAliveInitialDelay: 10000, keepAliveInitialDelay: 10000,
enableKeepAlive: true, enableKeepAlive: true,
}) })
public statement = new StatementTable(this._database)
public nsfwContent = new NSFWContentTable(this._database)
public learn = new LearnTable(this._database)
public get statement() { public ping() {
return new StatementTable(this._database)
}
public get nsfwContent() {
return new NSFWContentTable(this._database)
}
public get learn() {
return new LearnTable(this._database)
}
public async ping() {
this._database.getConnection().then(conn => { this._database.getConnection().then(conn => {
conn.ping() conn.ping()
conn.release() conn.release()
}) })
} }
public async execute<T>(sql: string, values?: any): Promise<T> {
const db = await this._database.getConnection()
let data: any
await run(db, async () => {
data = await db.execute(sql, [...values])
})
return data
}
} }

View file

@ -1,7 +1,7 @@
import { type Pool } from 'mysql2/promise'
import run from '../run'
import type { BaseTable, LearnData } from '../type' import type { BaseTable, LearnData } from '../type'
import { type Pool } from 'mysql2/promise'
import { Snowflake } from 'discord.js' import { Snowflake } from 'discord.js'
import run from '../run'
export class LearnTable implements BaseTable<LearnData, string> { export class LearnTable implements BaseTable<LearnData, string> {
public name = 'learn' public name = 'learn'
@ -69,14 +69,4 @@ export class LearnTable implements BaseTable<LearnData, string> {
) )
return rows return rows
} }
public async execute<W>(sql: string, values?: any): Promise<W> {
const db = await this._database.getConnection()
let data: any
await run(db, async () => {
data = await db.execute(sql, [...values])
})
return data
}
} }

View file

@ -1,9 +1,10 @@
import type { BaseTable, NSFWData } from '../type'
import { type Pool } from 'mysql2/promise' import { type Pool } from 'mysql2/promise'
import run from '../run' import run from '../run'
import type { BaseTable, NSFWData } from '../type'
export class NSFWContentTable implements BaseTable<NSFWData, number> { export class NSFWContentTable implements BaseTable<NSFWData, number> {
public name = 'nsfw_content' public name = 'nsfw_content'
public constructor(private _database: Pool) {} public constructor(private _database: Pool) {}
public async all(): Promise<NSFWData[]> { public async all(): Promise<NSFWData[]> {
@ -56,19 +57,11 @@ export class NSFWContentTable implements BaseTable<NSFWData, number> {
data: any, data: any,
): Promise<NSFWData[]> { ): Promise<NSFWData[]> {
const [rows] = await this._database.execute<NSFWData[]>( const [rows] = await this._database.execute<NSFWData[]>(
`SELECT * FROM nsfw_content WHERE ${key} = ?;`, `SELECT *
FROM nsfw_content
WHERE ${key} = ?;`,
[data], [data],
) )
return rows return rows
} }
public async execute<W>(sql: string, values?: any): Promise<W> {
const db = await this._database.getConnection()
let data: any
await run(db, async () => {
data = await db.execute(sql, [...values])
})
return data
}
} }

View file

@ -1,6 +1,6 @@
import type { BaseTable, ResponseData } from '../type'
import { type Pool } from 'mysql2/promise' import { type Pool } from 'mysql2/promise'
import run from '../run' import run from '../run'
import type { BaseTable, ResponseData } from '../type'
export class StatementTable implements BaseTable<ResponseData, number> { export class StatementTable implements BaseTable<ResponseData, number> {
public name = 'statement' public name = 'statement'
@ -73,14 +73,4 @@ export class StatementTable implements BaseTable<ResponseData, number> {
) )
return rows return rows
} }
public async execute<W>(sql: string, values?: any): Promise<W> {
const db = await this._database.getConnection()
let data: any
await run(db, async () => {
data = await db.execute(sql, [...values])
})
return data
}
} }

View file

@ -33,5 +33,4 @@ export interface BaseTable<T, V> {
update(data: any): Promise<void> update(data: any): Promise<void>
delete(key: V): Promise<void> delete(key: V): Promise<void>
findOneAnotherKey(key: string, data: any): Promise<T[]> findOneAnotherKey(key: string, data: any): Promise<T[]>
execute<W>(sql: string, values?: any): Promise<W>
} }