ඞඞඞඞඞඞඞඞ #3

Closed
migan wants to merge 1 commit from github/fork/imnyang/main into main
14 changed files with 306 additions and 15949 deletions

13626
.pnp.cjs generated

File diff suppressed because one or more lines are too long

2067
.pnp.loader.mjs generated

File diff suppressed because it is too large Load diff

View file

@ -1,97 +1,22 @@
import {
ActivityType,
Client,
Collection,
GatewayIntentBits,
TextChannel,
} from 'discord.js'
import { Command, noPerm, ChatBot, NODE_ENV } from './modules'
import { readdirSync } from 'node:fs'
import { join } from 'node:path'
import { execSync } from 'node:child_process'
import config from '../config.json'
const prefix = '멒힌아 '
export default class MuffinAI extends Client {
get chatBot() {
return this.#chatBot
}
#chatBot = new ChatBot()
#modules: Collection<string, Command> = new Collection()
public constructor() {
super({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
})
}
public override login(): Promise<string> {
if (NODE_ENV === 'development') this.on('debug', console.info)
this.chatBot.train(this)
setInterval(async () => {
const db = await this.chatBot.db.getConnection()
await db.beginTransaction()
await db.ping()
await db.commit()
db.release()
}, 600000)
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)
if (NODE_ENV === 'development') console.log(b.name)
})
this.once('ready', () => {
console.log(
`Build Number: ${execSync('git rev-parse --short HEAD').toString()}`,
)
this.user!.setActivity({
type: ActivityType.Playing,
name: 'ㅅ살려주세요..!',
})
console.log(`먹힐 준비 완료`)
}).on('messageCreate', async msg => {
if (msg.author.bot) return
if (msg.content.startsWith('머핀아 ')) {
if (msg.channel instanceof TextChannel) {
await msg.channel.sendTyping()
this.chatBot //
.getResponse(msg)
.then(response => {
msg.channel.send(response)
})
}
} else if (msg.content.startsWith(prefix)) {
if (msg.channel instanceof TextChannel) if (msg.channel.nsfw) return
const args: string[] = msg.content
.slice(prefix.length)
.trim()
.split(/ +/g)
if (NODE_ENV === 'development') console.log(args)
const command = this.#modules.get(args.shift()!.toLowerCase())
if (!command) return
if (command.noPerm && msg.author.id !== config.bot.owner_ID)
return await noPerm(msg)
command.execute(msg, args)
}
})
return super.login(config.bot.token)
}
}
declare module 'discord.js' {
interface Client {
get chatBot(): ChatBot
}
}
/*
*/
// Amogus

View file

@ -1,13 +1,22 @@
import { Command } from '../modules'
import { type Message } from 'discord.js'
export default class extends Command {
public constructor() {
super('봇꺼', true)
}
public execute(msg: Message, args: string[]) {
msg.channel.send('ㅇㅇ').finally(() => {
msg.client.destroy()
})
}
}
/*
*/
// Amogus

View file

@ -1,22 +1,22 @@
import { Command, type ResponseData, type NSFWData } from '../modules'
import { type Message } from 'discord.js'
export default class extends Command {
public constructor() {
super('학습데이터량')
}
public async execute(msg: Message, args: string[]) {
const db = await msg.client.chatBot.db.getConnection()
const [rows] = await db.execute<ResponseData[]>('SELECT * FROM statement;')
const [nsfw] = await db.execute<NSFWData[]>('SELECT * FROM nsfw_content;')
const muffin: ResponseData[] = []
rows.forEach(row => {
if (row.persona === 'muffin') muffin.push(row)
else return
})
msg.channel.send(
`머핀 데이터: ${muffin.length}\nnsfw 데이터: ${nsfw.length}`,
)
db.release()
}
}
/*
*/
// Amogus

View file

@ -1,25 +1,22 @@
import { Command } from '../modules'
import { Message } from 'discord.js'
import { inspect } from 'node:util'
export default class extends Command {
public constructor() {
super('테스트', true)
}
public async execute(msg: Message, args: string[]) {
if (!args) return msg.channel.send('전달받은 인자가 없습니다.')
try {
const a = eval(args.join(' '))
if (inspect(a).includes(msg.client.token))
return msg.channel.send(
`\`\`\`js\n${inspect(a).replaceAll(
msg.client.token,
'[discord_token]'
)}\n\`\`\``
)
await msg.channel.send(`\`\`\`js\n${inspect(a)}\n\`\`\``)
} catch (err) {
await msg.channel.send(`\`\`\`js\n${err}\n\`\`\``)
}
}
}
/*
*/
// Amogus

View file

@ -1 +1,22 @@
import('./Client').then(a => new a.default().login())
/*
*/
// Amogus

View file

@ -1,79 +1,22 @@
import type { Client, Message } from 'discord.js'
import database, { ResponseData } from './database'
import { TextChannel } from 'discord.js'
import config from '../../config.json'
export default class ChatBot {
get db() {
return this.#db
}
#db = database
public async getResponse(msg: Message): Promise<string> {
const db = await this.db.getConnection()
const [rows] = await db.execute<ResponseData[]>('SELECT * FROM statement;')
let response: string
if ((msg.channel as TextChannel).nsfw) {
const [rows1] = await db.execute<ResponseData[]>(
'SELECT * FROM nsfw_content;',
)
const rows2 = [...rows, ...rows1]
response = rows2[Math.floor(Math.random() * rows2.length)].text
} else {
response = rows[Math.floor(Math.random() * rows.length)].text
}
if (!response) response = '살ㄹ려주세요'
db.release()
return response
}
public async train(client: Client): Promise<ChatBot> {
const db = await this.db.getConnection()
client.on('messageCreate', async msg => {
if (msg.author.bot) return
if (msg.author.id === config.train.user_ID) {
const response = await this.getResponse(msg)
const [rows] = await db.execute<ResponseData[]>(
'SELECT * FROM statement;',
)
try {
await db.beginTransaction()
await db.execute(
'INSERT INTO statement (id, text, persona, in_response_to) VALUES (?, ?, ?, ?);',
[++rows[rows.length - 1].id, msg.content, 'muffin', response],
)
await db.commit()
} catch (err) {
console.log(err)
await db.rollback()
}
} else {
if (!(msg.channel as TextChannel).nsfw) return
if (!msg.content.startsWith('머핀아 ')) return
const user = `user:${msg.author.username.slice(0, 50).toLowerCase()}`
const text = msg.content.replace('머핀아 ', '')
const [rows] = await db.execute<ResponseData[]>(
'SELECT * FROM nsfw_content;',
)
try {
await db.beginTransaction()
await db.execute(
`INSERT INTO nsfw_content (id, text, persona) VALUES (?, ?, ?);`,
[++rows[rows.length - 1].id, text, user],
)
await db.commit()
} catch (err) {
console.log(err)
await db.rollback()
}
}
})
db.release()
setInterval(async () => {
const db = await database.getConnection()
await db.ping()
db.release()
}, 60000)
return this
}
}
/*
*/
// Amogus

View file

@ -1,6 +1,22 @@
import { Message } from 'discord.js'
export default abstract class Command {
protected constructor(public name: string, public noPerm: boolean = false) {}
public abstract execute(msg: Message, args: string[]): any
}
/*
*/
// Amogus

View file

@ -1,22 +1,22 @@
import { RowDataPacket, createPool } from 'mysql2/promise'
import config from '../../config.json'
export interface BaseData extends RowDataPacket {
id: number
text: string
created_at: string
persona: string
}
export interface ResponseData extends BaseData {
search_text: string
conversation: string
in_response_to: string | null
search_in_response_to: string
}
export { BaseData as NSFWData }
const database = createPool(config.mysql)
export default database
/*
*/
// Amogus

View file

@ -1,5 +1,22 @@
type NODE_ENV_TYPE = 'production' | 'development' | string
export const NODE_ENV: NODE_ENV_TYPE = process.env.NODE_ENV
? process.env.NODE_ENV
: 'production'
/*
*/
// Amogus

View file

@ -1,6 +1,22 @@
import ChatBot from './ChatBot'
import Command from './Command'
import database, { ResponseData, NSFWData } from './database'
import noPerm from './noPerm'
import { NODE_ENV } from './env'
export { ChatBot, Command, database, noPerm, ResponseData, NODE_ENV, NSFWData }
/*
*/
// Amogus

View file

@ -1,13 +1,22 @@
import { type Message } from 'discord.js'
export default async function noPerm(msg: Message) {
await msg.reply({
content: '당신은 내 제작자가 아니잖아!',
allowedMentions: {
repliedUser: false,
parse: [],
users: [],
roles: [],
},
})
}
/*
*/
// Amogus

View file

@ -1,9 +1,22 @@
import { defineConfig } from 'tsup'
export default defineConfig({
clean: true,
format: ['cjs'],
entry: ['src/index.ts', 'src/Commands/*.ts'],
// minify: true,
// splitting: true,
})
/*
*/
// Amogus