bot/src/Client.ts

89 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-01-25 05:42:09 +00:00
import { ActivityType, Client, GatewayIntentBits, Message } 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-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
2023-01-28 09:10:38 +00:00
switch (this.chatBot.trainType) {
case 'muffinOnly':
this.chatBot.trainType = 'All'
msg.channel.send('다음 모드로 변경: 전체 학습')
break
case 'All':
this.chatBot.trainType = 'muffinOnly'
msg.channel.send('다음 모드로 변경: 머핀만 학습')
break
}
} else if (msg.content.startsWith('멒힌아 현재모드')) {
if (!isNotOwner(msg)) return
switch (this.chatBot.trainType) {
2023-01-25 11:23:01 +00:00
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
}