-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
1889 lines (1685 loc) · 79.7 KB
/
commands.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 main
import (
"encoding/hex"
"fmt"
"log"
"strconv"
"strings"
"time"
"unicode/utf8"
"github.com/bwmarrin/discordgo"
"github.com/deefstes/ClanEventsBot/database"
"github.com/deefstes/ClanEventsBot/logging"
)
//gocyclo:ignore
// BotHelp is used to display a list of available commands or instructions on using a specified command
func BotHelp(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
if len(command) == 1 {
command = append(command, "nothing")
}
message := fmt.Sprintf("Need some help with the __%s__ command? EventsBot is happy to oblige :nerd:", command[1])
switch command[1] {
case "nothing":
message = "```\r\nList of EventsBot commands:"
message = fmt.Sprintf("%s\r\n %slistevents", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %sdetails", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %snew", message, config.CommandPrefix)
// message = fmt.Sprintf("%s\r\n %snewevent", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %scancel", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %sedit", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %srename", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %ssignup", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %sleave", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %swisdom", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %slisttimezones", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n\r\nCommands that require Admin priviledges", message)
message = fmt.Sprintf("%s\r\n %saddserver", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %saddtimezone", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %sremovetimezone", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n %sroletimezone", message, config.CommandPrefix)
//message = fmt.Sprintf("%s\r\n %simpersonate", message, config.CommandPrefix)
//message = fmt.Sprintf("%s\r\n %sunimpersonate", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n```", message)
message = fmt.Sprintf("%sYou can get help on any of these commands by typing %shelp followed by the name of the command", message, config.CommandPrefix)
case "listevents":
message = fmt.Sprintf("%s\r\nHere's how to get a list of upcoming events:", message)
message = fmt.Sprintf("%s\r\n```\r\n%slistevents [Date] [@Username]\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n Date: The date for which you want to see events. This value is optional", message)
message = fmt.Sprintf("%s\r\n @Username: The Discord user for which you want to see events. This value is optional.", message)
message = fmt.Sprintf("%s\r\n\r\nNote: Both the date and username values are optional. You can specify either, neither or both but then they must be in the order shown above. If you omit the date, you will be shown all upcoming events and if you omit the user you will be shown events for all users.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "details":
message = fmt.Sprintf("%s\r\nHere's how to get details for an event:", message)
message = fmt.Sprintf("%s\r\n```\r\n%sdetails EventID\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n EventID: That weird looking 4 character identifier that uniquely identifies the event. Take care to get it right. It's your key to participation, enjoyment and a deeper level of zen.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "new":
message = fmt.Sprintf("%s\r\nHere's how to create a new event (interactive mode):", message)
message = fmt.Sprintf("%s\r\n```\r\n%snew Name\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n Name: A name for your event.", message)
message = fmt.Sprintf("%s\r\n```", message)
message = fmt.Sprintf("%s\r\nHere's an example for you:", message)
message = fmt.Sprintf("%s\r\n```\r\n%snew Last Wish Training Raid\r\n```", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\nThis will create an event named \"Last Wish Training Raid\" and the bot will prompt you for the remaining values required.", message)
case "newevent":
message = fmt.Sprintf("%s\r\n* * * NOTICE * * *", message)
message = fmt.Sprintf("%s\r\nThis command has been deprecated. Consider rather using **%snew**", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\nHere's how to create a new event (explicit mode):", message)
message = fmt.Sprintf("%s\r\n```\r\n%snewevent Date Time (TimeZone) Duration Name Description Size\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n Date: In the format DD/MM/YYYY", message)
message = fmt.Sprintf("%s\r\n Time: In the format HH:MM (24 hour clock)", message)
message = fmt.Sprintf("%s\r\n TimeZone: A time zone abbreviation between brackets", message)
message = fmt.Sprintf("%s\r\n Duration: Number of hours the event will last", message)
message = fmt.Sprintf("%s\r\n Name: A name for your event. Surround it in quotes if it's more than one word", message)
message = fmt.Sprintf("%s\r\nDescription: A longer description of your event. You totally want to surround this one in quotes", message)
message = fmt.Sprintf("%s\r\n TeamSize: Just a number denoting how many players can sign up", message)
message = fmt.Sprintf("%s\r\n\r\nNote: Specifying a time zone is optional, as can be seen in the example below. If no time zone is specified, the role default time zone will be used.", message)
message = fmt.Sprintf("%s\r\n```", message)
message = fmt.Sprintf("%s\r\nHere's an example for you:", message)
message = fmt.Sprintf("%s\r\n```\r\n%snewevent %s 20:00 2 \"Normal Leviathan\" \"Fresh start of Leviathan raid\" 6\r\n```", message, config.CommandPrefix, time.Now().Format("02/01/2006"))
message = fmt.Sprintf("%s\r\nThis will create a 2 hour event to start at 8pm tonight and which will allow 6 people to sign up", message)
case "edit":
message = fmt.Sprintf("%s\r\nHere's how to edit an event:", message)
message = fmt.Sprintf("%s\r\n```\r\n%sedit EventID\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n EventID: That weird looking 4 character identifier that uniquely identifies the event. Take care to get it right. It's your key to participation, enjoyment and a deeper level of zen.", message)
message = fmt.Sprintf("%s\r\nThis will bring up an interactive message allowing you to edit the", message)
message = fmt.Sprintf("%s\r\n\r\nNote: Only the creator of an event or users with the EventsBotAdmin role assigned can edit an event.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "rename":
message = fmt.Sprintf("%s\r\nHere's how to rename an event:", message)
message = fmt.Sprintf("%s\r\n```\r\n%srename EventID Name\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n EventID: That weird looking 4 character identifier that uniquely identifies the event. Take care to get it right. It's your key to participation, enjoyment and a deeper level of zen.", message)
message = fmt.Sprintf("%s\r\n Name: New name to be used for the event.", message)
message = fmt.Sprintf("%s\r\n\r\nNote: Only the creator of an event or users with the EventsBotAdmin role assigned can edit an event.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "cancel":
message = fmt.Sprintf("%s\r\nHere's how to cancel an event:", message)
message = fmt.Sprintf("%s\r\n```\r\n%scancel EventID\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n EventID: That weird looking 4 character identifier that uniquely identifies the event. Take care to get it right. It's your key to participation, enjoyment and a deeper level of zen.", message)
message = fmt.Sprintf("%s\r\n\r\nNote: Only the creator of an event or users with the EventsBotAdmin role assigned can cancel an event.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "signup":
message = fmt.Sprintf("%s\r\nHere's how to sign up to an event:", message)
message = fmt.Sprintf("%s\r\n```\r\n%ssignup EventID [@Username] [@Username] ...\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n EventID: That weird looking 4 character identifier that uniquely identifies the event. Take care to get it right. It's your key to participation, enjoyment and a deeper level of zen.", message)
message = fmt.Sprintf("%s\r\n @Username: List of Discord users whom you wish to sign up to the event. Only the event creator and users with the EventsBotAdmin role assigned are allowed to sign users other than themselves up to an event. This value is optional.", message)
message = fmt.Sprintf("%s\r\n\r\nNote: You can still sign up to an event even if it is already full. You will then be registered as a reserve for the event and promoted if someone leaves the event.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "leave":
message = fmt.Sprintf("%s\r\nHere's how to leave an event:", message)
message = fmt.Sprintf("%s\r\n```\r\n%sleave EventID [@Username]\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n EventID: That weird looking 4 character identifier that uniquely identifies the event. Take care to get it right. It's your key to participation, enjoyment and a deeper level of zen.", message)
message = fmt.Sprintf("%s\r\n @Username: The Discord user whom you wish to remove from the event. Only the event creator and users with the EventsBotAdmin role assigned are allowed to remove users other than themselves from an event. This value is optional.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "impersonate":
message = fmt.Sprintf("%s\r\nHere's how to impersonate a user:", message)
message = fmt.Sprintf("%s\r\n```\r\n%simpersonate @Username\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n @Username: The Discord user you wish to impersonate", message)
message = fmt.Sprintf("%s\r\n\r\nNote: This will have the effect of any further commands you issue, until you've issued %sunimpersonate, behaving as if they originated from the specified user. This is dangerous of course and so only users with the EventsBotAdmin role assigned are allowed to issue this command. You have been warned.", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n```", message)
case "unimpersonate":
message = fmt.Sprintf("%s\r\nHere's how to stop impersonating a user:", message)
message = fmt.Sprintf("%s\r\n```\r\n%sunimpersonate\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%sYes, it's that simple", message)
message = fmt.Sprintf("%s\r\n```", message)
case "wisdom":
message = fmt.Sprintf("%s\r\nHere's how to obtain a nugget of wisdom:", message)
message = fmt.Sprintf("%s\r\n```\r\n%swisdom\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%sYes, it's that simple. Just ask and you shall receive.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "addnaughtylist":
message = fmt.Sprintf("%s\r\nHere's how to add a user to the naughty list:", message)
message = fmt.Sprintf("%s\r\n```\r\n%saddnaughtylist @Username\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n @Username: The Discord user you wish to add to the naughty list", message)
message = fmt.Sprintf("%s\r\n```", message)
case "removenaughtylist":
message = fmt.Sprintf("%s\r\nHere's how to remove a user from the naughty list:", message)
message = fmt.Sprintf("%s\r\n```\r\n%sremovenaughtylist @Username\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n @Username: The Discord user you wish to remove from the naughty list", message)
message = fmt.Sprintf("%s\r\n```", message)
case "remindnaughtylist":
message = fmt.Sprintf("%s\r\nHere's how to set the naughty list reminder frequency:", message)
message = fmt.Sprintf("%s\r\n```\r\n%sremindnaughtylist Interval RandomFactor\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n Interval: The interval in minutes between messages", message)
message = fmt.Sprintf("%s\r\n RandomFactor: The factor (decimal value between 0 and 1 to randomise the interval by", message)
message = fmt.Sprintf("%s\r\n```", message)
case "addserver":
message = fmt.Sprintf("%s\r\nHere's how to add a server to EventsBot:", message)
message = fmt.Sprintf("%s\r\n```\r\n%saddserver\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%sYes, it's that simple", message)
message = fmt.Sprintf("%s\r\n```", message)
case "addtimezone":
message = fmt.Sprintf("%s\r\nHere's how to add a time zone to EventsBot:", message)
message = fmt.Sprintf("%s\r\n```\r\n%saddtimezone Abbrev Location [Emoji]\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n Abbrev: Abbreviation to be used for this time zone (ie. ET, CT, etc.)", message)
message = fmt.Sprintf("%s\r\n Location: A location that represents the time zone (conforms to the tz database naming convention)", message)
message = fmt.Sprintf("%s\r\n Emoji: A server emoji representing the time zone. This value is optional", message)
message = fmt.Sprintf("%s\r\n\r\nNote: For more information on the tz database naming convention, see https://en.wikipedia.org/wiki/Tz_database", message)
message = fmt.Sprintf("%s\r\n\r\nNote: EventsBot automatically adjusts times based on the specified location's Daylight Saving convention.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "removetimezone":
message = fmt.Sprintf("%s\r\nHere's how to remove a time zone from EventsBot:", message)
message = fmt.Sprintf("%s\r\n```\r\n%sremovetimezone Abbrev\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n Abbrev: Abbreviation for the time zone to be removed", message)
message = fmt.Sprintf("%s\r\n```", message)
case "listtimezones":
message = fmt.Sprintf("%s\r\nHere's how to obtain a list of time zones:", message)
message = fmt.Sprintf("%s\r\n```\r\n%slisttimezones\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%sYes, it's that simple. Just ask and you shall receive.", message)
message = fmt.Sprintf("%s\r\n```", message)
case "roletimezone":
message = fmt.Sprintf("%s\r\nHere's how to associate a time zone to a server role:", message)
message = fmt.Sprintf("%s\r\n```\r\n%sroletimezone Role Abbrev\r\n", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n Role: Server role to which time zone should be linked", message)
message = fmt.Sprintf("%s\r\n Abbrev: Abbreviation provided when '%saddtimezone' command was issued", message, config.CommandPrefix)
message = fmt.Sprintf("%s\r\n```", message)
default:
message = fmt.Sprintf("%s\r\nWait! What? Are you having me on? I don't know anything about %s", message, command[1])
message = fmt.Sprintf("%s\r\nEventsBot is not amused :expressionless:", message)
}
s.ChannelMessageSend(m.ChannelID, message)
}
//gocyclo:ignore
// ListEvents is used to list all upcoming events on a specified (optional) date, for a specified (optional) user
// ~listevents
// ~listevents @username
// ~listevents date
// ~listevents date @username
func ListEvents(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
message := ""
// Test for correct number of arguments
if len(command) > 3 {
message = "Whoah, not so sure about those arguments. EventsBot is confused :thinking:"
message = fmt.Sprintf("%s\r\nFor help with listing events, type the following:\r\n```%shelp listevents```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
var specdate time.Time
listuser := "all"
// Check first argument
if len(command) > 1 {
if isUser(command[1]) {
listuser = m.Mentions[0].Username
} else if isDate(command[1]) {
specdate, _ = time.ParseInLocation("02/01/2006", command[1], defaultLocation)
} else {
message = "Whoah, not so sure about those arguments. EventsBot is confused :confounded:"
message = fmt.Sprintf("%s\r\nFor help with listing events, type the following:\r\n```%shelp listevents```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
}
// Check second argument
if len(command) > 2 {
if isUser(command[2]) {
listuser = m.Mentions[0].Username
} else {
message = "Whoah, not so sure about those arguments. EventsBot is confused :anguished:"
message = fmt.Sprintf("%s\r\nFor help with listing events, type the following:\r\n```%shelp listevents```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
}
results, err := db.GetEvents(g.ID, listuser, specdate)
if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, ":scream::scream::scream:Something very weird happened when trying to read the events. Sorry but EventsBot has no answers for you :cry:")
return
}
// Get all time zones
tzLookup := make(map[string]database.TimeZone)
tzs, err := db.GetTimeZones(g.ID)
if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, ":scream::scream::scream:Something very weird happened when trying to read the events. Sorry but EventsBot has no answers for you :cry:")
return
}
for _, tz := range tzs {
tzLookup[tz.Abbrev] = tz
}
var reply string
if specdate.IsZero() {
reply = fmt.Sprintf("%s - Upcoming events", g.Name)
} else {
reply = fmt.Sprintf("%s - Events on %s", g.Name, specdate.Format("Mon 02/01/2006"))
}
reply = fmt.Sprintf("%s for %s\r\n", reply, listuser)
if len(results) == 0 {
reply = fmt.Sprintf("%sZip. Nothing. Nada.\r\nWhat nonsense is this? EventsBot does not approve :frowning2:", reply)
} else {
for _, event := range results {
tzInfo := ""
eventLocation := defaultLocation
if event.TimeZone != "" {
tzInfo = fmt.Sprintf(" (%s)", event.TimeZone)
eventLocation, _ = time.LoadLocation(tzLookup[event.TimeZone].Location)
}
freeSpace := event.TeamSize - len(event.Participants)
curEvent := fmt.Sprintf("```\r\n%8v: %s%s - %s", event.EventID, event.DateTime.In(eventLocation).Format("Mon 02/01 15:04"), tzInfo, event.Name)
// Add players to message
if len(event.Participants) > 0 {
curEvent = fmt.Sprintf("%s\r\n Players:", curEvent)
for _, participant := range event.Participants {
curEvent = fmt.Sprintf("%s %s,", curEvent, participant.DisplayName())
}
// Remove trailing comma
curEvent = strings.TrimSuffix(curEvent, ",")
}
// Add reserves to message
if len(event.Reserves) > 0 {
curEvent = fmt.Sprintf("%s\r\nReserves:", curEvent)
for _, reserve := range event.Reserves {
curEvent = fmt.Sprintf("%s %s,", curEvent, reserve.DisplayName())
}
// Remove trailing comma
curEvent = strings.TrimSuffix(curEvent, ",")
}
// Add status to message
curEvent = fmt.Sprintf("%s\r\n Status: ", curEvent)
switch freeSpace {
case 0:
curEvent = fmt.Sprintf("%sFULL", curEvent)
case 1:
curEvent = fmt.Sprintf("%s1 Space", curEvent)
default:
curEvent = fmt.Sprintf("%s%d Spaces", curEvent, freeSpace)
}
curEvent = fmt.Sprintf("%s\r\n```", curEvent)
s.ChannelMessageSend(m.ChannelID, reply)
reply = curEvent
}
}
s.ChannelMessageSend(m.ChannelID, reply)
}
// Details is used to display detailed information on a specified event
// Usage: ~details EventID
func Details(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
message := ""
// Test for correct number of arguments
if len(command) != 2 {
message = "Whoah, not so sure about those arguments. EventsBot is confused :thinking:"
message = fmt.Sprintf("%s\r\nFor help with getting the details of an event, type the following:\r\n```%shelp details```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
// Find event in DB
event, err := db.GetEvent(g.ID, command[1])
if err == errNoRecords {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot could find no such event. Are you sure you got that Event ID of %s right? Them's finicky numbers :grimacing:", command[1]))
return
} else if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot feels that he should know event %s, but doesn't. Let's just pretend this never happened, okay? :flushed:", command[1]))
return
}
// Get time zone
tzInfo := ""
eventLocation := defaultLocation
if event.TimeZone != "" {
tz, err := db.GetTimeZone(g.ID, event.TimeZone)
if err == errNoRecords {
message = fmt.Sprintf("Say what? %s? EventsBot doesn't know any such time zone.", tz)
message = fmt.Sprintf("%s\r\nFor help with linking server roles to time zones, type the following:\r\n```%shelp roletimezone```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
} else if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, "EventsBot had trouble interpreting the time zone information of this event. Are we anywhere near a worm hole perhaps? :no_mouth:")
return
}
tzInfo = tz.Abbrev
eventLocation, _ = time.LoadLocation(tz.Location)
}
message = fmt.Sprintf("**EventID:** %s", event.EventID)
message = fmt.Sprintf("%s\r\n**Creator:** %s", message, event.Creator.Mention())
message = fmt.Sprintf("%s\r\n**Date:** %s", message, event.DateTime.In(eventLocation).Format("Mon 02/01/2006"))
message = fmt.Sprintf("%s\r\n**Time:** %s for %d hours", message, event.DateTime.In(eventLocation).Format("15:04"), event.Duration)
if event.TimeZone != "" {
message = fmt.Sprintf("%s\r\n**Time Zone:** %s", message, tzInfo)
}
message = fmt.Sprintf("%s\r\n**Name:** %s", message, event.Name)
message = fmt.Sprintf("%s\r\n**Description:** %s", message, event.Description)
message = fmt.Sprintf("%s\r\n**Team Size:** %d of %d", message, len(event.Participants), event.TeamSize)
if len(event.Participants) > 0 {
message = fmt.Sprintf("%s\r\n**Participants:**", message)
for _, participant := range event.Participants {
message = fmt.Sprintf("%s\r\n - %s", message, participant.Mention())
}
}
if len(event.Reserves) > 0 {
message = fmt.Sprintf("%s\r\n**Reserves:**", message)
for _, reserve := range event.Reserves {
message = fmt.Sprintf("%s\r\n - %s", message, reserve.Mention())
}
}
s.ChannelMessageSend(m.ChannelID, message)
}
// New is used to create a new event interactively
func New(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
location, locAbbr := getLocation(g, s, m)
newid := getEventID(time.Now())
gv, ok := guildVarsMap[g.ID]
if !ok {
s.ChannelMessageSend(m.ChannelID, "EventsBot had trouble obtaining the guild information :no_mouth:")
return
}
curUser := gv.impersonated
year, month, day := time.Now().Date()
if curUser.UserName == "" {
curUser = database.ClanUser{
UserName: m.Author.Username,
UserID: m.Author.ID,
Nickname: getNickname(g, s, m.Author.ID),
DateTime: time.Now(),
}
}
eventName := strings.Join(command[1:], " ")
// Test for name
if len(eventName) > 50 {
message := "That's a very long name right there. You realise EventsBot has to memorise these things? Have a heart and keep it under 50 characters please. :triumph:"
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp new```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
event := database.ClanEvent{
EventID: newid,
Creator: curUser,
Name: eventName,
DateTime: time.Date(year, month, day, 19, 0, 0, 0, location),
TimeZone: locAbbr,
Duration: 1,
TeamSize: 6,
}
newEvent := developingEvent{
TriggerMessage: m,
State: stateNew,
Event: event,
}
ShowDevelopingEvent(s, m, m.ChannelID, newEvent)
}
//gocyclo:ignore
// NewEvent is used to create a new event with all values provided up front
func NewEvent(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
message := ""
var dateNdx, timeNdx, tzNdx, durationNdx, nameNdx, descrNdx, teamNdx int
tzNdx = -1
// Test for correct number of arguments
switch len(command) {
case 7:
dateNdx = 1
timeNdx = 2
durationNdx = 3
nameNdx = 4
descrNdx = 5
teamNdx = 6
case 8:
dateNdx = 1
timeNdx = 2
tzNdx = 3
durationNdx = 4
nameNdx = 5
descrNdx = 6
teamNdx = 7
default:
message = "Whoah, not so sure about those arguments. EventsBot is confused :thinking:"
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp newevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
locAbbr := ""
var usrLocation *time.Location
// Test for time zone specification
if tzNdx > 0 {
if !strings.HasPrefix(command[tzNdx], "(") || !strings.HasSuffix(command[tzNdx], ")") {
message = fmt.Sprintf("Is %s supposed to be a time zone? Please put time zones in brackets :point_up:", command[tzNdx])
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp newevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
locAbbr = command[tzNdx]
locAbbr = strings.TrimPrefix(locAbbr, "(")
locAbbr = strings.TrimSuffix(locAbbr, ")")
// Check if timezone is known
tz, err := db.GetTimeZone(g.ID, locAbbr)
if err == errNoRecords {
message = fmt.Sprintf("Say what? %s? EventsBot doesn't know any such time zone.", tz)
message = fmt.Sprintf("%s\r\nFor help with linking server roles to time zones, type the following:\r\n```%shelp roletimezone```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
} else if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, ":scream::scream::scream:Something very weird happened when trying to find the time zone. Sorry but EventsBot has no answers for you :cry:")
return
}
usrLocation, err = time.LoadLocation(tz.Location)
if err != nil {
message = "EventsBot is having trouble working with this time zone. Are we anywhere near a worm hole perhaps? :no_mouth:"
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp newevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
} else {
usrLocation, locAbbr = getLocation(g, s, m)
}
// Test for date and time arguments
datetime := fmt.Sprintf("%s %s", command[dateNdx], command[timeNdx])
dt, err := time.ParseInLocation("02/01/2006 15:04", datetime, usrLocation)
if err != nil {
message = fmt.Sprintf("Whoah, not so sure about that date and time (%s). EventsBot is confused :thinking:", datetime)
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp newevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
if dt.Before(time.Now()) {
message = "Are you trying to create an event in the past? EventsBot has lost his flux capacitor :robot:"
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp newevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
// Test for duration
duration, err := strconv.Atoi(command[durationNdx])
if err != nil {
message = fmt.Sprintf("What kind of a duration is %s? EventsBot needs a vacation of %s weeks :beach:", command[durationNdx], command[durationNdx])
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp newevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
// Test for name
if len(command[nameNdx]) > 50 {
message = "That's a very long name right there. You realise EventsBot has to memorise these things? Have a heart and keep it under 50 characters please. :triumph:"
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp newevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
// Test for description
if len(command[descrNdx]) > 150 {
message = "That's a very long description right there. You realise EventsBot has to memorise these things? Have a heart and keep it under 150 characters please. :triumph:"
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp newevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
// Test for size
teamSize, err := strconv.Atoi(command[teamNdx])
if err != nil {
message = fmt.Sprintf("How many players you say? %s? EventsBot wouldn't do that if he were you :speak_no_evil:", command[teamNdx])
message = fmt.Sprintf("%s\r\nFor help with creating a new event, type the following:\r\n```%shelp newevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
newid := getEventID(time.Now())
curUser := guildVarsMap[g.ID].impersonated
if curUser.UserName == "" {
curUser = database.ClanUser{
UserName: m.Author.Username,
UserID: m.Author.ID,
Nickname: getNickname(g, s, m.Author.ID),
DateTime: time.Now(),
}
}
newEvent := database.ClanEvent{
EventID: newid,
Creator: curUser,
DateTime: dt,
TimeZone: locAbbr,
Duration: duration,
Name: command[nameNdx],
Description: command[descrNdx],
TeamSize: teamSize,
Full: false,
}
err = db.NewEvent(g.ID, newEvent)
if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, ":scream::scream::scream:Something very weird happened when trying to create this event. Sorry but EventsBot has no answers for you :cry:")
return
}
message = fmt.Sprintf("Woohoo! A new event has been created by %s. EventsBot is most pleased :ok_hand:", newEvent.Creator.Mention())
message = fmt.Sprintf("%s\r\nEvent ID: **%s**", message, newEvent.EventID)
message = fmt.Sprintf("%s\r\n\r\nTo sign up for this event, type the following:", message)
message = fmt.Sprintf("%s\r\n```%ssignup %s```", message, config.CommandPrefix, newEvent.EventID)
s.ChannelMessageSend(m.ChannelID, message)
signupCmd := []string{"signup", newEvent.EventID}
Signup(g, s, m, signupCmd)
}
// Edit is used to edit an existing event
func Edit(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
message := ""
// Test for correct number of arguments
if len(command) < 2 {
message = "Whoah, not so sure about those arguments. EventsBot is confused :thinking:"
message = fmt.Sprintf("%s\r\nFor help with editing an event, type the following:\r\n```%shelp edit```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
curUser := guildVarsMap[g.ID].impersonated
curUser.DateTime = time.Now()
if curUser.UserName == "" {
curUser = database.ClanUser{
UserName: m.Author.Username,
UserID: m.Author.ID,
Nickname: getNickname(g, s, m.Author.ID),
DateTime: time.Now(),
}
}
// Find event in DB
event, err := db.GetEvent(g.ID, command[1])
if err == errNoRecords {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot could find no such event. Are you sure you got that Event ID of %s right? Them's finicky numbers :grimacing:", command[1]))
return
} else if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot feels that he should know event %s, but doesn't. Let's just pretend this never happened, okay? :flushed:", command[1]))
return
}
// Check that user has permissions
allowed := false
if event.Creator.UserName == curUser.UserName {
allowed = true
} else if hasRole(g, s, m, "EventsBotAdmin") {
allowed = true
}
if !allowed {
message = "Yo yo yo. Back up a second dude. You don't have permissions to edit this event.\r\nEventsBot will not stand for this :point_up:"
message = fmt.Sprintf("%s\r\nFor help with editing events, type the following:\r\n```%shelp edit```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
newMsg, _ := s.ChannelMessageSend(m.ChannelID, "EDIT EVENT")
EditEvent(s, m, m.ChannelID, newMsg.ID, strings.ToUpper(command[1]))
}
// Rename is used to rename an existing event
// ~rename EventID Name
func Rename(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
message := ""
// Test for correct number of arguments
if len(command) < 3 {
message = "Whoah, not so sure about those arguments. EventsBot is confused :thinking:"
message = fmt.Sprintf("%s\r\nFor help with editing an event, type the following:\r\n```%shelp edit```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
newName := strings.Join(command[2:], " ")
// Test for name
if len(newName) > 50 {
message := "That's a very long name right there. You realise EventsBot has to memorise these things? Have a heart and keep it under 50 characters please. :triumph:"
message = fmt.Sprintf("%s\r\nFor help with renaming an new event, type the following:\r\n```%shelp rename```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
curUser := guildVarsMap[g.ID].impersonated
curUser.DateTime = time.Now()
if curUser.UserName == "" {
curUser = database.ClanUser{
UserName: m.Author.Username,
UserID: m.Author.ID,
Nickname: getNickname(g, s, m.Author.ID),
DateTime: time.Now(),
}
}
// Find event in DB
event, err := db.GetEvent(g.ID, command[1])
if err == errNoRecords {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot could find no such event. Are you sure you got that Event ID of %s right? Them's finicky numbers :grimacing:", command[1]))
return
} else if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot feels that he should know event %s, but doesn't. Let's just pretend this never happened, okay? :flushed:", command[1]))
return
}
// Check that user has permissions
allowed := false
if event.Creator.UserName == curUser.UserName {
allowed = true
} else if hasRole(g, s, m, "EventsBotAdmin") {
allowed = true
}
if !allowed {
message = "Yo yo yo. Back up a second dude. You don't have permissions to rename this event.\r\nEventsBot will not stand for this :point_up:"
message = fmt.Sprintf("%s\r\nFor help with renaming events, type the following:\r\n```%shelp rename```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
oldName := event.Name
event.Name = newName
// Update event
err = db.UpdateEvent(g.ID, *event)
if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, ":scream::scream::scream:Something very weird happened when trying to rename this event. Sorry but EventsBot has no answers for you :cry:")
return
}
message = fmt.Sprintf("Alright pay attention! %s's event, %s, shall henceforth be called %s.", event.Creator.Mention(), oldName, newName)
s.ChannelMessageSend(m.ChannelID, message)
}
// CancelEvent is used to delete a specified event
// ~cancelevent EventID
func CancelEvent(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
message := ""
// Test for correct number of arguments
if len(command) != 2 {
message = "Whoah, not so sure about those arguments. EventsBot is confused :thinking:"
message = fmt.Sprintf("%s\r\nFor help with cancelling an event, type the following:\r\n```%shelp cancelevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
curUser := guildVarsMap[g.ID].impersonated
curUser.DateTime = time.Now()
if curUser.UserName == "" {
curUser = database.ClanUser{
UserName: m.Author.Username,
UserID: m.Author.ID,
Nickname: getNickname(g, s, m.Author.ID),
DateTime: time.Now(),
}
}
// Find event in DB
event, err := db.GetEvent(g.ID, command[1])
if err == errNoRecords {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot could find no such event. Are you sure you got that Event ID of %s right? Them's finicky numbers :grimacing:", command[1]))
return
} else if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot feels that he should know event %s, but doesn't. Let's just pretend this never happened, okay? :flushed:", command[1]))
return
}
// Check that user has permissions
allowed := false
if event.Creator.UserName == curUser.UserName {
allowed = true
} else if hasRole(g, s, m, "EventsBotAdmin") {
allowed = true
}
if !allowed {
message = "Yo yo yo. Back up a second dude. You don't have permissions to cancel this event.\r\nEventsBot will not stand for this :point_up:"
message = fmt.Sprintf("%s\r\nFor help with cancelling events, type the following:\r\n```%shelp cancelevent```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
// Delete record
err = db.DeleteEvent(g.ID, command[1])
if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, ":scream::scream::scream:Something very weird happened when trying to create this event. Sorry but EventsBot has no answers for you :cry:")
return
}
message = fmt.Sprintf("Tragedy! %s's event, %s, has been cancelled.", event.Creator.Mention(), event.Name)
message = fmt.Sprintf("%s\r\n\r\n\"We don't have commit. Repeat. We are decommissioning the committal of the launch. It is now a negatory launch phase. We are in a no fly, no go phase. That is a November Gorgon phase, of non-flying. And we're gonna say 'goodnight, thank you, good work, over and out'\".", message)
message = fmt.Sprintf("%s\r\n\r\nEventsBot will cry himself to sleep tonight :sob:", message)
s.ChannelMessageSend(m.ChannelID, message)
}
//gocyclo:ignore
// Signup is used to sign the author or a specified user up to an event
// ~signup EventID
// ~signup EventID @Username
func Signup(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
message := ""
curUser := guildVarsMap[g.ID].impersonated
curUser.DateTime = time.Now()
if curUser.UserName == "" {
curUser = database.ClanUser{
UserName: m.Author.Username,
UserID: m.Author.ID,
Nickname: getNickname(g, s, m.Author.ID),
DateTime: time.Now(),
}
}
signupUsers := []database.ClanUser{}
if len(command) < 2 {
message = "Come on! Surely you're not expecting me to guess which event you're trying to sign up to :confused:"
message = fmt.Sprintf("%s\r\nFor help with signing up to events, type the following:\r\n```%shelp signup```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
// Check first argument
if len(command) > 2 {
for i := 2; i < len(command); i++ {
if isUser(command[i]) {
// Find user in list of mentions
for _, mentionedUser := range m.Mentions {
if strings.Replace(command[i], "!", "", 1) == mentionedUser.Mention() {
signupUser := database.ClanUser{
UserName: mentionedUser.Username,
UserID: mentionedUser.ID,
Nickname: getNickname(g, s, mentionedUser.ID),
DateTime: time.Now(),
}
signupUsers = append(signupUsers, signupUser)
}
}
} else {
message = "Whoah, not so sure about those arguments. EventsBot is confused :confounded:"
message = fmt.Sprintf("%s\r\n%s doesn't look like anyone I recognise.", message, command[i])
message = fmt.Sprintf("%s\r\nFor help with signing up to events, type the following:\r\n```%shelp signup```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
}
} else {
signupUsers = append(signupUsers, curUser)
}
// Find event in DB
event, err := db.GetEvent(g.ID, command[1])
if err == errNoRecords {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot could find no such event. Are you sure you got that Event ID of %s right? Them's finicky numbers :grimacing:", command[1]))
return
} else if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("EventsBot feels that he should know event %s, but doesn't. Let's just pretend this never happened, okay? :flushed:", command[1]))
return
}
// If different user is specified, check that current user has permissions
if signupUsers[0] != curUser || len(signupUsers) > 1 {
allowed := false
if event.Creator.UserName == curUser.UserName {
allowed = true
} else if hasRole(g, s, m, "EventsBotAdmin") {
allowed = true
}
if !allowed {
message = "Yo yo yo. Back up a second dude. You don't have permissions to sign other users up to events.\r\nEventsBot will not stand for this :point_up:"
message = fmt.Sprintf("%s\r\nFor help with signing up to events, type the following:\r\n```%shelp signup```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
}
// Check if any of the specified users are already signed up for this event
for i1, signupUser := range signupUsers {
for _, participant := range event.Participants {
if participant.UserName == signupUser.UserName {
if signupUser.UserName == curUser.UserName {
s.ChannelMessageSend(m.ChannelID, "You are already signed up to this event.\r\nEventsBot hasn't got time for your shenanigans :rolling_eyes:")
} else {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%s is already signed up to this event.\r\nEventsBot hasn't got time for your shenanigans :rolling_eyes:", signupUser.DisplayName()))
}
return
}
}
for _, reserve := range event.Reserves {
if reserve.UserName == signupUser.UserName {
if signupUser.UserName == curUser.UserName {
s.ChannelMessageSend(m.ChannelID, "You are already a reserve for this event.\r\nCan you just relax please? EventsBot will let you know if a space opens up. Don't call us, we'll call you. :rolling_eyes:")
} else {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%s is already a reserve for this event.\r\nCan you just relax please? EventsBot will let you know if a space opens up. Don't call us, we'll call you. :rolling_eyes:", signupUser.DisplayName()))
}
return
}
}
for i2 := 20; i2 < i1; i2++ {
if signupUsers[i1].UserName == signupUsers[i2].UserName {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("How many times do you want to sign %s up for this event.\r\nNo one is _that_ important. :confused:", signupUser.DisplayName()))
return
}
}
}
// Sign up all specified users
for _, signupUser := range signupUsers {
// Check if event is full
if len(event.Participants) >= event.TeamSize {
s.ChannelMessageSend(m.ChannelID, "Oh noes! This event is already full :cry:\r\nBut don't worry, EventsBot will put you on the reserves list and notify you if someone leaves.")
for _, reserve := range event.Reserves {
if reserve.UserName == curUser.UserName {
continue
}
}
event.Reserves = append(event.Reserves, signupUser)
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%s is now signed up as a reserve for %s's event, %s.\r\nEventsBot approves :thumbsup:", signupUser.Mention(), event.Creator.Mention(), event.Name))
} else {
event.Participants = append(event.Participants, signupUser)
event.Full = len(event.Participants) >= event.TeamSize
message := fmt.Sprintf("%s is now signed up for %s's event, %s.\r\n", signupUser.Mention(), event.Creator.Mention(), event.Name)
if event.Full {
message = fmt.Sprintf("%sThis event is now full. It's all systems go!\r\n", message)
message = fmt.Sprintf("%sEventsBot definitely approves :thumbsup::thumbsup:", message)
} else {
if event.TeamSize-len(event.Participants) == 1 {
message = fmt.Sprintf("%sThere is one space left\r\n", message)
} else {
message = fmt.Sprintf("%sThere are %d spaces left\r\n", message, event.TeamSize-len(event.Participants))
}
message = fmt.Sprintf("%sEventsBot approves :thumbsup:", message)
}
s.ChannelMessageSend(m.ChannelID, message)
}
}
err = db.UpdateEvent(g.ID, *event)
if err != nil {
log.Println(logging.LogEntry{
Severity: "ERROR",
Message: fmt.Sprintf("database: %+v", err),
})
s.ChannelMessageSend(m.ChannelID, ":scream::scream::scream:Something very weird happened when trying to update the event. Sorry but EventsBot has no answers for you :cry:")
return
}
}
//gocyclo:ignore
// Leave is used to remove the author or specified user from an event
// ~leave EventID
// ~leave EventID @Username
func Leave(g *discordgo.Guild, s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
message := ""
// Test for correct number of arguments
if len(command) < 2 {
message = "Whoah, not so sure about those arguments. EventsBot is confused :thinking:"
message = fmt.Sprintf("%s\r\nFor help with leaving an event, type the following:\r\n```%shelp leave```", message, config.CommandPrefix)
s.ChannelMessageSend(m.ChannelID, message)
return
}
curUser := guildVarsMap[g.ID].impersonated
curUser.DateTime = time.Now()
if curUser.UserName == "" {
curUser = database.ClanUser{