bot/src/Client.ts

87 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-02-02 13:17:58 +00:00
import {
ActivityType,
Client,
Collection,
GatewayIntentBits,
TextChannel,
} from 'discord.js'
2023-02-01 05:43:14 +00:00
import { Command, noPerm, ChatBot } from './modules'
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'
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()
2023-02-02 13:17:58 +00:00
#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()
2023-02-02 13:17:58 +00:00
this.#modules.set(b.name, b)
2023-01-30 08:54:08 +00:00
})
2023-02-06 11:21:58 +00:00
this.once('ready', () => {
this.user!.setActivity({
2023-01-23 13:53:02 +00:00
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-02-01 05:43:14 +00:00
if (msg.content.startsWith('머핀아 ')) {
2023-02-02 13:17:58 +00:00
if (msg.channel instanceof TextChannel) {
if (msg.channel.nsfw) return
await msg.channel.sendTyping()
2023-02-04 10:47:48 +00:00
await msg.channel.send(await this.chatBot.getResponse(msg))
2023-02-02 13:17:58 +00:00
}
2023-02-01 05:43:14 +00:00
} else if (msg.content.startsWith(prefix)) {
2023-02-04 10:47:48 +00:00
if (msg.channel instanceof TextChannel) if (msg.channel.nsfw) return
2023-01-30 08:54:08 +00:00
const args: string[] = msg.content
.slice(prefix.length)
.trim()
.split('/ +/g')
2023-02-02 13:17:58 +00:00
const command = this.#modules.get(args.toString())
2023-01-30 08:54:08 +00:00
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() {
super.destroy()
2023-02-04 10:47:48 +00:00
process.exit()
2023-01-24 10:54:49 +00:00
}
2023-01-23 13:53:02 +00:00
}
2023-01-30 08:54:08 +00:00
declare module 'discord.js' {
interface Client {
chatBot: ChatBot
}
}