/
botactions.go
1631 lines (1283 loc) · 60.1 KB
/
botactions.go
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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package tiktokmod
import (
"database/sql"
"fmt"
"os"
"sort"
"strconv"
"strings"
"time"
"github.com/nlopes/slack"
"github.com/robfig/cron"
)
// BotActions - TikTokConf Actions based on commands
func BotActions(lowerString string, tiktok *TikTokConf, ev *slack.MessageEvent, rtm *slack.RTM, api *slack.Client, c *cron.Cron, cronjobs *Cronjobs, CronState string) (*cron.Cron, *Cronjobs, string) {
var attachments Attachment
var smessage string
var teamID string
var labelID string
var cardTitle string
var testPayload BotDMPayload
if strings.Contains(lowerString, "run builtin test") || strings.Contains(lowerString, "run built-in test") {
//rtm.SendMessage(rtm.NewOutgoingMessage("Running Built-In test that you built! :unicornfart:", ev.Msg.Channel))
rtm.SendMessage(rtm.NewOutgoingMessage("Currently no built-in tests!", ev.Msg.Channel))
//opts, _ := LoadConf(tiktok, "mcboard")
//SendAlert(tiktok, opts, "demo")
}
// Request that TikTokConf checks and alerts on non-active retro action item cards (this can also be CRON'd)
if strings.Contains(lowerString, "check retro action activity") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
attachments.Color = ""
attachments.Text = ""
Wrangler(tiktok.Config.SlackHook, "Checking Sprint Retro boards for action items with no activity!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to check sprint retro boards for action items with no activity on `"+teamID+"` trello board.", tiktok, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
return c, cronjobs, CronState
}
CheckActionCards(tiktok, opts, teamID)
Wrangler(tiktok.Config.SlackHook, "Check process complete.", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
}
}
// Dump Chapter Cards by column
if strings.Contains(lowerString, "chapter points") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
var columnID string
var colName string
var message string
attachments.Color = ""
attachments.Text = ""
Wrangler(tiktok.Config.SlackHook, "One sec, let me add that up!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
return c, cronjobs, CronState
}
columnID, colName = GetColumn(opts, lowerString)
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to add up chapter points on `"+teamID+"` trello board in column `"+colName+"`.", tiktok, attachments)
allChapters, noChapter, err := ChapterPoint(tiktok, opts, columnID)
if err != nil {
return c, cronjobs, CronState
}
for _, chapter := range allChapters {
message = message + "Points for " + chapter.ChapterName + " = " + strconv.Itoa(chapter.ChapterPoints) + "\n"
}
message = message + "Points not assigned to a chapter: " + strconv.Itoa(noChapter) + "\n"
attachments.Color = "#00ff00"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Chapter point counts", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
return c, cronjobs, CronState
}
}
// Check for Critical bugs when asked
if strings.Contains(lowerString, "are there any critical bugs") || strings.Contains(lowerString, "check for critical bugs") {
teamID := Between(ev.Msg.Text, "[", "]")
userInfo, _ := api.GetUserInfo(ev.Msg.User)
if teamID == "" {
teamID = "mcboard"
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to check for Critical Bugs and didn't specify a team, so defaulting to `mcboard` trello board.", tiktok, attachments)
Wrangler(tiktok.Config.SlackHook, "You didn't specify a team/trello board so I'm assuming you mean `mcboard`.", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
}
LogToSlack(userInfo.Name+" asked me to check for Critical Bugs on the "+teamID+" trello board.", tiktok, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
return c, cronjobs, CronState
}
attachments.Color = ""
attachments.Text = ""
Wrangler(tiktok.Config.SlackHook, "One sec, I will check and then alert the "+opts.General.ComplaintChannel+" channel if I find any.", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
numBug := CheckBugs(opts, tiktok)
if numBug == 0 {
Wrangler(tiktok.Config.SlackHook, "I didn't find any critical bugs, Sweet!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
Wrangler(tiktok.Config.SlackHook, "I found a critical bug quantity of "+strconv.Itoa(numBug)+"!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
}
return c, cronjobs, CronState
}
// Dump Chapter Cards by column into the Database - defaults to backlog if no column specified
if strings.Contains(lowerString, "record chapter count ") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
var colName string
attachments.Color = ""
attachments.Text = ""
Wrangler(tiktok.Config.SlackHook, "One sec, let me add that up and record it to the database!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
return c, cronjobs, CronState
}
_, colName = GetColumn(opts, lowerString)
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to record in the DB the card count on chapter cards on `"+teamID+"` trello board in column `"+colName+"`.", tiktok, attachments)
err = RecordChapters(tiktok, teamID, colName)
if err != nil {
Wrangler(tiktok.Config.SlackHook, "Something went wrong, please check the logs in the log channel #"+tiktok.Config.LogChannel, ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
return c, cronjobs, CronState
}
Wrangler(tiktok.Config.SlackHook, "Data recorded!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
return c, cronjobs, CronState
}
}
// Dump Chapter Cards by column
if strings.Contains(lowerString, "check chapters") || strings.Contains(lowerString, "chapter count ") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
var columnID string
var colName string
var message string
attachments.Color = ""
attachments.Text = ""
Wrangler(tiktok.Config.SlackHook, "One sec, let me add that up!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
return c, cronjobs, CronState
}
columnID, colName = GetColumn(opts, lowerString)
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to add report on chapter cards on `"+teamID+"` trello board in column `"+colName+"`.", tiktok, attachments)
allChapters, totalCards, err := ChapterCount(tiktok, opts, columnID)
if err != nil {
return c, cronjobs, CronState
}
for _, chapter := range allChapters {
message = message + "Cards for " + chapter.ChapterName + " = " + strconv.Itoa(chapter.ChapterCount) + "\n"
}
message = message + "Total Cards in column " + colName + " = " + strconv.Itoa(totalCards) + "\n"
attachments.Color = "#00ff00"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Chapter card counts", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
return c, cronjobs, CronState
}
}
// Grab Card Timing Data on Command
if strings.Contains(lowerString, "get card data") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to get all the card timing data on `"+teamID+"` trello board", tiktok, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("I couldn't find the team config file ("+teamID+".toml) you asked for!.", ev.Msg.Channel))
return c, cronjobs, CronState
}
rtm.SendMessage(rtm.NewOutgoingMessage("Attempting to pull card timing data.\n*Warning* This can take several minutes, please wait patiently. :knuckles_waiting:", ev.Msg.Channel))
if strings.Contains(lowerString, "DB ONLY") {
CardPlay(tiktok, opts, ev.Msg.Channel, teamID, false)
} else {
CardPlay(tiktok, opts, ev.Msg.Channel, teamID, true)
}
LogToSlack("Completed retrieving card timing on `"+teamID+"` trello board for "+userInfo.Name, tiktok, attachments)
}
}
// Check That cards have a Theme
if strings.Contains(lowerString, "check themes") {
var amessage string
var temp string
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to verify Theme labels on `"+teamID+"` trello board", tiktok, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("I couldn't find the team config file ("+teamID+".toml) you asked for!.", ev.Msg.Channel))
return c, cronjobs, CronState
}
temp, _ = CheckThemes(tiktok, opts, opts.General.Upcoming)
amessage = amessage + temp
temp, _ = CheckThemes(tiktok, opts, opts.General.Scoped)
amessage = amessage + temp
temp, _ = CheckThemes(tiktok, opts, opts.General.ReadyForWork)
amessage = amessage + temp
if amessage != "" {
attachments.Color = "#ff0000"
attachments.Text = amessage
Wrangler(tiktok.Config.SlackHook, "*WARNING*! The following cards do *not* have appropriate Theme Labels on them: ", opts.General.ComplaintChannel, tiktok.Config.SlackEmoji, attachments)
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("Hurray all cards have theme labels!", ev.Msg.Channel))
}
}
}
// Retrieve Previous Card Description
if strings.Contains(lowerString, "description history ") {
var cardID string
var msgBreak []string
amessage := ""
if strings.Contains(strings.ToLower(lowerString), "@"+strings.ToLower(tiktok.Config.BotID)) {
msgBreak = strings.SplitAfterN(lowerString, " ", 4)
if len(msgBreak) != 4 {
rtm.SendMessage(rtm.NewOutgoingMessage("I'm not sure what you are asking me to do.", ev.Msg.Channel))
return c, cronjobs, CronState
}
cardID = msgBreak[3]
} else {
msgBreak = strings.SplitAfterN(lowerString, " ", 3)
if len(msgBreak) != 3 {
rtm.SendMessage(rtm.NewOutgoingMessage("I'm not sure what you are asking me to do.", ev.Msg.Channel))
return c, cronjobs, CronState
}
cardID = msgBreak[2]
}
descHistory, err := GetDescHistory(tiktok, cardID)
if err != nil {
errTrap(tiktok, "Error in retrieve card description history for card "+cardID+" function GetDescHistory in trello.go", err)
return c, cronjobs, CronState
}
// Build message
if len(descHistory) > 0 {
cardTitle = descHistory[0].Data.Card.Name
}
userInfo, _ := api.GetUserInfo(ev.Msg.User)
for _, dh := range descHistory {
amessage = amessage + "*Date:* " + dh.Date.Format("2006-01-02 15:04:05\n")
amessage = amessage + "*Editor:* " + dh.MemberCreator.FullName + "\n"
amessage = amessage + "*Desc:* " + dh.Data.Card.Desc + "\n\n"
}
testPayload.Text = "Description history for requested card (" + cardTitle + "): "
testPayload.Channel = userInfo.ID
attachments.Color = "#00ff00"
attachments.Text = amessage
testPayload.Attachments = append(testPayload.Attachments, attachments)
err = WranglerDM(tiktok, testPayload)
if err != nil {
errTrap(tiktok, "Issue sending Direct Slack message to "+userInfo.Name+" when card history was requested.", err)
rtm.SendMessage(rtm.NewOutgoingMessage("Issue sending Direct Slack message to "+userInfo.Name+" when card history was requested for `"+cardTitle+"`!", ev.Msg.Channel))
return c, cronjobs, CronState
}
rtm.SendMessage(rtm.NewOutgoingMessage("I have DM'd you the history description of the card `"+cardTitle+"`!", ev.Msg.Channel))
}
// Retrieve Holiday List
if strings.Contains(strings.ToLower(lowerString), "company holidays") {
var holidaymsg string
var year string
if strings.Contains(strings.ToLower(lowerString), "company holidays all") {
year = "0"
} else {
t := time.Now()
year = t.Format("2006")
}
holiday, err := GetHoliday(tiktok, year)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("Sorry this data was unavailable, please check my logs.", ev.Msg.Channel))
if tiktok.Config.LogToSlack {
LogToSlack("Error retrieving Holiday dates from DB. "+err.Error(), tiktok, attachments)
}
return c, cronjobs, CronState
}
for _, h := range holiday {
holidayDate := h.Day.Format("01/02/2006")
holidaymsg = holidaymsg + holidayDate + " - " + h.Name + "\n"
}
attachments.Color = "#0000ff"
attachments.Text = holidaymsg
Wrangler(tiktok.Config.SlackHook, "Known Holidays for "+year+":", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
}
// Record todays points
if strings.Contains(lowerString, "record points for") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
userInfo, _ := api.GetUserInfo(ev.Msg.User)
if Permissions(tiktok, ev.Msg.User, "scrum", api, tiktok.Config.ScrumControlChannel) {
LogToSlack(userInfo.Name+" asked me to record all board points for "+teamID+".", tiktok, attachments)
rtm.SendMessage(rtm.NewOutgoingMessage("Permissions accepted. Checking points for ["+teamID+"] this may take a moment.", ev.Msg.Channel))
opts, _ := LoadConf(tiktok, teamID)
sOpts, _ := GetDBSprint(tiktok, teamID)
message, valid := GetAllPoints(tiktok, opts, sOpts)
if valid {
hmessage := "Recording today's sprint points for *" + opts.General.TeamName + "*\n"
rtm.SendMessage(rtm.NewOutgoingMessage(hmessage+message, ev.Msg.Channel))
}
} else {
smessage = "You are not the boss of me! Permission denied."
rtm.SendMessage(rtm.NewOutgoingMessage(smessage, ev.Msg.Channel))
LogToSlack(userInfo.Name+" asked me to record todays points for "+teamID+" but did not have permissions so I ignored them.", tiktok, attachments)
}
}
}
// Counting Cards - Record Theme Card #'s for reporting
if strings.Contains(lowerString, "count cards") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to count up the Theme cards on `"+teamID+"` trello board.", tiktok, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("I couldn't find the team config file ("+teamID+".toml) you asked for!.", ev.Msg.Channel))
return c, cronjobs, CronState
}
attachments.Color = ""
attachments.Text = ""
Wrangler(tiktok.Config.SlackHook, "Hold please while I count some cards!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
allThemes, err := CountCards(opts, tiktok, teamID)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("Hrm, something went a foul, please check the logs.", ev.Msg.Channel))
return c, cronjobs, CronState
}
// Should Sort Array DESC by points
sort.Slice(allThemes, func(i, j int) bool {
return allThemes[i].Pts > allThemes[j].Pts
})
amessage := ""
for _, s := range allThemes {
amessage = amessage + "Total `" + s.Name + "` Cards: " + strconv.Itoa(s.Pts) + "\n"
}
attachments.Color = "#0000ff"
attachments.Text = amessage
Wrangler(tiktok.Config.SlackHook, "Number of cards per theme (label) in `Un-Scoped` and `Ready for Points` on "+opts.General.TeamName+" board:", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
}
}
// Add up Theme Points
if strings.Contains(lowerString, "theme points") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
var columnID string
var colName string
var myInt int
var myPerc float64
attachments.Color = ""
attachments.Text = ""
Wrangler(tiktok.Config.SlackHook, "One sec, let me add that up!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("I couldn't find the team config file ("+teamID+".toml) you asked for!.", ev.Msg.Channel))
return c, cronjobs, CronState
}
// check which column was specified if any
lowString := strings.ToLower(lowerString)
if strings.Contains(lowString, "next sprint") {
columnID = opts.General.NextsprintID
colName = "Next Sprint"
} else if strings.Contains(lowString, "ready for points") {
columnID = opts.General.Scoped
colName = "Ready for Points"
} else if strings.Contains(lowString, "ready for work") {
columnID = opts.General.ReadyForWork
colName = "Ready for Work"
} else {
columnID = opts.General.NextsprintID
colName = "Next Sprint"
}
// check if total points was specified for % calcs
tP := Between(ev.Msg.Text, "{", "}")
if tP != "" {
myInt, err = strconv.Atoi(tP)
if err != nil {
errTrap(tiktok, "Integer Conversion Error", err)
rtm.SendMessage(rtm.NewOutgoingMessage("There's an issue with what you specified in { } as total points. This must be an integer! You specified: "+tP, ev.Msg.Channel))
return c, cronjobs, CronState
}
}
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to add up the Theme points on `"+teamID+"` trello board in column `"+colName+"`.", tiktok, attachments)
allThemes, err := ThemePoints(opts, tiktok, columnID)
if err != nil {
errTrap(tiktok, "Trello Error", err)
rtm.SendMessage(rtm.NewOutgoingMessage("There seems to be an issue with this RetroID in Trello, I can't retrieve this information. ("+err.Error()+")", ev.Msg.Channel))
return c, cronjobs, CronState
}
// Should Sort Array DESC by points
sort.Slice(allThemes, func(i, j int) bool {
return allThemes[i].Pts > allThemes[j].Pts
})
// Grab ignore labels
ignoreLabels, err := GetIgnoreLabels(tiktok, opts.General.BoardID)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("Gack there was an error! ("+err.Error()+")", ev.Msg.Channel))
return c, cronjobs, CronState
}
// Build Output
amessage := ""
for _, s := range allThemes {
if SliceExists(tiktok, ignoreLabels, s.ID) {
if tiktok.Config.DEBUG {
fmt.Println("Skipping " + s.Name)
}
} else {
if tP != "" {
deci := float64(s.Pts) / float64(myInt)
myPerc = deci * 100.0
amessage = amessage + "Total `" + s.Name + "` Points: " + strconv.Itoa(s.Pts) + " - (" + strconv.FormatFloat(myPerc, 'f', 0, 64) + "%)\n"
} else {
amessage = amessage + "Total `" + s.Name + "` Points: " + strconv.Itoa(s.Pts) + "\n"
}
}
}
attachments.Color = "#0000ff"
attachments.Text = amessage
Wrangler(tiktok.Config.SlackHook, "Points per label (Theme) in `"+colName+"` on "+opts.General.TeamName+" board:", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
}
}
// Check sprint points for previous sprint (squads and totals)
// @tiktok previous sprint points [mcboard] mcboard-07-25-2018
if strings.Contains(lowerString, "previous sprint points") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team inside the [ ]\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
var msgBreak []string
var locale int
var amessage string
var myTotal int
//break down message
if strings.Contains(strings.ToLower(lowerString), "@"+strings.ToLower(tiktok.Config.BotID)) {
msgBreak = strings.SplitAfterN(lowerString, " ", 6)
if len(msgBreak) != 6 {
rtm.SendMessage(rtm.NewOutgoingMessage("I'm not sure what you are asking me to do.", ev.Msg.Channel))
return c, cronjobs, CronState
}
locale = 5
} else {
msgBreak = strings.SplitAfterN(lowerString, " ", 5)
if len(msgBreak) != 5 {
rtm.SendMessage(rtm.NewOutgoingMessage("I'm not sure what you are asking me to do.", ev.Msg.Channel))
return c, cronjobs, CronState
}
locale = 4
}
opts, err := LoadConf(tiktok, teamID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID in `previous sprint points` command "+teamID, err)
return c, cronjobs, CronState
}
sprintLow := strings.ToLower(msgBreak[locale])
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to retrieve the squad points for previous sprint `"+sprintLow+"` on `"+teamID+"` trello board", tiktok, attachments)
attachments.Color = ""
attachments.Text = ""
Wrangler(tiktok.Config.SlackHook, "Let me grab the point data for `"+sprintLow+"`!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
myTotal = 0
SprintPoints, err := GetPreviousSprintPoints(tiktok, sprintLow)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("Something went totally wrong, please check the logs.", ev.Msg.Channel))
} else {
amessage = ""
for _, s := range SprintPoints {
amessage = amessage + "Total `" + s.SquadName + "` Points: " + strconv.Itoa(s.SprintPoints) + "\n"
myTotal = myTotal + s.SprintPoints
}
amessage = amessage + "Total Sprint Points:" + strconv.Itoa(myTotal)
attachments.Color = "#0000ff"
attachments.Text = amessage
Wrangler(tiktok.Config.SlackHook, "Points per squad for sprint `"+sprintLow+"` on "+opts.General.TeamName+" board:", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
}
}
}
// Add up squad points
if strings.Contains(lowerString, "squad points") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
var columnID string
var colName string
attachments.Color = ""
attachments.Text = ""
Wrangler(tiktok.Config.SlackHook, "One sec, let me add that up!", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
opts, err := LoadConf(tiktok, teamID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
return c, cronjobs, CronState
}
// check which column was specified if any
lowString := strings.ToLower(lowerString)
if strings.Contains(lowString, "next sprint") {
columnID = opts.General.NextsprintID
colName = "Next Sprint"
} else if strings.Contains(lowString, "ready for points") {
columnID = opts.General.Scoped
colName = "Ready for Points"
} else if strings.Contains(lowString, "ready for work") {
columnID = opts.General.ReadyForWork
colName = "Ready for Work"
} else if strings.Contains(lowString, "working") {
columnID = opts.General.Working
colName = "Working"
} else {
columnID = opts.General.NextsprintID
colName = "Next Sprint"
}
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to add up the squad points on `"+teamID+"` trello board in column `"+colName+"`.", tiktok, attachments)
allSquads, nonPoints, err := SquadPoints(columnID, opts, tiktok)
amessage := ""
for _, s := range allSquads {
if opts.General.BoardID == s.BoardID {
amessage = amessage + "Total `" + s.Squadname + "` Points: " + strconv.Itoa(s.SquadPts) + "\n"
}
}
amessage = amessage + "Total Points not assigned to a squad: " + strconv.Itoa(nonPoints) + "\n"
attachments.Color = "#0000ff"
attachments.Text = amessage
Wrangler(tiktok.Config.SlackHook, "Points per squad in `"+colName+"` on "+opts.General.TeamName+" board:", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
}
}
// List retro board
if strings.Contains(lowerString, "retro board") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
message := ListAllTOML(tiktok)
attachments.Color = "#0000CC"
attachments.Text = message
Wrangler(tiktok.Config.SlackHook, "Please specify team in [ ] - Like `@"+tiktok.Config.BotName+" retro [mcboard]`\nHere's a list: ", ev.Msg.Channel, tiktok.Config.SlackEmoji, attachments)
} else {
sOpts, err := GetDBSprint(tiktok, teamID)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("Sorry I couldn't find what you were asking for! - ", ev.Msg.Channel))
return c, cronjobs, CronState
}
allTheThings, err := RetrieveAll(tiktok, sOpts.RetroID, "none")
if err != nil {
errTrap(tiktok, "Error from `RetrieveAll` getting board info in `botactions.go` retro board command ", err)
rtm.SendMessage(rtm.NewOutgoingMessage("There seems to be an issue with this RetroID in Trello, I can't retrieve this information. Please see logs.", ev.Msg.Channel))
return c, cronjobs, CronState
}
message := "The current sprint reto board for `" + sOpts.SprintName + "` is <" + allTheThings.ShortURL + "|" + allTheThings.Name + ">"
rtm.SendMessage(rtm.NewOutgoingMessage(message, ev.Msg.Channel))
}
}
// List all cards in PR Column
ls := strings.ToLower(lowerString)
if strings.Contains(ls, "list pr") || strings.Contains(ls, "open pr") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
rtm.SendMessage(rtm.NewOutgoingMessage("I did not understand which board you want, sorry.", ev.Msg.Channel))
} else {
opts, err := LoadConf(tiktok, teamID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
} else {
userInfo, err := api.GetUserInfo(ev.Msg.User)
if err != nil {
errTrap(tiktok, "api.GetUserInfo function error returned in `botactions.go`", err)
}
LogToSlack(userInfo.Name+" asked me to list the PR's on `"+teamID+"` trello board.", tiktok, attachments)
output, err := PRSummary(opts, tiktok)
if err != nil {
errTrap(tiktok, "PRSummary function error returned in `botactions.go`", err)
return c, cronjobs, CronState
}
if output == "" {
rtm.SendMessage(rtm.NewOutgoingMessage("Dumping list of PRs to main Slack channel, per your request.", ev.Msg.Channel))
} else {
rtm.SendMessage(rtm.NewOutgoingMessage(output, ev.Msg.Channel))
}
}
}
}
// Dupe a board
if strings.Contains(lowerString, "dupe trello board") || strings.Contains(lowerString, "copy trello board") {
teamID := Between(ev.Msg.Text, "[", "]")
if teamID == "" {
rtm.SendMessage(rtm.NewOutgoingMessage("I did not understand which board you want, sorry.", ev.Msg.Channel))
} else {
opts, err := LoadConf(tiktok, teamID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("Hold please, attempting to dupe it up.", ev.Msg.Channel))
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to make a dupe of the `"+teamID+"` trello board, so I'm doing that.", tiktok, attachments)
allTheThings, err := RetrieveAll(tiktok, opts.General.BoardID, "none")
if err != nil {
errTrap(tiktok, "Error from `RetrieveAll` getting board info in `botactions.go` dupe trello board command ", err)
rtm.SendMessage(rtm.NewOutgoingMessage("There seems to be an issue with this request in Trello, I can't retrieve this information. Please see logs.", ev.Msg.Channel))
return c, cronjobs, CronState
}
rightnow := time.Now().Local()
nameDate := rightnow.Format("01-02-06")
dupeName := "DUPE-" + nameDate + ": " + allTheThings.Name
output, _ := DupeTrelloBoard(allTheThings.ID, dupeName, opts.General.TrelloOrg, tiktok)
if tiktok.Config.DEBUG {
fmt.Println(output)
}
if tiktok.Config.LogToSlack {
LogToSlack(output, tiktok, attachments)
}
rtm.SendMessage(rtm.NewOutgoingMessage(output, ev.Msg.Channel))
}
}
}
// Reload Cron Jobs from file
if strings.Contains(lowerString, "reload cron") || strings.Contains(lowerString, "re-load cron") || strings.Contains(lowerString, "reload all cron") {
userInfo, err := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to re-load all the CRONJobs, so I'm attempting that.", tiktok, attachments)
c.Stop()
CronState = "Halted"
cronjobs, c, err = CronLoad(tiktok)
if err != nil {
errTrap(tiktok, "CRON Jobs failed to load due to file error.", err)
rtm.SendMessage(rtm.NewOutgoingMessage("CRON Jobs failed to load due to file error.", ev.Msg.Channel))
} else {
if tiktok.Config.DEBUG {
fmt.Println("CRON Jobs were re-loaded from file!")
}
rtm.SendMessage(rtm.NewOutgoingMessage("CRON Jobs were re-loaded!", ev.Msg.Channel))
CronState = "Running"
}
}
// List Cron Jobs from file
if strings.Contains(lowerString, "list all cronjobs") || strings.Contains(lowerString, "show me all cronjobs") || strings.Contains(lowerString, "list cronjobs") {
var message string
var attachments Attachment
if CronState == "Not Loaded" {
rtm.SendMessage(rtm.NewOutgoingMessage("The Cron State is currently not loaded. Please Reload it!", ev.Msg.Channel))
return c, cronjobs, CronState
}
userInfo, _ := api.GetUserInfo(ev.Msg.User)
message = "Existing Cron State is: `" + CronState + "`\n"
message = message + "```"
for _, cr := range cronjobs.Cronjob {
opts, err := LoadConf(tiktok, cr.Config)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
}
message = message + cr.Timing + " - " + opts.General.TeamName + " - " + cr.Action + "\n"
}
message = message + "```"
testPayload.Text = "Current Running Cron Jobs"
testPayload.Channel = userInfo.ID
attachments.Color = "#0c15dd"
attachments.Text = message
testPayload.Attachments = append(testPayload.Attachments, attachments)
err := WranglerDM(tiktok, testPayload)
if err != nil {
return c, cronjobs, CronState
}
rtm.SendMessage(rtm.NewOutgoingMessage("I have DM'd you the current cron jobs, lucky you!", ev.Msg.Channel))
}
// New Sprint Setup
if strings.Contains(lowerString, "start a new sprint") {
var rboard bool
smessage = ""
boardID := Between(ev.Msg.Text, "[", "]")
if boardID == "" {
rtm.SendMessage(rtm.NewOutgoingMessage("I did not understand which team you want, sorry.", ev.Msg.Channel))
} else {
userInfo, _ := api.GetUserInfo(ev.Msg.User)
LogToSlack(userInfo.Name+" asked me to run a new sprint for the "+boardID+" configuration.", tiktok, attachments)
if Permissions(tiktok, ev.Msg.User, "admin", api, tiktok.Config.ScrumControlChannel) {
opts, err := LoadConf(tiktok, boardID)
if err != nil {
errTrap(tiktok, "Load Conf Error for TeamID "+teamID, err)
rtm.SendMessage(rtm.NewOutgoingMessage("I couldn't find the team config file ("+boardID+".toml) you asked for!.", ev.Msg.Channel))
} else {
if strings.Contains(lowerString, "suppress retro") {
rboard = true
smessage = smessage + "I will supress creation of a Retro board\n"
} else {
rboard = false
}
smessage = smessage + "Permissions accepted, attempting to Sprint it up!"
rtm.SendMessage(rtm.NewOutgoingMessage(smessage, ev.Msg.Channel))
returnMsg, _ := Sprint(opts, tiktok, rboard)
rtm.SendMessage(rtm.NewOutgoingMessage(returnMsg, ev.Msg.Channel))
}
} else {
smessage = "You are not the boss of me! Permission denied."
rtm.SendMessage(rtm.NewOutgoingMessage(smessage, ev.Msg.Channel))
if tiktok.Config.LogToSlack {
LogToSlack(userInfo.Name+" does not have the appropriate permissions and was told to `get bent`.", tiktok, attachments)
}
}
}
}
// STOP Cron Jobs
if strings.Contains(lowerString, "stop all cron") || strings.Contains(lowerString, "shutdown all cron") || strings.Contains(lowerString, "halt all cron") {
userInfo, _ := api.GetUserInfo(ev.Msg.User)
if Permissions(tiktok, ev.Msg.User, "scrum", api, tiktok.Config.ScrumControlChannel) {
smessage = "Permissions accepted. Halting all Cron Jobs!"
rtm.SendMessage(rtm.NewOutgoingMessage(smessage, ev.Msg.Channel))
LogToSlack(userInfo.Name+" asked me to halt all Cron Jobs so I did.", tiktok, attachments)
CronState = "Halted"
c.Stop()
} else {
smessage = "You are not the boss of me! Permission denied."
rtm.SendMessage(rtm.NewOutgoingMessage(smessage, ev.Msg.Channel))
LogToSlack(userInfo.Name+" asked me to halt all Cron Jobs but did not have permissions so I ignored them.", tiktok, attachments)
}
}
// Shutdown
if strings.Contains(lowerString, "shutdown please") {
userInfo, _ := api.GetUserInfo(ev.Msg.User)
if Permissions(tiktok, ev.Msg.User, "admin", api, tiktok.Config.AdminSlackChannel) {
smessage = "Permissions accepted. Okay logging off bye!"
rtm.SendMessage(rtm.NewOutgoingMessage(smessage, ev.Msg.Channel))
LogToSlack(userInfo.Name+" asked me to shutdown, so I am.", tiktok, attachments)
duration := time.Duration(4) * time.Second
time.Sleep(duration)
os.Exit(0)
} else {
smessage = "You are not the boss of me! Permission denied."
rtm.SendMessage(rtm.NewOutgoingMessage(smessage, ev.Msg.Channel))
LogToSlack(userInfo.Name+" asked me to shut down, but did not have permissions so I ignored them.", tiktok, attachments)
}
}
// Build a config file
if strings.Contains(lowerString, "build a configuration file") {
boardID := Between(ev.Msg.Text, "[", "]")
BuildConfig(boardID, tiktok, ev.Msg.User, api)
rtm.SendMessage(rtm.NewOutgoingMessage("Okay, I Direct Messaged your config to you.", ev.Msg.Channel))
}
// TROLL the board
if strings.Contains(lowerString, "troll team") || strings.Contains(lowerString, "troll board") {
attachments.Text = ""
attachments.Color = ""
teamID = Between(ev.Msg.Text, "[", "]")
if teamID == "" {
rtm.SendMessage(rtm.NewOutgoingMessage("I did not understand which team you want, sorry.", ev.Msg.Channel))
} else {
opts, err := LoadConf(tiktok, teamID)
userInfo, _ := api.GetUserInfo(ev.Msg.User)