-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.js
618 lines (548 loc) · 33.5 KB
/
index.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
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
const Eris = require('eris');
const config = require('./config.js');
var Trello = require("node-trello");
var t = new Trello(config.trelloKey, config.trelloToken);
var bot = new Eris(config.botToken);
bot.on("error", err => {
console.log("@" + bot.user.username + " - " + "ERROR:\n" + err.stack);
});
bot.on("ready", () => {
console.log('Ready!');
});
function delay(delayMS) {
return function(arg){
return new Promise((resolve) => {
setTimeout(() => resolve(arg), delayMS);
});
}
}
bot.on('guildMemberUpdate', (guild, member, oldMember) => {
if(oldMember.roles.indexOf(config.hunterRole) <= -1 && member.roles.indexOf(config.hunterRole) > -1){
bot.createMessage(config.bugHunterChannel, 'Welcome <@' + member.user.id + '> to the Bug Hunters™!');
}
});
bot.on('messageCreate', (msg) => {
var messageSplit = msg.content.split(' ');
var command = messageSplit.shift();
var channelID = msg.channel.id;
var userTag = msg.author.username + "#" + msg.author.discriminator;
var userID = msg.author.id;
switch (command.toLowerCase()) {
case "!android":
var android = config.androidAlphaRole;
var roles = msg.member.roles;
var index = roles.indexOf(android);
if(index === -1){
roles.push(android);
bot.editGuildMember(msg.guild.id, userID, {
roles: roles
}).then(() => {
bot.createMessage(channelID, "<@" + userID + ">, you have been given the role of `Android Alpha`. Use the same command again to remove this role from yourself.").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
bot.createMessage(config.modLogChannel, "Gave `Android Alpha` to **" + userTag + "**");
});
}else{
roles.splice(index, 1);
bot.editGuildMember(msg.guild.id, userID, {
roles: roles
}).then(() => {
bot.createMessage(channelID, "<@" + userID + ">, you have been removed from the `Android Alpha` role. Use the same command again to add this role to yourself.").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
bot.createMessage(config.modLogChannel, "Removed `Android Alpha` from **" + userTag + "**");
});
}
break;
case "!ios":
var ios = config.iosTestflightRole;
var roles = msg.member.roles;
var index = roles.indexOf(ios);
if(index === -1){
roles.push(ios);
bot.editGuildMember(msg.guild.id, userID, {
roles: roles
}).then(() => {
bot.createMessage(channelID, "<@" + userID + ">, you have been given the role of `iOSTestflight`. Use the same command again to remove this role from yourself.").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
bot.createMessage(config.modLogChannel, "Gave `iOSTestflight` to **" + userTag + "**");
});
}else{
roles.splice(index, 1);
bot.editGuildMember(msg.guild.id, userID, {
roles: roles
}).then(() => {
bot.createMessage(channelID, "<@" + userID + ">, you have been removed from the `iOSTestflight` role. Use the same command again to add this role to yourself.").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
bot.createMessage(config.modLogChannel, "Removed `iOSTestflight` from **" + userTag + "**");
});
}
break;
}
if(channelID === config.androidChannel || channelID === config.canaryChannel || channelID === config.iosChannel){
if(command.toLowerCase() === "!addnote"){
var joinedMessage = messageSplit.join(' ');
var trelloURL = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)?\s*\|\s*([\s\S]*)/gi, "$2");
var note = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)?\s*\|\s*([\s\S]*)/gi, "$5");
t.get("/1/cards/" + trelloURL, { }, function(errorURL, urlData) {
if(!!urlData && !!urlData.id){
if(note === trelloURL){
bot.createMessage(channelID, "<@" + userID + ">, please provide a note").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
}else{
repro(note, undefined, channelID, trelloURL, userID, userTag, undefined, undefined, msg.id);
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, please provide a valid URL and a note").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
}
});
}
if(command.toLowerCase() === "!canrepro" || command.toLowerCase() === "!canrepo"){
var joinedMessage = messageSplit.join(' ');
var trelloURL = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)?\s*\|\s*([\s\S]*)/gi, "$2");
var clientInfo = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)?\s*\|\s*([\s\S]*)/gi, "$5");
t.get("/1/cards/" + trelloURL, { }, function(errorURL, urlData) {
if(!!urlData && !!urlData.id){
var reproduction = "Can reproduce.";
bot.getMessages(channelID).then((data) => {
var dataFinder = data.find(function(foundObj) {
return foundObj.author.id === config.botID && foundObj.content.indexOf('https://trello.com/c/' + trelloURL) > -1;
});
var editMsgCreate = dataFinder.content + "\n✅ " + userTag;
if(clientInfo === trelloURL){
repro(clientInfo, reproduction, channelID, trelloURL, userID, userTag, dataFinder.id, editMsgCreate, msg.id);
}else{
repro(clientInfo, reproduction, channelID, trelloURL, userID, userTag, dataFinder.id, editMsgCreate, msg.id);
}
});
}else{
bot.createMessage(channelID, "<@" + userID + ">, please provide a valid URL and a client version").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
}
});
}
if(command.toLowerCase() === "!cannotrepro" || command.toLowerCase() === "!cantrepro" || command.toLowerCase() === "!cantrepo" || command.toLowerCase() === "!cannotrepo"){
var joinedMessage = messageSplit.join(' ');
var trelloURL = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)?\s*\|\s*([\s\S]*)/gi, "$2");
var clientInfo = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)?\s*\|\s*([\s\S]*)/gi, "$5");
if(!!trelloURL && (clientInfo !== trelloURL)){
t.get("/1/cards/" + trelloURL, { }, function(errorURL, urlData) {
if(!!urlData && !!urlData.id){
var reproduction = "Can't reproduce.";
bot.getMessages(channelID).then((data) => {
var dataFinder = data.find(function(foundObj) {
return foundObj.author.id === config.botID && foundObj.content.indexOf('https://trello.com/c/' + trelloURL) > -1;
});
var editMsgCreate = dataFinder.content + "\n❌ " + userTag;
if(clientInfo === trelloURL){
repro(clientInfo, reproduction, channelID, trelloURL, userID, userTag, dataFinder.id, editMsgCreate, msg.id);
}else{
repro(clientInfo, reproduction, channelID, trelloURL, userID, userTag, dataFinder.id, editMsgCreate, msg.id);
}
});
}else{
bot.createMessage(channelID, "<@" + userID + ">, incorrect url").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
}
});
}else{
bot.createMessage(channelID, "<@" + userID + ">, please provide a valid URL and a client version").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
}
}
if(command.toLowerCase() === "!attach"){
var dev = msg.member.roles.indexOf(config.devRole);
var hunter = msg.member.roles.indexOf(config.hunterRole);
var admin = msg.member.roles.indexOf(config.adminRole);
if(dev > -1 || hunter > -1 || admin > -1){
var attachment;
var joinedMessage = messageSplit.join(' ');
var trelloURL = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)?(\s\|(?:\s)?(.*))?/gi, "$2");
var attachmentUrl = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)?(\s\|(?:\s)?(.*))?/gi, "$6");
t.get("/1/cards/" + trelloURL, { }, function(errorURL, urlData) {
if(!!urlData && !!urlData.id){
if(!!msg.attachments[0]){
attachment = msg.attachments[0].url;
addAttachment(channelID, attachment, trelloURL, userID, trelloURL, urlData.name, userTag);
}else if(!!attachmentUrl.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/ig)){
attachment = attachmentUrl;
addAttachment(channelID, attachment, trelloURL, userID, trelloURL, urlData.name, userTag);
}else{
bot.createMessage(channelID, "<@" + userID + "> Please include a valid image").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + "> Please include a valid trello link").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
bot.deleteMessage(channelID, msg.id);
});
}
});
}else{
bot.createMessage(channelID, "<@" + userID + ">, only people with the role of Bug Hunter or higher can use that command, in order to prevent spam and abuse. Just ask any Bug Hunter™ and they'll be more than happy to help you out.").then(delay(config.delayInMS)).then((msg_id) => {
bot.deleteMessage(msg_id.channel.id, msg_id.id);
bot.deleteMessage(channelID, msg.id);
});
}
} // Add attachments to reports // Attach files to existing reports
if(command.toLowerCase() === "!edit"){
var dev = msg.member.roles.indexOf(config.devRole);
var hunter = msg.member.roles.indexOf(config.hunterRole);
var admin = msg.member.roles.indexOf(config.adminRole);
if(dev > -1 || hunter > -1 || admin > -1){
var attachment;
var joinedMessage = messageSplit.join(' ');
var splitter = msg.content.match(/\|/g);
var trelloURL = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)? \| ([\s\S]*)/gi, "$2");
var report = joinedMessage.replace(/(?:(<)?(?:https?:\/\/)?(?:www\.)?trello.com\/c\/)?([^\/|\s|\>]+)(\/|\>)?(?:[\w-\d]*)?(\/|\>|\/>)? \| ([\s\S]*)/gi, "$5");
var lowerCaseReport = report.toLowerCase();
var matchFormat = lowerCaseReport.match(/\bsteps to reproduce|expected result|actual result/gi);
if(!!splitter && splitter.length < 2) {
if(!!matchFormat && matchFormat.indexOf('steps to reproduce') > -1) {
if(!!matchFormat && matchFormat.indexOf('expected result') > -1) {
if(!!matchFormat && matchFormat.indexOf('actual result') > -1) {
t.get("/1/cards/" + trelloURL, { }, function(errorURL, urlData) {
if(!!urlData && !!urlData.id){
var attachment;
var section2 = report.match(/(steps to reproduce)([\s\S]*)(?=expected result)/gi);
var section3 = report.match(/(expected result)([\s\S]*)(?=actual result)/gi);
var systemClient = lowerCaseReport.match(/\b(?:system setting)|\b(?:client version)/gi);
if(!!systemClient && systemClient.length === 1 && systemClient.indexOf('system setting') > -1) {
var section4 = report.match(/(actual result)([\s\S]*)(?=system setting)/gi);
var section5 = report.match(/(system setting)([\s\S]*)/gi);
var section4Clean = section4[0].replace(/(actual result(s)?(:)?)([\s\S]*)/gi, '$4');
var section5Clean = section5[0].replace(/(System Setting(s)?(:)?)([\s\S]*)/gi, '$4');
var combinedSections = section4Clean + "\n####System settings:\n" + section5Clean;
}else if(!!systemClient && systemClient.length === 1 && systemClient.indexOf('client version') > -1) {
var section4 = report.match(/(actual result)([\s\S]*)(?=client version)/gi);
var section5 = report.match(/(client version)([\s\S]*)/gi);
var section4Clean = section4[0].replace(/(actual result(s)?(:)?)([\s\S]*)/gi, '$4');
var section5Clean = section5[0].replace(/(client version(s)?(:)?)([\s\S]*)/gi, '$4');
var combinedSections = section4Clean + "\n####Client version:\n" + section5Clean;
}else if(!!systemClient && systemClient.length === 2){
var section4 = report.match(/(actual result)([\s\S]*)(?=client version)/gi);
var section4Clean = section4[0].replace(/(actual result(s)?(:)?)([\s\S]*)/gi, '$4');
if(systemClient[0] === "client version"){
var section5 = report.match(/(client version)([\s\S]*)(?=system setting)/gi);
var section5Clean = section5[0].replace(/(client version(s)?(:)?)([\s\S]*)/gi, '$4');
var section6 = report.match(/(system setting)([\s\S]*)/gi);
var section6Clean = section6[0].replace(/(system setting(s)?(:)?)([\s\S]*)/gi, '$4');
}else{
var section5 = report.match(/(system setting)([\s\S]*)(?=client version)/gi);
var section5Clean = section5[0].replace(/(system setting(s)?(:)?)([\s\S]*)/gi, '$4');
var section6 = report.match(/(client version)([\s\S]*)/gi);
var section6Clean = section6[0].replace(/(client version(s)?(:)?)([\s\S]*)/gi, '$4');
}
var combinedSections = section4Clean + "\n####System settings:\n" + section5Clean + "\n####Client version:\n" + section6Clean;
}else{
var section4 = report.match(/(actual result)([\s\S]*)/gi);
var section4Clean = section4[0].replace(/(actual result(s)?(:)?)([\s\S]*)/gi, '$4');
var combinedSections = section4Clean;
}
var section2Clean = section2[0].replace(/(steps to reproduce(s)?(:)?)([\s\S]*)/gi, '$4');
var section3Clean = section3[0].replace(/(expected result(s)?(:)?)([\s\S]*)/gi, '$4');
if(!section2){
section2.push(' ');
}else if(!section3){
section3.push(' ');
}else if(!section4){
section4.push(' ');
}
if(section2[0].indexOf(' - ') > -1){
var section2String = section2Clean.replace(/(-)\s/g, '\n$&'); // give new lines to the list
if(!section2String){
section2String.push(' ');
}
const reportString = "Reported by " + userTag + '\n\n####Steps to reproduce:' + section2String + '\n\n####Expected result:\n' + section3Clean + '\n####Actual result:\n' + combinedSections;
if(!!msg.attachments[0]){
attachment = msg.attachments[0].url;
}else{
attachment = undefined;
}
updateTrelloCard(trelloURL, attachment, channelID, reportString, '<@' + userID + '>', userTag);
}else{
bot.createMessage(channelID, "<@" + userID + "> Please format the reproduction steps correctly ` - step one - step two - step three (etc)`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + "> I can’t find that issue in Trello. Please double check the URL.").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
});
}else{
bot.createMessage(channelID, "<@" + userID + ">, you need to include `Actual Result:`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, you need to include `Expected Result:`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, you need to include `Steps to Reproduce: - step one - step two - step three (etc)`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, please include **one** pipe `|`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, only people with the role of Bug Hunter or higher can use that command, in order to prevent spam and abuse. Just ask any Bug Hunter™ and they'll be more than happy to help you out.").then(delay(config.delayInMS)).then((msg_id) => {
bot.deleteMessage(msg_id.channel.id, msg_id.id);
});
}
} // Edit an existing reports
if(command.toLowerCase() === "!submit"){ // Submit a report
var dev = msg.member.roles.indexOf(config.devRole);
var hunter = msg.member.roles.indexOf(config.hunterRole);
var admin = msg.member.roles.indexOf(config.adminRole);
if(dev > -1 || hunter > -1 || admin > -1){
var splitter = msg.content.match(/\|/g);
var joinedMessage = messageSplit.join(' ');
const pipe = joinedMessage.indexOf("|");
const header = joinedMessage.substr(0, pipe).trim();
var report = joinedMessage.substr(pipe + 1).trim();
var lowerCaseReport = report.toLowerCase();
var matchFormat = lowerCaseReport.match(/\bsteps to reproduce|expected result|actual result/gi);
if(!!splitter && splitter.length < 2){
if(!!matchFormat && matchFormat.indexOf('steps to reproduce') > -1){
if(!!matchFormat && matchFormat.indexOf('expected result') > -1){
if(!!matchFormat && matchFormat.indexOf('actual result') > -1){
var attachment;
var section2 = report.match(/(steps to reproduce)([\s\S]*)(?=expected result)/gi);
var section3 = report.match(/(expected result)([\s\S]*)(?=actual result)/gi);
var systemClient = lowerCaseReport.match(/\b(?:system setting)|\b(?:client version)/gi);
if(!!systemClient && systemClient.length === 1 && systemClient.indexOf('system setting') > -1){
var section4 = report.match(/(actual result)([\s\S]*)(?=system setting)/gi);
var section5 = report.match(/(system setting)([\s\S]*)/gi);
var section4Clean = section4[0].replace(/(actual result(s)?(:)?)([\s\S]*)/gi, '$4');
var section5Clean = section5[0].replace(/(System Setting(s)?(:)?)([\s\S]*)/gi, '$4');
var combinedSections = section4Clean + "\n####System settings:\n" + section5Clean;
var repostCombinedSections = section4Clean + "\n**System settings:**" + section5Clean;
}else if(!!systemClient && systemClient.length === 1 && systemClient.indexOf('client version') > -1){
var section4 = report.match(/(actual result)([\s\S]*)(?=client version)/gi);
var section5 = report.match(/(client version)([\s\S]*)/gi);
var section4Clean = section4[0].replace(/(actual result(s)?(:)?)([\s\S]*)/gi, '$4');
var section5Clean = section5[0].replace(/(client version(s)?(:)?)([\s\S]*)/gi, '$4');
var combinedSections = section4Clean + "\n####Client version:\n" + section5Clean;
var repostCombinedSections = section4Clean + "\n**Client version:**" + section5Clean;
}else if(!!systemClient && systemClient.length === 2){
var section4 = report.match(/(actual result)([\s\S]*)(?=client version)/gi);
var section4Clean = section4[0].replace(/(actual result(s)?(:)?)([\s\S]*)/gi, '$4');
if(systemClient[0] === "client version"){
var section5 = report.match(/(client version)([\s\S]*)(?=system setting)/gi);
var section5Clean = section5[0].replace(/(client version(s)?(:)?)([\s\S]*)/gi, '$4');
var section6 = report.match(/(system setting)([\s\S]*)/gi);
var section6Clean = section6[0].replace(/(system setting(s)?(:)?)([\s\S]*)/gi, '$4');
}else{
var section5 = report.match(/(system setting)([\s\S]*)(?=client version)/gi);
var section5Clean = section5[0].replace(/(system setting(s)?(:)?)([\s\S]*)/gi, '$4');
var section6 = report.match(/(client version)([\s\S]*)/gi);
var section6Clean = section6[0].replace(/(client version(s)?(:)?)([\s\S]*)/gi, '$4');
}
var combinedSections = section4Clean + "\n####System settings:\n" + section5Clean + "\n####Client version:\n" + section6Clean;
var repostCombinedSections = section4Clean + "\n**System settings:**" + section5Clean + "\n**Client version:**" + section6Clean;
}else{
var section4 = report.match(/(actual result)([\s\S]*)/gi);
var section4Clean = section4[0].replace(/(actual result(s)?(:)?)([\s\S]*)/gi, '$4');
var combinedSections = section4Clean;
var repostCombinedSections = section4Clean;
}
var section2Clean = section2[0].replace(/(steps to reproduce(s)?(:)?)([\s\S]*)/gi, '$4');
var section3Clean = section3[0].replace(/(expected result(s)?(:)?)([\s\S]*)/gi, '$4');
if(!section2){
section2.push(' ');
}else if(!section3){
section3.push(' ');
}else if(!section4){
section4.push(' ');
}
if(section2[0].indexOf(' - ') > -1){
var section2String = section2Clean.replace(/(-)\s/g, '\n$&'); // give new lines to the list
if(!section2String){
section2String.push(' ');
}
const reportStringSubmit = "Reported by " + userTag + '\n\n####Steps to reproduce:' + section2String + '\n\n####Expected result:\n' + section3Clean + '\n####Actual result:\n' + combinedSections;
const repostReportString = "Reported by " + userTag + "\n**Short description:** " + header + "\n**Steps to reproduce:** " + section2String + "\n**Expected result:** " + section3Clean + "\n**Actual result:** " + repostCombinedSections;
var cleanRepostReport = repostReportString.replace(/((http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)\.(?:jpg|gif|png))/gim, "");
if(!!msg.attachments[0]){
attachment = msg.attachments[0].url;
}else{
attachment = undefined;
}
if(channelID === config.iosChannel){
var listID = config.iosCard;
sendToTrello(listID, header, reportStringSubmit, channelID, attachment, "iOS", userTag, cleanRepostReport, msg.id);
}else if(channelID === config.androidChannel){
var listID = config.androidCard;
sendToTrello(listID, header, reportStringSubmit, channelID, attachment, "Android", userTag, cleanRepostReport, msg.id);
}else if(channelID === config.canaryChannel){
var listID = config.canaryCard;
sendToTrello(listID, header, reportStringSubmit, channelID, attachment, "Canary", userTag, cleanRepostReport, msg.id);
}
}else{
bot.createMessage(channelID, "<@" + userID + "> Please format the reproduction steps correctly ` - step one - step two - step three (etc)`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, you need to include `Actual Result:`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, you need to include `Expected Result:`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, you need to include `Steps to Reproduce: - step one - step two - step three (etc)`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, please include **one** pipe `|`").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}
}else{
bot.createMessage(channelID, "<@" + userID + ">, only people with the role of Bug Hunter or higher can use that command, in order to prevent spam and abuse. Just ask any Bug Hunter™ and they'll be more than happy to help you out.").then(delay(config.delayInMS)).then((msg_id) => {
bot.deleteMessage(msg_id.channel.id, msg_id.id);
});
}
}
}
});
function repro(recievedData, reproduction, channelID, trelloURL, userID, userTag, editMsgID, editMsgContent, msgID){
if(!!reproduction){
var mergedContent = reproduction + '\n' + recievedData;
}else{
var mergedContent = recievedData;
}
var sentRepro = function(error, info){
if(!!error){
bot.createMessage(channelID, "Something went wrong, please try again").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}else{
bot.createMessage(channelID, "<@" + userID + ">, your note has been added to the ticket.").then(delay(config.delayInMS)).then((msg_id) => {
bot.deleteMessage(msg_id.channel.id, msg_id.id);
bot.deleteMessage(channelID, msgID);
});
if(!!editMsgID && !!editMsgContent){
bot.editMessage(channelID, editMsgID, editMsgContent);
bot.createMessage(config.modLogChannel, "**" + userTag + "**: " + reproduction + " `" + info.data.card.name + "` <http://trello.com/c/" + info.data.card.shortLink + ">");
}else{
bot.createMessage(config.modLogChannel, "**" + userTag + "**: Added a note to `" + info.data.card.name + "` <http://trello.com/c/" + info.data.card.shortLink + ">");
}
}
}
var reproInfo = {
text: mergedContent + "\n\n" + userTag
}
t.post("/1/cards/" + trelloURL + "/actions/comments", reproInfo, sentRepro);
}
function addAttachment(channelID, attachment, cardID, userID, trelloURL, urlDateName, userTag){
var attachmentAdded = function(attachmentAddedErr, dataAttachment){
if(!!attachmentAddedErr){
bot.createMessage(channelID, "Something went wrong, please try again").then(delay(config.delayInMS)).then((innerMsg) => {
bot.deleteMessage(innerMsg.channel.id, innerMsg.id);
});
}else{
bot.createMessage(channelID, "<@" + userID + ">, your attachment has been added.").then(delay(config.delayInMS)).then((msg_id) => {
bot.deleteMessage(msg_id.channel.id, msg_id.id);
});
bot.createMessage(config.modLogChannel, "**" + userTag + "** added an attachment to `" + urlDateName + "` <https://trello.com/c/" + trelloURL + ">");
}
}
var addAttachment = {
url: attachment,
name: userTag
}
t.post('/1/cards/' + cardID + '/attachments', addAttachment, attachmentAdded);
}
function sendToTrello(listID, header, report, channelID, attachment, whereFrom, userTag, repostReportString, msgID){
var creationSuccess = function(creationSuccessErr, data) {
if(!!creationSuccessErr){
console.log(creationSuccessErr);
}
if(!!attachment){
var attachmentAdded = function(attachmentAddedErr, dataAttachment){
if(!!attachmentAddedErr){
console.log(attachmentAddedErr);
}
bot.createMessage(channelID, repostReportString + "\n<" + data.shortUrl + ">\n\n**Reproducibility:**").then(delay(config.delayInMS)).then(() => {
bot.deleteMessage(channelID, msgID);
});
bot.createMessage(config.modLogChannel, whereFrom + ": **" + userTag + "** submitted this report `" + header + "` <" + data.shortUrl + ">");
}
var addAttachment = {
url: attachment,
name: userTag
}
t.post('/1/cards/' + data.id + '/attachments', addAttachment, attachmentAdded);
}else{
bot.createMessage(channelID, repostReportString + "\n<" + data.shortUrl + ">\n\n**Reproducibility:**").then(delay(config.delayInMS)).then(() => {
bot.deleteMessage(channelID, msgID);
});
bot.createMessage(config.modLogChannel, whereFrom + ": **" + userTag + "** submitted this report `" + header + "` <" + data.shortUrl + ">");
}
};
var newCard = {
name: header,
desc: report,
idList: listID,
pos: 'top'
};
t.post('/1/cards/', newCard, creationSuccess);
}
function updateTrelloCard(cardID, attachment, channelID, report, userID, userTag){
var cardUpdated = function(error, data){
if(!!attachment){
var attachmentAdded = function(attachmentAddedErr, dataAttachment){
if(!!attachmentAddedErr){
console.log(attachmentAddedErr);
}
bot.createMessage(channelID, userID + ", the Bug Report at <" + data.shortUrl + "> has been successfully updated.");
bot.createMessage(config.modLogChannel, "**" + userTag + "** edited this report `" + data.name + "` <" + data.shortUrl + ">");
}
var addAttachment = {
url: attachment,
name: userTag
}
t.post('/1/cards/' + data.id + '/attachments', addAttachment, attachmentAdded);
}else{
bot.createMessage(channelID, userID + ", the Bug Report at <" + data.shortUrl + "> has been successfully updated.");
bot.createMessage(config.modLogChannel, "**" + userTag + "** edited this report `" + data.name + "` <" + data.shortUrl + ">");
}
}
var updateCard = {
value: report
}
t.put('/1/cards/' + cardID + '/desc', updateCard, cardUpdated);
}
bot.connect();