-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
224 lines (187 loc) Β· 10.7 KB
/
main.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
const auth = require('./credentials.json');
const Discord = require('discord.js');
const client = new Discord.Client();
global.fetch = require("node-fetch");
const Core = require('./core.js');
// (1) client start
client.login(auth.token);
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
// (2) events
client.on('message', msg => {
if (msg.toString().startsWith("!core")) {
var args = msg.toString().substring(1).split(' ');
var cmd = args[1];
if (cmd == "setdonations") {
try {
if (msg.member.hasPermission('ADMINISTRATOR', false, false)) {
new Core().fromDiscord(msg.guild.id, auth.token).then(function (core) {
core.getInstance().asNetwork().setDonationChannel(msg.channel.id).then((core) => {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('π', 'The donation events will now appear on this channel', false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}).catch(function (reason) {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('There was an error while linking the guild with your donation events', reason, false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
});
})
} else {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('β You\'re not an administrator!', 'You need to have the ADMINISTRATOR permission in order to execute this command.', false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}
} catch (error) {
console.log(error)
}
} else if (cmd == "setsessions") {
try {
if (msg.member.hasPermission('ADMINISTRATOR', false, false)) {
new Core().fromDiscord(msg.guild.id, auth.token).then(function (core) {
core.getInstance().asNetwork().setSessionChannel(msg.channel.id).then((core) => {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('π', 'The session events will now appear on this channel', false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}).catch(function (reason) {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('There was an error while linking the guild with your session events', reason, false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
});
})
} else {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('β You\'re not an administrator!', 'You need to have the ADMINISTRATOR permission in order to execute this command.', false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}
} catch (error) {
console.log(error)
}
} else if (cmd == "setkey") {
if (args.length = 3) {
var coreInstance = new Core(args[2])
try {
if (msg.member.hasPermission('ADMINISTRATOR', false, false)) {
coreInstance.getInstance().asNetwork().setGuild(msg.guild.id).then((successMessage) => {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('π', 'This instance has been linked to this guild. The message has been deleted in order to prevent your keys to be copied.', false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}).catch(function (reason) {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('There was an error while linking the guild with your instance', reason, false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
});;
} else {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('β You\'re not an administrator!', 'You need to have the ADMINISTRATOR permission in order to execute this command.', false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}
} catch (error) {
console.log(error)
}
} else {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('Invalid params', 'You need a second param in order to execute this command. The message has been deleted in order to prevent your keys to be copied.', false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}
msg.delete()
} else if (cmd == "link") {
if (args.length < 3) {
new Core().fromDiscord(msg.guild.id, auth.token, true).then(function (core) {
var url = "https://api.purecore.io/link/discord/associate/?key=" + core.getKey();
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('Link your account', 'Link your game accounts by [clicking here](' + url + ')', false)
.setThumbnail(msg.author.avatarURL)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}).catch(function (reason) {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('β There was an error while generating your authentication url', reason, false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
});
} else {
if (args[2] == "global") {
new Core().fromDiscord(msg.guild.id, auth.token, true).then(function (core) {
var url = "https://api.purecore.io/link/discord/associate/?key=" + core.getKey();
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('Global profile linking', 'Link your game accounts by [clicking here](' + url + ')', false)
.setThumbnail(msg.guild.iconURL)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}).catch(function (reason) {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('β There was an error while generating your authentication url', reason, false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
});
} else {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.addField('β Unknown argument', false)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}
}
} else {
const embed = new Discord.RichEmbed()
.setColor('#448aff')
.setTitle('core. help')
.setDescription('Welcome to [purecore.io](https://purecore.io/)!')
.setAuthor('quiquelhappy', 'https://i.imgur.com/OAQblee.png', 'https://twitter.com/quiquelhappy/')
.addBlankField(false)
.addField('!core setkey <key>', 'Sets your discord key. This links your instance with this guild. In order to execute any other commands, you need to do this first. You can get your key [here](https://purecore.io/dashboard/)', true)
.addBlankField(false)
.addField('!core settickets', 'Set ticket updates channel', true)
.addField('!core setpunishments', 'Set punishment updates channel', true)
.addField('!core setdonations', 'Set donation updates channel', true)
.addField('!core setsessions', 'Set session updates channel', true)
.addBlankField(false)
.addField('!core minecraft', 'Returns your Minecraft account if any', true)
.addField('!core payments', 'Returns your payments if any', true)
.addField('!core link', 'Returns an url so you can link your discord account with your game sessions', true)
.setTimestamp()
.setFooter('the all-in-one community managment solution');
msg.channel.send(embed);
}
}
});