-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
439 lines (351 loc) · 18.7 KB
/
index.js
File metadata and controls
439 lines (351 loc) · 18.7 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
const Discord = require('discord.js');
const mysql = require('mysql');
const moment = require('moment');
const config = require('./config.json');
const client = new Discord.Client();
moment.locale("en-ca");
const conn = mysql.createConnection({
host : 'IP',
port : 'PORT',
user : 'NAME',
password : 'PASSWORD',
database : 'Database name',
charset : 'utf8mb4'
});
client.once('ready', () => {
console.log('-Rutkuli bot is online!');
client.user.setActivity("-Rutkuli- !Help", { type: "Streaming"});
});
setInterval(function(){
console.log('-Checking for expired keys...');
conn.query("UPDATE users SET `valid` = 'false' WHERE `expire` <= DATE_SUB(NOW(), INTERVAL 5 MINUTE)", function (err) {
if (err) {
return console.log(err);
}
});
}, 120000);
setInterval(function(){
console.log('-Checking for expired keys with ip address...');
conn.query("UPDATE users SET `server` = '0' WHERE `expire` <= DATE_SUB(NOW(), INTERVAL 5 MINUTE)", function (err) {
if (err) {
return console.log(err);
}
});
}, 120000);
client.on('message', message => {
if (!message.content.startsWith(config.prefix) || message.author.bot) return;
if (message.channel.type == "dm") return;
const args = message.content.slice(config.prefix.length).split(' ');
const command = args.shift();
if (command === 'redeem') {
if (!args.length) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('Correct use: !redeem [MY KEY]')
return message.channel.send(embed);
}
conn.query('SELECT * FROM users WHERE license = ?', [args[0]], function (err, result) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('The key you entered is not valid.')
return message.channel.send(embed);
}
if (result.length > 0) {
if (result) {
if (result[0].user == "NULL") {
conn.query('UPDATE users SET user = ? WHERE license = ?', [message.member.id, args[0]], function (err) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('A server-side error has occurred.')
return message.channel.send(embed);
}
const embed = new Discord.RichEmbed()
.setColor('#9500ff')
.setAuthor('verified!', 'https://cdn.discordapp.com/attachments/728943475684278324/732990460557131786/41-418338_success-png-payment-successful-icon-clipart.png')
.setDescription('The given key has been assigned to your account.')
return message.channel.send(embed);
});
} else {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('This key is already used.')
return message.channel.send(embed);
}
}
}
});
}
if (command === 'setip') {
message.delete();
if (!args.length) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('Correct use: !setip [YOUR KEY] [YOUR SERVER IP ADRESS]')
return message.channel.send(embed);
}
conn.query('SELECT * FROM users WHERE license = ?', [args[0]], function (err, result) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('The key you entered is not valid.')
return message.channel.send(embed);
}
if (args[1] == "localhost" || args[1] == "127.0.0.1") {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription(`You cannot use this server address (${args[1]}).\nYou should use the public address of the FiveM hosting server.`)
return message.channel.send(embed);
}
if (result.length > 0) {
if (result) {
let beforeIp = result[0].server;
if (result[0].user == message.member.id || message.member.hasPermission('ADMINISTRATOR')) {
conn.query('UPDATE users SET server = ? WHERE license = ?', [args[1], args[0]], function (err) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('A server-side error has occurred.')
return message.channel.send(embed);
}
const embed = new Discord.RichEmbed()
.setColor('#9500ff')
.setAuthor('verified!', 'https://cdn.discordapp.com/attachments/728943475684278324/732990460557131786/41-418338_success-png-payment-successful-icon-clipart.png')
.setDescription(`The server address assigned to the key has been successfully changed.\nFrom **${beforeIp}** to **${args[1]}**.`)
return message.channel.send(embed);
});
} else {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('You are not the owner of this key.')
return message.channel.send(embed);
}
}
}
});
}
if (command === 'setproduct') {
message.delete();
if (!args.length) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('Correct use: !setgame [BUYER KEY] [product]')
return message.channel.send(embed);
}
conn.query('SELECT * FROM users WHERE license = ?', [args[0]], function (err, result) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('The product you entered is not valid.')
return message.channel.send(embed);
}
if (args[1] == "steam" || args[1] == "steam") {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription(`You cannot use this product (${args[1]}).\nYou should use products like FiveM / Spoofer etc.`)
return message.channel.send(embed);
}
if (result.length > 0) {
if (result) {
if (result[0].user == message.member.id || message.member.hasPermission('ADMINISTRATOR')) {
conn.query('UPDATE users SET product = ? WHERE license = ?', [args[1], args[0]], function (err) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('A server-side error has occurred.')
return message.channel.send(embed);
}
const embed = new Discord.RichEmbed()
.setColor('#9500ff')
.setAuthor('verified!', 'https://cdn.discordapp.com/attachments/728943475684278324/732990460557131786/41-418338_success-png-payment-successful-icon-clipart.png')
.setDescription(`The product assigned to the key has been successfully changed.`)
return message.channel.send(embed);
});
} else {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('You are not the owner of this key.')
return message.channel.send(embed);
}
}
}
});
}
if (command === 'status') {
conn.query('SELECT * FROM users WHERE user = ?', [message.member.id], function (err, result) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('you dont own any products.')
return message.channel.send(embed);
}
if (result.length > 0) {
if (result) {
let date;
if (result[0].valid == "true") {
date = moment(result[0].expire).format('LLL');
} else {
date = "❌ Your subscription has expired.";
}
const embed = new Discord.RichEmbed()
.setColor('#9500ff')
.setAuthor('STATUS', 'https://cdn.discordapp.com/attachments/728943475684278324/732990460557131786/41-418338_success-png-payment-successful-icon-clipart.png')
.addField('your subscription will expire on:', date)
return message.channel.send(embed);
}
} else {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('The key you entered is not valid.')
return message.channel.send(embed);
}
});
}
if (command === 'keys') {
conn.query('SELECT * FROM users WHERE user = ?', [message.member.id], function (err, result) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('An error occurred while retrieving your keys.')
return message.channel.send(embed);
}
if (result.length > 0) {
if (result) {
const embed = new Discord.RichEmbed()
.setColor('#9500ff')
.setAuthor('verified', 'https://cdn.discordapp.com/attachments/728943475684278324/732990460557131786/41-418338_success-png-payment-successful-icon-clipart.png')
.setDescription('```List of keys assigned to your account.```');
result.forEach(function(row) {
embed.addField('Key:', row.license)
})
embed.setTimestamp()
return message.channel.send(embed);
}
} else {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('You don\'t have any keys on your account.')
return message.channel.send(embed);
}
});
}
////////////////////////////////////////////////////
if (command === 'help') {
const exampleEmbed = new Discord.RichEmbed()
.setColor('#9500ff')
.setAuthor('Rutkuli- Do you need help?', 'https://i.imgur.com/DhNQJUw.png')
.setThumbnail('https://cdn.discordapp.com/attachments/728943475684278324/729468233677275226/a43c.png')
.addField('!help', 'Lists bot commands')
.addField('!delete', 'Deletes the key from the database (DEV)')
.addField('!create', 'Creates a new key (DEV)')
.addField('!redeem:', 'Assigns a key to the account')
.addField('!setip', 'Assigns the servers IP to the key')
.addField('!setproduct', 'Assigns a product to the key (DEV)')
.addField('!status', 'Tells you the status of your account')
.addField('!keys', 'List of keys assigned to the account')
.addField('!Sreq', 'Opens support request platform (use only if you need help)')
.setTimestamp()
return message.channel.send(exampleEmbed).then(msg => msg.delete(60000));
}
if (command === 'delete') {
if (message.member.hasPermission('ADMINISTRATOR')) {
if (!args.length) {
const exampleEmbed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('Correct use: !delete [KEY]')
return message.channel.send(exampleEmbed);
}
conn.query('SELECT license FROM users WHERE license = ?', [args[0]], function (err, result) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('The key you entered is not valid.')
return message.channel.send(embed);
}
if (result.length > 0) {
if (result) {
conn.query('DELETE FROM users WHERE license = ?', [args[0]], function (err) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('An error occurred while performing the operation.')
return message.channel.send(embed);
}
const embed = new Discord.RichEmbed()
.setColor('#9500ff')
.setAuthor('verified!', 'https://cdn.discordapp.com/attachments/728943475684278324/732990460557131786/41-418338_success-png-payment-successful-icon-clipart.png')
.setDescription(`The **${args[0]}** has been removed from the database.`)
return message.channel.send(embed);
});
}
}
});
} else {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('You do not have the required permissions to use this.')
return message.channel.send(embed);
}
}
if (command === 'create') {
if (message.member.hasPermission('ADMINISTRATOR') || message.member.roles.has('user id')) {
let r = Math.random().toString(36).substr(5, 5) + "-" + Math.random().toString(36).substr(5, 5) + "-" + Math.random().toString(36).substr(5, 5) + "-" + Math.random().toString(36).substr(5, 5);
if (!args.length) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('Correct use: !create [NUMBER] [DAY / MONTH / YEAR]')
return message.channel.send(embed);
}
conn.query(`INSERT INTO users (license, expire, creator) VALUES ('${r}', DATE_ADD(NOW(), INTERVAL ${args[0]} ${args[1]}), ${message.member.id});`, function (err) {
if (err) {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('An error occurred while performing the operation.')
return message.channel.send(embed);
}
const priv = new Discord.RichEmbed()
.setColor('##9500ff')
.setAuthor('Lisence created!', 'https://cdn.discordapp.com/attachments/728943475684278324/729468233677275226/a43c.png')
.setDescription(`The **${r}** key was successfully generated.\nThe key is valid for **${args[0]} ${args[1]} ${args[2]}**.`)
message.author.send(priv);
const embed = new Discord.RichEmbed()
.setColor('#9500ff')
.setAuthor('Created!', 'https://cdn.discordapp.com/attachments/728943475684278324/729468233677275226/a43c.png')
.setDescription('Okay dude:sunglasses: ')
return message.channel.send(embed);
});
} else {
const embed = new Discord.RichEmbed()
.setColor('#e2574c')
.setAuthor('ERROR!', 'https://i.imgur.com/8bo2OJT.png')
.setDescription('You do not have the required permissions to do this.')
return message.channel.send(embed);
}
}
});
client.login(config.token);