2023-02-02 13:17:58 +00:00
|
|
|
import {
|
|
|
|
ActivityType,
|
|
|
|
Client,
|
|
|
|
Collection,
|
|
|
|
GatewayIntentBits,
|
|
|
|
TextChannel,
|
|
|
|
} from 'discord.js'
|
2024-05-30 09:50:14 +00:00
|
|
|
import { type Command, noPerm, ChatBot, NODE_ENV } from './modules'
|
2023-01-30 08:54:08 +00:00
|
|
|
import { readdirSync } from 'node:fs'
|
|
|
|
import { join } from 'node:path'
|
2023-06-05 05:06:03 +00:00
|
|
|
import config from '../config.json'
|
2024-05-30 11:34:15 +00:00
|
|
|
import Dokdo from 'dokdo'
|
2023-01-23 13:53:02 +00:00
|
|
|
|
2024-06-08 13:51:02 +00:00
|
|
|
const prefix = '머핀아 '
|
2023-01-25 11:23:01 +00:00
|
|
|
|
2024-05-30 13:15:23 +00:00
|
|
|
export default class MuffinBot extends Client {
|
2024-06-09 12:17:20 +00:00
|
|
|
#modules: Collection<string, Command> = new Collection()
|
2023-02-11 06:03:25 +00:00
|
|
|
get chatBot() {
|
2024-05-30 11:34:15 +00:00
|
|
|
return new ChatBot()
|
|
|
|
}
|
2024-05-30 13:15:23 +00:00
|
|
|
get modules(): Collection<string, Command> {
|
|
|
|
return this.#modules
|
|
|
|
}
|
2024-06-09 12:17:20 +00:00
|
|
|
public dokdo: Dokdo = new Dokdo(this, {
|
|
|
|
aliases: ['dokdo', 'dok'],
|
|
|
|
owners: [config.bot.owner_ID],
|
|
|
|
noPerm,
|
|
|
|
prefix,
|
|
|
|
})
|
|
|
|
public prefix = prefix
|
2023-01-23 13:53:02 +00:00
|
|
|
public constructor() {
|
|
|
|
super({
|
|
|
|
intents: [
|
|
|
|
GatewayIntentBits.Guilds,
|
|
|
|
GatewayIntentBits.GuildMessages,
|
|
|
|
GatewayIntentBits.MessageContent,
|
|
|
|
],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
public override login(): Promise<string> {
|
2023-02-08 12:00:37 +00:00
|
|
|
if (NODE_ENV === 'development') this.on('debug', console.info)
|
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()
|
2024-05-30 13:15:23 +00:00
|
|
|
this.modules.set(b.name, b)
|
2024-05-30 09:50:14 +00:00
|
|
|
if (NODE_ENV === 'development') console.log(`${b.name}가 로ㄷ드됨`)
|
2023-01-30 08:54:08 +00:00
|
|
|
})
|
|
|
|
|
2023-11-25 04:04:29 +00:00
|
|
|
this.once('ready', client => {
|
|
|
|
function setStatus() {
|
|
|
|
client.user.setActivity({
|
|
|
|
type: ActivityType.Custom,
|
|
|
|
name: 'ㅅ살려주세요..!',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
setStatus()
|
|
|
|
setInterval(() => setStatus(), 600000)
|
|
|
|
|
2024-06-06 03:00:09 +00:00
|
|
|
console.log(`먹힐 준ㅂ비 완료`)
|
2023-01-30 08:54:08 +00:00
|
|
|
}).on('messageCreate', async msg => {
|
2023-12-02 07:22:48 +00:00
|
|
|
const args: string[] = msg.content
|
|
|
|
.slice(prefix.length)
|
|
|
|
.trim()
|
|
|
|
.split(/ +/g)
|
|
|
|
|
|
|
|
if (NODE_ENV === 'development') console.log(args)
|
2023-01-23 13:53:02 +00:00
|
|
|
if (msg.author.bot) return
|
2024-05-30 09:50:14 +00:00
|
|
|
if (msg.content.startsWith(prefix)) {
|
2024-05-30 11:34:15 +00:00
|
|
|
if (args[0].startsWith('dokdo') || args[0].startsWith('dok')) {
|
|
|
|
await this.dokdo.run(msg)
|
|
|
|
} else {
|
2024-06-09 12:17:20 +00:00
|
|
|
await msg.channel.sendTyping()
|
|
|
|
const command = this.modules.get(args.shift()!.toLowerCase())
|
2023-12-02 07:22:48 +00:00
|
|
|
|
2024-06-09 12:17:20 +00:00
|
|
|
if (command) {
|
|
|
|
if (command.noPerm && msg.author.id !== config.bot.owner_ID)
|
|
|
|
return await noPerm(msg)
|
2023-12-02 07:22:48 +00:00
|
|
|
|
2024-06-09 12:17:20 +00:00
|
|
|
await command.execute(msg, args)
|
|
|
|
} else {
|
|
|
|
const response = await this.chatBot.getResponse(msg)
|
|
|
|
await msg.reply(response)
|
2023-12-02 07:22:48 +00:00
|
|
|
}
|
2023-02-02 13:17:58 +00:00
|
|
|
}
|
2023-01-30 08:54:08 +00:00
|
|
|
}
|
2023-01-23 13:53:02 +00:00
|
|
|
})
|
2023-06-05 05:06:03 +00:00
|
|
|
return super.login(config.bot.token)
|
2023-01-23 13:53:02 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-30 08:54:08 +00:00
|
|
|
|
|
|
|
declare module 'discord.js' {
|
|
|
|
interface Client {
|
2023-02-11 06:03:25 +00:00
|
|
|
get chatBot(): ChatBot
|
2024-05-30 13:15:23 +00:00
|
|
|
get modules(): Collection<string, Command>
|
2024-06-09 12:17:20 +00:00
|
|
|
dokdo: Dokdo
|
|
|
|
prefix: string
|
2023-01-30 08:54:08 +00:00
|
|
|
}
|
|
|
|
}
|