bot/src/Client.ts

78 lines
2 KiB
TypeScript
Raw Normal View History

2023-01-25 05:42:09 +00:00
import { ActivityType, Client, GatewayIntentBits, Message } from 'discord.js'
2023-01-24 07:43:52 +00:00
import ChatBot from './ChatBot.js'
2023-01-24 11:27:40 +00:00
import Dokdo from 'dokdo'
2023-01-23 13:53:02 +00:00
import 'dotenv/config'
2023-01-25 05:42:09 +00:00
function noPerm(msg: Message) {
msg.reply({
content: '당신은 내 남자친구가 아니야!',
allowedMentions: {
repliedUser: false,
parse: [],
users: [],
roles: [],
},
})
}
2023-01-25 11:23:01 +00:00
function isNotOwner(msg: Message): boolean {
if (msg.author.id !== '415135882006495242') {
noPerm(msg)
return false
} else return true
}
2023-01-23 13:53:02 +00:00
export default class MuffinAI extends Client {
2023-01-25 11:23:01 +00:00
private chatBot = new ChatBot()
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-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-24 03:55:58 +00:00
}).on('messageCreate', msg => {
2023-01-23 13:53:02 +00:00
if (msg.author.bot) return
2023-01-24 11:27:40 +00:00
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)
else if (msg.content.startsWith('멒힌아 봇꺼')) {
2023-01-25 11:23:01 +00:00
if (!isNotOwner(msg)) return
2023-01-24 10:54:49 +00:00
this.destroy()
2023-01-25 11:23:01 +00:00
} else if (msg.content.startsWith('멒힌아 모드변경')) {
if (!isNotOwner(msg)) return
const a = this.chatBot.changeTrainType()
switch (a) {
case 'muffinOnly':
msg.channel.send('현재 모드: 머핀만 학습')
break
case 'All':
msg.channel.send('현재 모드: 전체 학습')
break
}
2023-01-24 10:54:49 +00:00
} else return
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
}