bot/src/Client.ts

76 lines
2 KiB
TypeScript
Raw Normal View History

2023-01-30 08:54:08 +00:00
import { ActivityType, Client, Collection, GatewayIntentBits } from 'discord.js'
2023-01-28 09:10:38 +00:00
import ChatBot from './ChatBot'
2023-01-24 11:27:40 +00:00
import Dokdo from 'dokdo'
2023-01-30 08:54:08 +00:00
import { readdirSync } from 'node:fs'
import { join } from 'node:path'
import Command from './Command'
import noPerm from './noPerm'
2023-01-23 13:53:02 +00:00
import 'dotenv/config'
2023-01-30 08:54:08 +00:00
const prefix = '멒힌아 '
2023-01-25 11:23:01 +00:00
2023-01-23 13:53:02 +00:00
export default class MuffinAI extends Client {
2023-01-30 08:54:08 +00:00
public chatBot = new ChatBot()
private modules: Collection<string, Command> = new Collection()
2023-01-23 13:53:02 +00:00
public constructor() {
super({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
})
}
public override login(): Promise<string> {
2023-01-25 11:23:01 +00:00
this.chatBot.train(this)
2023-01-30 08:54:08 +00:00
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)
})
2023-01-23 13:53:02 +00:00
this.once('ready', client => {
client.user!.setActivity({
type: ActivityType.Playing,
name: 'ㅅ살려주세요..!',
})
2023-01-23 14:00:35 +00:00
console.log(`먹힐 준비 완료`)
2023-01-30 08:54:08 +00:00
}).on('messageCreate', async msg => {
2023-01-23 13:53:02 +00:00
if (msg.author.bot) return
2023-01-30 08:54:08 +00:00
await new Dokdo(this, {
prefix,
2023-01-25 05:42:09 +00:00
noPerm,
2023-01-24 11:27:40 +00:00
aliases: ['테스트'],
owners: ['415135882006495242'],
}).run(msg)
2023-01-24 10:54:49 +00:00
if (msg.content.startsWith('머핀아 ')) this.chatBot.getResponse(msg, true)
2023-01-30 08:54:08 +00:00
else if (msg.content.startsWith(prefix)) {
const args: string[] = msg.content
.slice(prefix.length)
.trim()
.split('/ +/g')
const command = this.modules.get(args.join(' '))
if (!command) return
if (command.noPerm && msg.author.id !== '415135882006495242')
return await noPerm(msg)
command.execute(msg, args)
}
2023-01-23 13:53:02 +00:00
})
return super.login()
}
2023-01-24 10:54:49 +00:00
public override destroy() {
this.chatBot.destroy()
super.destroy()
}
2023-01-23 13:53:02 +00:00
}
2023-01-30 08:54:08 +00:00
declare module 'discord.js' {
interface Client {
chatBot: ChatBot
}
}