feat: 학습데이터량 add user data

This commit is contained in:
Siwoo Jeon 2024-06-19 19:03:24 +09:00
parent 38810a3f1b
commit 1bcd8d92ae
Signed by: migan
GPG key ID: C4151385FFD2082A
14 changed files with 7350 additions and 5584 deletions

9503
.pnp.cjs generated

File diff suppressed because one or more lines are too long

2546
.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": [
"arcanis.vscode-zipfs",
"esbenp.prettier-vscode"
]
"recommendations": ["arcanis.vscode-zipfs", "esbenp.prettier-vscode"]
}

View file

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

View file

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

View file

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

View file

@ -10,13 +10,16 @@ export default class extends Command {
const data = await db.statement.all()
const nsfwData = await db.nsfwContent.all()
const learnData = await db.learn.all()
const userData = await db.learn.findOneAnotherKey('user_id', msg.author.id)
const muffin: ResponseData[] = []
data.forEach(row => {
if (row.persona === 'muffin') muffin.push(row)
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 { TextChannel } from 'discord.js'
import config from '../../config.json'
import { NODE_ENV } from '.'
import learn from '../Commands/learn'
import learning_data from '../Commands/learning_data'
export default class ChatBot {
get db() {
return new MaaDatabase()
public constructor(public db: MaaDatabase) {
setInterval(async () => {
this.db.ping()
}, 60000)
}
public async getResponse(msg: Message): Promise<string> {
const prefix = msg.client.prefix
const data = await this.db.statement.all()
@ -64,10 +64,6 @@ export default class ChatBot {
})
}
})
setInterval(async () => {
await this.db.ping()
}, 60000)
return this
}
}

View file

@ -1,6 +1,7 @@
import { createPool } from 'mysql2/promise'
import { LearnTable, NSFWContentTable, StatementTable } from './model'
import config from '../../../config.json'
import run from './run'
export class MaaDatabase {
private _database = createPool({
@ -8,23 +9,24 @@ export class MaaDatabase {
keepAliveInitialDelay: 10000,
enableKeepAlive: true,
})
public statement = new StatementTable(this._database)
public nsfwContent = new NSFWContentTable(this._database)
public learn = new LearnTable(this._database)
public get statement() {
return new StatementTable(this._database)
}
public get nsfwContent() {
return new NSFWContentTable(this._database)
}
public get learn() {
return new LearnTable(this._database)
}
public async ping() {
public ping() {
this._database.getConnection().then(conn => {
conn.ping()
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 Pool } from 'mysql2/promise'
import { Snowflake } from 'discord.js'
import run from '../run'
export class LearnTable implements BaseTable<LearnData, string> {
public name = 'learn'
@ -69,14 +69,4 @@ export class LearnTable implements BaseTable<LearnData, string> {
)
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 run from '../run'
import type { BaseTable, NSFWData } from '../type'
export class NSFWContentTable implements BaseTable<NSFWData, number> {
public name = 'nsfw_content'
public constructor(private _database: Pool) {}
public async all(): Promise<NSFWData[]> {
@ -56,19 +57,11 @@ export class NSFWContentTable implements BaseTable<NSFWData, number> {
data: any,
): Promise<NSFWData[]> {
const [rows] = await this._database.execute<NSFWData[]>(
`SELECT * FROM nsfw_content WHERE ${key} = ?;`,
`SELECT *
FROM nsfw_content
WHERE ${key} = ?;`,
[data],
)
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 run from '../run'
import type { BaseTable, ResponseData } from '../type'
export class StatementTable implements BaseTable<ResponseData, number> {
public name = 'statement'
@ -73,14 +73,4 @@ export class StatementTable implements BaseTable<ResponseData, number> {
)
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>
delete(key: V): Promise<void>
findOneAnotherKey(key: string, data: any): Promise<T[]>
execute<W>(sql: string, values?: any): Promise<W>
}