-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
103 lines (89 loc) · 2.97 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import discord, { Intents } from 'discord.js' ;
import consola from 'consola' ;
//configs
import { BOT_TOKEN } from './config';
import connectDB from './config/db';
//constants
import {
PREFIX ,
GET_USER ,
REGISTER ,
GET_VIRTUAL ,
REFRESH ,
HELP
} from './utils/constants' ;
//utils
import parseMessage from './utils/parseMessage' ;
import { virtualContestsEmbed , userInfoEmbed } from './message_templates/embeds' ;
//actions
import getUser from './actions/GetUser' ;
import registerUser from './actions/RegisterUser' ;
import getVirtual from './actions/GetVirtual' ;
const client: any = new discord.Client({
intents: [
Intents.FLAGS.GUILDS ,
Intents.FLAGS.GUILD_MESSAGES
]
}) ;
client.login(BOT_TOKEN) ;
client.on('ready' , () => {
connectDB() ;
consola.success("Polycarp V2 is online") ;
}) ;
client.on("messageCreate" , async (userMessage: any): Promise<any> => {
if(userMessage.author.bot) return null ;
if(userMessage.content.startsWith(PREFIX)) {
let {
COMMAND ,
ARGS ,
FLAGS
} : {
COMMAND : string ;
ARGS : any ;
FLAGS : string[]
} = parseMessage(userMessage.content) ;
switch (COMMAND) {
case GET_USER : {
let {
success ,
userData ,
message
} : {
success : boolean ;
userData : any ;
message : string
} = await getUser(ARGS.username) ;
if (success) {
userMessage.reply({embeds : [userInfoEmbed(userData)]}) ;
} else {
userMessage.reply(message) ;
}
return ;
}
case REGISTER : {
const author : any = userMessage.author ;
const handle : string = ARGS.handle ;
let {success , message } : { success : boolean ; message : string } = await registerUser(author , handle) ;
if (success) {
userMessage.member.setNickname(handle) ;
}
userMessage.reply(message) ;
return ;
}
case GET_VIRTUAL: {
// userMessage.reply(`This action is under maintainance at the moment...`) ;
// break ;
let { success , contests , message } : { success : boolean ; contests : any ; message : string } = await getVirtual(ARGS.users) ;
if ( success ) {
// consola.log(contests) ;
userMessage.reply({embeds : [virtualContestsEmbed(contests)]}) ;
} else {
userMessage.reply(message) ;
}
return ;
}
default :
userMessage.reply("Hello world !") ;
}
}
});