forked from MikeyUsersREC/ERM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenus.py
10037 lines (8858 loc) · 387 KB
/
menus.py
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
import asyncio
import datetime
import typing
import discord
import pytz
import logging
import roblox
from discord import Interaction
from discord.ext import commands
from oauth2client.service_account import ServiceAccountCredentials
from bson import ObjectId
from datamodels.ShiftManagement import ShiftItem
from utils.constants import blank_color, BLANK_COLOR, GREEN_COLOR, ORANGE_COLOR, RED_COLOR
from utils.timestamp import td_format
from utils.utils import int_invis_embed, int_failure_embed, int_pending_embed, time_converter, get_elapsed_time, \
generalised_interaction_check_failure, generator, ArgumentMockingInstance, config_change_log
import gspread_asyncio
import random
REQUIREMENTS = ["gspread", "oauth2client"]
class Setup(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="All", style=discord.ButtonStyle.green)
async def all(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
return await generalised_interaction_check_failure(interaction.followup)
await interaction.response.defer()
self.value = "all"
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label="Punishments", style=discord.ButtonStyle.blurple)
async def punishments(
self, interaction: discord.Interaction, button: discord.ui.Button
):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
return await generalised_interaction_check_failure(interaction.followup)
await interaction.response.defer()
self.value = "punishments"
self.stop()
@discord.ui.button(label="Staff Management", style=discord.ButtonStyle.blurple)
async def staff_management(
self, interaction: discord.Interaction, button: discord.ui.Button
):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
return await generalised_interaction_check_failure(interaction.followup)
await interaction.response.defer()
self.value = "staff management"
self.stop()
@discord.ui.button(label="Shift Management", style=discord.ButtonStyle.blurple)
async def shift_management(
self, interaction: discord.Interaction, button: discord.ui.Button
):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
return await generalised_interaction_check_failure(interaction.followup)
await interaction.response.defer()
self.value = "shift management"
self.stop()
class Dropdown(discord.ui.Select):
def __init__(self, user_id):
self.user_id = user_id
options = [
discord.SelectOption(
label="Staff Management",
value="staff_management",
description="Inactivity Notices, and managing staff members",
),
discord.SelectOption(
label="Anti-ping",
value="antiping",
description="Responding to certain pings, ping immunity",
),
discord.SelectOption(
label="Punishments",
value="punishments",
description="Punishing community members for rule infractions",
),
discord.SelectOption(
label="Moderation Sync",
value="moderation_sync",
description="Syncing moderation actions from Roblox to Discord",
),
discord.SelectOption(
label="Shift Management",
value="shift_management",
description="Shifts (duty on, duty off), and where logs should go",
),
discord.SelectOption(
label="Shift Types",
value="shift_types",
description="View and customise shift types",
),
discord.SelectOption(
label="Verification",
value="verification",
description="Roblox Verification, simplified!",
),
discord.SelectOption(
label="Game Logging",
value="game_logging",
description="Game Logging! Messages, STS, Events, and more!",
),
discord.SelectOption(
label="Customisation",
value="customisation",
description="Colours, branding, prefix, to customise to your liking",
),
discord.SelectOption(
label="Game Security",
value="security",
description="Anti-abuse detection, and security measures",
),
discord.SelectOption(
label="Privacy",
value="privacy",
description="Disable global warnings, privacy features",
),
]
# The placeholder is what will be shown when no option is chosen
# The min and max values indicate we can only pick one of the three options
# The options parameter defines the dropdown options. We defined this above
super().__init__(
placeholder="Select a category", min_values=1, max_values=1, options=options
)
async def callback(self, interaction: discord.Interaction):
if interaction.user.id == self.user_id:
await interaction.response.defer()
self.view.value = self.values[0]
self.view.stop()
else:
await interaction.response.defer(ephemeral=True, thinking=True)
return await generalised_interaction_check_failure(interaction.followup)
class ShiftModificationDropdown(discord.ui.Select):
def __init__(self, user_id, other=False):
self.user_id = user_id
if other is False:
options = [
discord.SelectOption(
label="On Duty",
value="on",
description="Start your in-game shift",
),
discord.SelectOption(
label="Toggle Break",
value="break",
description="Taking a break? Toggle your break status",
),
discord.SelectOption(
label="Off Duty",
value="off",
description="End your in-game shift",
),
discord.SelectOption(
label="Void shift",
value="void",
description="Void your in-game shift. This is irreversible.",
),
]
else:
options = [
discord.SelectOption(
label="On Duty",
value="on",
description="Start their in-game shift",
),
discord.SelectOption(
label="Toggle Break",
value="break",
description="Taking a break? Toggle their break status",
),
discord.SelectOption(
label="Off Duty",
value="off",
description="End their in-game shift",
),
]
# The placeholder is what will be shown when no option is chosen
# The min and max values indicate we can only pick one of the three options
# The options parameter defines the dropdown options. We defined this above
super().__init__(
placeholder="Select an option", min_values=1, max_values=1, options=options
)
async def callback(self, interaction: discord.Interaction):
if interaction.user.id == self.user_id:
await interaction.response.defer()
self.view.value = self.values[0]
self.disabled = True
for option in self.options:
if option.value == self.values[0]:
option.default = True
await interaction.message.edit(view=self.view)
self.view.stop()
else:
await interaction.response.defer(ephemeral=True, thinking=True)
return await generalised_interaction_check_failure(interaction.followup)
class AdministrativeActionsDropdown(discord.ui.Select):
def __init__(self, user_id):
self.user_id = user_id
options = [
discord.SelectOption(
label="Add time",
value="add",
description="Add time to their current shift",
),
discord.SelectOption(
label="Remove time",
value="remove",
description="Remove time from their current shift",
),
discord.SelectOption(
label="Void shift",
value="void",
description="Void their shift, and remove it from the leaderboard",
),
discord.SelectOption(
label="Clear Member Shifts",
value="clear",
description="Clear all of their shifts from the leaderboard",
),
]
# The placeholder is what will be shown when no option is chosen
# The min and max values indicate we can only pick one of the three options
# The options parameter defines the dropdown options. We defined this above
super().__init__(
placeholder="Administrative Actions",
min_values=1,
max_values=1,
options=options,
)
async def callback(self, interaction: discord.Interaction):
if interaction.user.id == self.user_id:
await interaction.response.defer()
self.view.admin_value = self.values[0]
self.disabled = True
for option in self.options:
if option.value == self.values[0]:
option.default = True
for item in self.view.children:
if isinstance(item, discord.ui.Select):
if item is not self:
item.disabled = True
await interaction.message.edit(view=self.view)
self.view.stop()
else:
await interaction.response.defer(ephemeral=True, thinking=True)
return await generalised_interaction_check_failure(interaction.followup)
class CustomDropdown(discord.ui.Select):
def __init__(self, user_id, options: list, limit=1):
self.user_id = user_id
optionList = []
for option in options:
if isinstance(option, str):
optionList.append(
discord.SelectOption(
label=option.replace("_", " ").title(), value=option
)
)
elif isinstance(option, discord.SelectOption):
optionList.append(option)
# The placeholder is what will be shown when no option is chosen
# The min and max values indicate we can only pick one of the three options
# The options parameter defines the dropdown options. We defined this above
super().__init__(
placeholder="Select an option",
min_values=1,
max_values=limit,
options=optionList,
)
async def callback(self, interaction: discord.Interaction):
if interaction.user.id == self.user_id:
await interaction.response.defer()
if len(self.values) == 1:
self.view.value = self.values[0]
else:
self.view.value = self.values
self.view.stop()
else:
await interaction.response.defer(ephemeral=True, thinking=True)
return await generalised_interaction_check_failure(interaction.followup)
class MultiPaginatorDropdown(discord.ui.Select):
def __init__(self, user_id, options: list, pages: dict, limit=1):
self.user_id = user_id
self.pages = pages
optionList = []
for option in options:
if isinstance(option, str):
optionList.append(
discord.SelectOption(
label=option.replace("_", " ").title(), value=option
)
)
elif isinstance(option, discord.SelectOption):
optionList.append(option)
# The placeholder is what will be shown when no option is chosen
# The min and max values indicate we can only pick one of the three options
# The options parameter defines the dropdown options. We defined this above
super().__init__(
placeholder="Select an option",
min_values=1,
max_values=limit,
options=optionList,
)
async def callback(self, interaction: discord.Interaction):
if interaction.user.id == self.user_id:
await interaction.response.defer()
await interaction.message.edit(
content=f"<:ERMCheck:1111089850720976906> **{interaction.user.name},** you're currently viewing the **{self.values[0].replace('_', ' ').title()}** commands!",
embed=self.pages.get(self.values[0]),
)
else:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
# noinspection PyUnresolvedReferences
class MultiDropdown(discord.ui.Select):
def __init__(self, user_id, options: list):
self.user_id = user_id
optionList = []
for option in options:
if isinstance(option, str):
optionList.append(
discord.SelectOption(
label=option.replace("_", " ").title(), value=option
)
)
elif isinstance(option, discord.SelectOption):
optionList.append(option)
# # # # print(t(t(t(t(optionList)
# The placeholder is what will be shown when no option is chosen
# The min and max values indicate we can only pick one of the three options
# The options parameter defines the dropdown options. We defined this above
super().__init__(
placeholder="Select an option",
max_values=len(optionList),
options=optionList,
)
async def callback(self, interaction: discord.Interaction):
if interaction.user.id == self.user_id:
await interaction.response.defer()
if len(self.values) == 1:
self.view.value = self.values[0]
else:
self.view.value = self.values
self.view.stop()
else:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
class SettingsSelectMenu(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
self.add_item(Dropdown(self.user_id))
class ModificationSelectMenu(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.00)
self.value = None
self.user_id = user_id
self.add_item(ShiftModificationDropdown(self.user_id))
class AdministrativeSelectMenu(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.00)
self.value = None
self.admin_value = None
self.user_id = user_id
self.add_item(ShiftModificationDropdown(self.user_id, other=True))
self.add_item(AdministrativeActionsDropdown(self.user_id))
class YesNoMenu(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="Yes", style=discord.ButtonStyle.green)
async def yes(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = True
await interaction.edit_original_response(view=self)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label="No", style=discord.ButtonStyle.danger)
async def no(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = False
await interaction.edit_original_response(view=self)
self.stop()
class AcknowledgeMenu(discord.ui.View):
def __init__(self, user_id, note: str):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
if note:
for child in self.children:
if child.label == "NOTE":
child.label = note
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="I acknowledge and understand", style=discord.ButtonStyle.green)
async def yes(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = True
await interaction.edit_original_response(view=self)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label="NOTE", style=discord.ButtonStyle.secondary, row=1, disabled=True)
async def note(self, interaction: discord.Interaction, button: discord.ui.Button):
pass
class YesNoExpandedMenu(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="Yes, continue", style=discord.ButtonStyle.primary)
async def yes(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = True
await interaction.edit_original_response(view=self)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(
label="I'll do this another time", style=discord.ButtonStyle.secondary
)
async def no(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = False
await interaction.edit_original_response(view=self)
self.stop()
class YesNoColourMenu(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="Yes", style=discord.ButtonStyle.primary)
async def yes(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = True
await interaction.edit_original_response(view=self)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label="No", style=discord.ButtonStyle.secondary)
async def no(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = False
await interaction.edit_original_response(view=self)
self.stop()
class ColouredButton(discord.ui.Button):
def __init__(self, user_id, label, style, emoji=None):
super().__init__(label=label, style=style, emoji=emoji)
self.user_id = user_id
async def callback(self, interaction: discord.Interaction):
if interaction.user.id == self.user_id:
await interaction.response.defer()
self.view.value = self.label
self.view.stop()
else:
await generalised_interaction_check_failure(interaction.response)
return
class CustomExecutionButton(discord.ui.Button):
def __init__(self, user_id, label, style, emoji=None, func=None, row=0):
"""
A button used for custom execution functions. This is often used to subvert pagination limitations.
:param user_id: the user who can use this button
:param label: the label of the button
:param style: style of the button : discord.ButtonStyle
:param emoji: emoji of the button
:param func: function to be executed when pressed
"""
super().__init__(label=label, style=style, emoji=emoji, row=row)
self.func = func
self.user_id = user_id
async def callback(self, interaction: discord.Interaction):
if interaction.user.id == self.user_id:
await self.func(interaction, self)
else:
return await interaction.response.send_message(embed=discord.Embed(
title="Not Permitted",
description="You are not permitted to interact with these buttons.",
color=blank_color
), ephemeral=True)
class ColouredMenu(discord.ui.View):
def __init__(self, user_id, buttons: list[str]):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
for index, button in enumerate(buttons):
if index == 0:
self.add_item(
ColouredButton(
self.user_id, button, discord.ButtonStyle.primary, emoji=None
)
)
else:
self.add_item(
ColouredButton(
self.user_id, button, discord.ButtonStyle.secondary, emoji=None
)
)
class EnableDisableMenu(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="Enable", style=discord.ButtonStyle.green)
async def yes(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = True
await interaction.edit_original_response(view=self)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label="Disable", style=discord.ButtonStyle.danger)
async def no(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = False
await interaction.edit_original_response(view=self)
self.stop()
class LinkPathwayMenu(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="ERM", style=discord.ButtonStyle.secondary)
async def ERM(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "erm"
await interaction.edit_original_response(view=self)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label="Bloxlink", style=discord.ButtonStyle.danger)
async def Bloxlink(
self, interaction: discord.Interaction, button: discord.ui.Button
):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "bloxlink"
await interaction.edit_original_response(view=self)
self.stop()
class ShiftModify(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="Add time (+)", style=discord.ButtonStyle.green)
async def add(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "add"
await interaction.edit_original_response(view=self)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label="Remove time (-)", style=discord.ButtonStyle.danger)
async def remove(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "remove"
await interaction.edit_original_response(view=self)
self.stop()
@discord.ui.button(label="End shift", style=discord.ButtonStyle.danger)
async def end(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "end"
await interaction.edit_original_response(view=self)
self.stop()
@discord.ui.button(label="Void shift", style=discord.ButtonStyle.danger)
async def void(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "void"
await interaction.edit_original_response(view=self)
self.stop()
class ActivityNoticeModification(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="Add time (+)", style=discord.ButtonStyle.green)
async def add(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "add"
await interaction.edit_original_response(view=self)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label="Remove time (-)", style=discord.ButtonStyle.danger)
async def remove(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "remove"
await interaction.edit_original_response(view=self)
self.stop()
@discord.ui.button(label="End Activity Notice", style=discord.ButtonStyle.danger)
async def end(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "end"
await interaction.edit_original_response(view=self)
self.stop()
@discord.ui.button(label="Void Activity Notice", style=discord.ButtonStyle.danger)
async def void(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "void"
await interaction.edit_original_response(view=self)
self.stop()
class PartialShiftModify(discord.ui.View):
def __init__(self, user_id):
super().__init__(timeout=600.0)
self.value = None
self.user_id = user_id
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label="Add time (+)", style=discord.ButtonStyle.green)
async def add(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "add"
await interaction.edit_original_response(view=self)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label="Remove time (-)", style=discord.ButtonStyle.danger)
async def remove(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
await interaction.response.defer(ephemeral=True, thinking=True)
await generalised_interaction_check_failure(interaction.followup)
return
await interaction.response.defer()
for item in self.children:
item.disabled = True
self.value = "remove"
await interaction.edit_original_response(view=self)
self.stop()
class LOAMenu(discord.ui.View):
def __init__(self, bot, roles, loa_roles, loa_object, user_id, code):
super().__init__(timeout=None)
self.value = None
self.bot = bot
self.loa_object = loa_object
if isinstance(roles, list):
self.roles = roles
elif isinstance(roles, int):
self.roles = [roles]
self.loa_role = loa_roles
self.user_id = user_id
self.id = code
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(
label="Accept", style=discord.ButtonStyle.green, custom_id="loamenu:accept"
)
async def accept(self, interaction: discord.Interaction, button: discord.ui.Button):
# await interaction.response.defer()
await interaction.response.defer(ephemeral=True, thinking=True)
if not any(
role in [r.id for r in interaction.user.roles] for role in self.roles
):
# await interaction.response.defer(ephemeral=True, thinking=True)
if (
not interaction.user.guild_permissions.manage_guild
and not interaction.user.guild_permissions.administrator
and not interaction.user == interaction.guild.owner
):
await generalised_interaction_check_failure(interaction.followup)
return
for item in self.children:
item.disabled = True
await interaction.message.edit(view=self)
for item in self.children:
item.disabled = True
if item.label == "Accept":
item.label = "Accepted"
else:
self.remove_item(item)
await interaction.message.edit(view=self)
s_loa = None
# # # # print(t(t(t(t(self)
# # # # print(t(t(t(t(self.bot)
for loa in await self.bot.loas.get_all():
if (
loa["message_id"] == interaction.message.id
and loa["guild_id"] == interaction.guild.id
):
s_loa = loa
s_loa["accepted"] = True
guild = self.bot.get_guild(s_loa["guild_id"])
try:
user = await guild.fetch_member(s_loa["user_id"])
except discord.NotFound:
user = None
if user is None:
return await interaction.followup.send(
embed=discord.Embed(
title="Could not find member",
description="I could not find the staff member which requested this Leave of Absence.",
color=BLANK_COLOR
),
ephemeral=True
)
settings = await self.bot.settings.find_by_id(interaction.guild.id)
mentionable = ""
await user.send(
embed=discord.Embed(
title="<:success:1163149118366040106> Activity Notice Accepted",
description=f"Your {s_loa['type']} request in **{interaction.guild.name}** was accepted!",
color=GREEN_COLOR
)
)
try:
await self.bot.loas.update_by_id(s_loa)
if isinstance(self.loa_role, int):
role = [discord.utils.get(guild.roles, id=self.loa_role)]
elif isinstance(self.loa_role, list):
role = [
discord.utils.get(guild.roles, id=role) for role in self.loa_role
]
for rl in role:
if rl not in user.roles:
await user.add_roles(rl)
self.value = True
except discord.HTTPException:
pass
embed = interaction.message.embeds[0]
embed.title = (
f"<:success:1163149118366040106> {s_loa['type']} Accepted"
)
embed.colour = GREEN_COLOR
embed.set_footer(text=f"Accepted by {interaction.user.name}")
await interaction.message.edit(
embed=embed,
view=None,
)
await self.bot.views.delete_by_id(self.id)
await interaction.followup.send(
embed=discord.Embed(
title="<:success:1163149118366040106> Request Accepted",
description=f"You have successfully accepted this staff member's {s_loa['type']} Request.",
color=GREEN_COLOR
)
)
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(