-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmodals.py
645 lines (522 loc) · 26.3 KB
/
modals.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
# import.standard
from typing import Any, Dict
# import.thirdparty
import discord
from discord.ext import commands
from discord.ui import InputText, Modal
# import.local
from . import utils
from .prompt.menu import ConfirmButton
class ModeratorApplicationModal(Modal):
""" Class for the moderator application. """
def __init__(self, client: commands.Bot) -> None:
""" Class init method. """
super().__init__(title="Moderator Application")
self.client = client
self.cog: commands.Cog = client.get_cog('ReportSupport')
self.add_item(InputText(label="How active are you on Discord"))#, what's your country of origin?"))
self.add_item(
InputText(
label="What is your age, gender and timezone?",
placeholder="Example: 21 years old, male, Brasília.",
style=discord.InputTextStyle.short,
)
)
self.add_item(
InputText(
label="Languages spoken and proficiency level?",
style=discord.InputTextStyle.short
)
)
self.add_item(
InputText(
label="How could you make a better community?",
style=discord.InputTextStyle.paragraph)
)
self.add_item(
InputText(
label="Why are you applying to be Staff?",# What's your motivation? ",
style=discord.InputTextStyle.paragraph, placeholder="Explain why you want to be a moderator and why we should add you.",
)
)
async def callback(self, interaction: discord.Interaction) -> None:
""" Callback for the moderation application. """
member: discord.Member = interaction.user
embed = discord.Embed(
title=f"__Moderator Application__",
color=member.color
)
member_native_roles = [
role.name.title() for role in member.roles
if str(role.name).lower().startswith('native')
]
member_native_roles = ['None.'] if not member_native_roles else member_native_roles
embed.set_thumbnail(url=member.display_avatar)
embed.add_field(name="Joined the server", value=member.joined_at.strftime("%a, %d %B %y, %I %M %p UTC"), inline=False)
embed.add_field(name="Native roles", value=', '.join(member_native_roles), inline=False)
embed.add_field(name="Age, gender, timezone", value=self.children[1].value, inline=False)
embed.add_field(name="Discord Activity", value=self.children[0].value, inline=False)
embed.add_field(name="Language Levels", value=self.children[2].value, inline=False)
embed.add_field(name="Approach to make Sloth a better community", value=self.children[3].value, inline=False)
embed.add_field(name="Motivation for application", value=self.children[4].value, inline=False)
confirm_view = ConfirmButton(member, timeout=60)
await interaction.response.send_message(
content="Are you sure you want to apply this?",
embed=embed, view=confirm_view, ephemeral=True)
await confirm_view.wait()
if confirm_view.value is None:
return await confirm_view.interaction.followup.send(f"**{member.mention}, you took too long to answer...**", ephemeral=True)
if not confirm_view.value:
return await confirm_view.interaction.followup.send(f"**Not doing it then, {member.mention}!**", ephemeral=True)
self.cog.cache[member.id] = await utils.get_timestamp()
await confirm_view.interaction.followup.send(content="""
**Application successfully made, please, be patient now.**
• We will let you know when we need a new mod. We check apps when we need it!""", ephemeral=True)
moderator_app_channel = await self.client.fetch_channel(self.cog.moderator_app_channel_id)
owner_role = discord.utils.get(moderator_app_channel.guild.roles, id=self.cog.owner_role_id)
app = await moderator_app_channel.send(content=f"{owner_role.mention}, {member.mention}", embed=embed)
await app.add_reaction('✅')
await app.add_reaction('❌')
# Saves in the database
await self.cog.insert_application(app.id, member.id, 'moderator')
class TeacherApplicationModal(Modal):
""" Class for the teacher application. """
def __init__(self, client: commands.Bot) -> None:
""" Class init method. """
super().__init__(title="Teacher Application")
self.client = client
self.cog: commands.Cog = client.get_cog('ReportSupport')
self.add_item(
InputText(
label="Age, from, resides in, how active on Discord",
placeholder="Example: 21yo, USA, Canada, very active.",
style=discord.InputTextStyle.short))
self.add_item(
InputText(
label="What language are you applying to teach?",
style=discord.InputTextStyle.short))
self.add_item(
InputText(
label="On what day and time you wanna teach?",
placeholder="Thursdays 5PM CET",
style=discord.InputTextStyle.short))
self.add_item(
InputText(
label="English Level",
placeholder="Please explain why you would be a great teacher.",
style=discord.InputTextStyle.short))
self.add_item(
InputText(
label="Motivation for applying",
placeholder="Please explain why you would be a great teacher.",
max_length=1000,
style=discord.InputTextStyle.paragraph))
async def callback(self, interaction: discord.Interaction) -> None:
""" Callback for the moderation application. """
member: discord.Member = interaction.user
embed = discord.Embed(
title=f"__Teacher Application__",
color=member.color
)
member_native_roles = [
role.name.title() for role in member.roles
if str(role.name).lower().startswith('native')
]
member_native_roles = ['None.'] if not member_native_roles else member_native_roles
embed.set_thumbnail(url=member.display_avatar)
embed.add_field(name="Joined the server", value=member.joined_at.strftime("%a, %d %B %y, %I %M %p UTC"), inline=False)
embed.add_field(name="Native roles", value=', '.join(member_native_roles), inline=False)
embed.add_field(name="Age, from, resides in, active", value=self.children[0].value, inline=False)
embed.add_field(name="Applying to teach", value=self.children[1].value.title(), inline=False)
embed.add_field(name="On what day", value=self.children[2].value.title(), inline=False)
embed.add_field(name="English Level", value=self.children[3].value.capitalize(), inline=False)
embed.add_field(name="Motivation for application", value=self.children[4].value.capitalize(), inline=False)
confirm_view = ConfirmButton(member, timeout=60)
await interaction.response.send_message(
"Are you sure you want to apply this?",
embed=embed, view=confirm_view, ephemeral=True)
await confirm_view.wait()
if confirm_view.value is None:
return await confirm_view.interaction.followup.send(f"**{member.mention}, you took too long to answer...**", ephemeral=True)
if not confirm_view.value:
return await confirm_view.interaction.followup.send(f"**Not doing it then, {member.mention}!**", ephemeral=True)
self.cog.cache[member.id] = await utils.get_timestamp()
await confirm_view.interaction.followup.send(content="""
**Application successfully made, please, be patient now.**
• We will let you know when we need a new teacher. We check apps when we need it!""", ephemeral=True)
teacher_app_channel = await self.client.fetch_channel(self.cog.teacher_app_channel_id)
mayu = discord.utils.get(teacher_app_channel.guild.members, id=self.cog.mayu_id)
app = await teacher_app_channel.send(content=f"{mayu.mention}, {member.mention}", embed=embed)
await app.add_reaction('✅')
await app.add_reaction('❌')
# Saves in the database
await self.cog.insert_application(app.id, member.id, 'teacher')
class EventHostApplicationModal(Modal):
""" Class for the Event Host application. """
def __init__(self, client: commands.Bot) -> None:
""" Class init method. """
super().__init__(title="Event Host Application")
self.client = client
self.cog: commands.Cog = client.get_cog('ReportSupport')
self.add_item(
InputText(
label="Event name and description",
placeholder="Please, type how your event is gonna be called, and a small description for it.",
style=discord.InputTextStyle.multiline))
self.add_item(
InputText(
label="Why do you want to host that event?",
style=discord.InputTextStyle.multiline))
self.add_item(
InputText(
label="When is the best time for you to host events?",
placeholder="I.E: Thursdays 3 pm CET, you can specify your timezone.",
style=discord.InputTextStyle.short))
self.add_item(
InputText(
label="Your age? Experience hosting events?",
style=discord.InputTextStyle.short))
self.add_item(
InputText(
label="Can you host events in English?",
placeholder="If not, in which language would you be hosting?",
style=discord.InputTextStyle.short))
async def callback(self, interaction: discord.Interaction) -> None:
""" Callback for the moderation application. """
member: discord.Member = interaction.user
embed = discord.Embed(
title=f"__Event Host Application__",
description=f"{member.mention} ({member.id})",
color=member.color
)
member_native_roles = [
role.name.title() for role in member.roles
if str(role.name).lower().startswith('native')
]
member_native_roles = ['None.'] if not member_native_roles else member_native_roles
embed.set_thumbnail(url=member.display_avatar)
embed.add_field(name="Joined the server", value=member.joined_at.strftime("%a, %d %B %y, %I %M %p UTC"), inline=False)
embed.add_field(name="Native roles", value=', '.join(member_native_roles), inline=False)
embed.add_field(name="Event Name & Description", value=self.children[0].value, inline=False)
embed.add_field(name="Reason to host", value=self.children[1].value.title(), inline=False)
embed.add_field(name="On what day", value=self.children[2].value.title(), inline=False)
embed.add_field(name="Age & Experience", value=self.children[3].value.capitalize(), inline=False)
embed.add_field(name="Can you host events in English?", value=self.children[4].value.capitalize(), inline=False)
confirm_view = ConfirmButton(member, timeout=60)
await interaction.response.send_message(
content="Are you sure you want to apply this?",
embed=embed, view=confirm_view, ephemeral=True)
await confirm_view.wait()
if confirm_view.value is None:
return await confirm_view.interaction.followup.send(f"**{member.mention}, you took too long to answer...**", ephemeral=True)
if not confirm_view.value:
return await interaction.followup.send(f"**Not doing it then, {member.mention}!**", ephemeral=True)
self.cog.cache[member.id] = await utils.get_timestamp()
await confirm_view.interaction.followup.send(content="""
**Application successfully made, please, be patient now.**
• We will let you know when we need a new event host. We check apps when we need it!""", ephemeral=True)
teacher_app_channel = await self.client.fetch_channel(self.cog.event_host_app_channel_id)
app = await teacher_app_channel.send(content=member.mention, embed=embed)
await app.add_reaction('✅')
await app.add_reaction('❌')
# Saves in the database
await self.cog.insert_application(app.id, member.id, 'event_host')
class DebateManagerApplicationModal(Modal):
""" Class for the Event Host application. """
def __init__(self, client: commands.Bot) -> None:
""" Class init method. """
super().__init__(title="Debate Manager Application")
self.client = client
self.cog: commands.Cog = client.get_cog('ReportSupport')
self.add_item(
InputText(
label="Age? Timezone? Active on Discord?",
style=discord.InputTextStyle.short))
self.add_item(
InputText(
label="In what languages do you wanna host events?",
style=discord.InputTextStyle.short))
self.add_item(
InputText(
label="Do you have any experience with:",
placeholder="Moderating events? Organizing events?",
style=discord.InputTextStyle.multiline))
self.add_item(
InputText(
label="Why are you applying to be a Debate Mod?",
style=discord.InputTextStyle.paragraph))
self.add_item(
InputText(
label="What would you change in the Debate Club?",
style=discord.InputTextStyle.paragraph))
async def callback(self, interaction: discord.Interaction) -> None:
""" Callback for the moderation application. """
member: discord.Member = interaction.user
embed = discord.Embed(
title=f"__Event Host Application__",
description=f"{member.mention} ({member.id})",
color=member.color
)
member_native_roles = [
role.name.title() for role in member.roles
if str(role.name).lower().startswith('native')
]
member_native_roles = ['None.'] if not member_native_roles else member_native_roles
embed.set_thumbnail(url=member.display_avatar)
embed.add_field(name="Joined the server", value=member.joined_at.strftime("%a, %d %B %y, %I %M %p UTC"), inline=False)
embed.add_field(name="Native roles", value=', '.join(member_native_roles), inline=False)
embed.add_field(name="Age, timezone, active", value=self.children[0].value, inline=False)
embed.add_field(name="Host debates in", value=self.children[1].value.title(), inline=False)
embed.add_field(name="Experience with moderating, organizing events", value=self.children[2].value.title(), inline=False)
embed.add_field(name="Motivation", value=self.children[3].value.capitalize(), inline=False)
embed.add_field(name="What would you change?", value=self.children[4].value.capitalize(), inline=False)
confirm_view = ConfirmButton(member, timeout=60)
await interaction.response.send_message(
content="Are you sure you want to apply this?",
embed=embed, view=confirm_view, ephemeral=True)
await confirm_view.wait()
if confirm_view.value is None:
return await confirm_view.interaction.followup.send(f"**{member.mention}, you took too long to answer...**", ephemeral=True)
if not confirm_view.value:
return await interaction.followup.send(f"**Not doing it then, {member.mention}!**", ephemeral=True)
self.cog.cache[member.id] = await utils.get_timestamp()
await confirm_view.interaction.followup.send(content="""
**Application successfully made, please, be patient now.**
• We will let you know when we need a new debate manager. We check apps when we need it!""", ephemeral=True)
debate_app_channel = await self.client.fetch_channel(self.cog.debate_manager_app_channel_id)
app = await debate_app_channel.send(content=member.mention, embed=embed)
await app.add_reaction('✅')
await app.add_reaction('❌')
# Saves in the database
await self.cog.insert_application(app.id, member.id, 'debate_manager')
class UserReportSupportDetailModal(Modal):
""" Class for specifying details for a Report Support request. """
def __init__(self, client: commands.Bot, option: str) -> None:
""" Class init method. """
super().__init__(title="Report-Support")
self.client = client
self.cog: commands.Cog = client.get_cog('ReportSupport')
self.add_item(
InputText(
label="Who are you reporting?",
placeholder="Type the username of the user you are reporting.",
style=discord.InputTextStyle.singleline
)
)
self.add_item(
InputText(
label="Reason of the report/What did this user do?",
placeholder="Describe the situation as much as you can, so we can help you better and faster.",
style=discord.InputTextStyle.paragraph
)
)
self.add_item(
InputText(
label="Do you possess evidence of what happened?",
placeholder="Recording, screenshots or witnesses can be considered as evidence ",
style=discord.InputTextStyle.paragraph,
min_length=2
)
)
self.option = option
async def callback(self, interaction) -> None:
""" Callback for the form modal. """
await interaction.response.defer()
reportee = self.children[0].value
text = self.children[1].value
evidence=self.children[2].value
member = interaction.user
if self.option == 'report_user':
try:
exists = await self.cog.report_someone(interaction, reportee, text, evidence)
if exists is False:
return
except Exception as e:
print(e)
else:
return await self.cog.audio(member, 'case_alert')
elif self.option == 'report_support':
message = f"Please, {member.mention}, try to explain what kind of help you want related to the server."
try:
exists = await self.cog.generic_help(interaction, 'general help', message)
if exists is False:
return
except Exception as e:
print(e)
else:
return #await self.cog.audio(member, 'general_help_alert')
elif self.option == 'report_help':
message = f"Please, {member.mention}, inform us what roles you want, and if you spotted a specific problem with the reaction-role selection."
try:
exists = await self.cog.generic_help(interaction, 'role help', message)
if exists is False:
return
except Exception as e:
print(e)
else:
return #await self.cog.audio(member, 'role_help_alert')
elif self.option == 'Oopsie':
return await interaction.followup.send("**All right, cya!**", ephemeral=True)
class UserReportStaffDetailModal(Modal):
""" Class for specifying details for a Report Support request. """
def __init__(self, client: commands.Bot, option: str) -> None:
""" Class init method. """
super().__init__(title="Report Staff")
self.client = client
self.cog: commands.Cog = client.get_cog('ReportSupport')
self.add_item(
InputText(
label="Who are you reporting?",
placeholder="Type the username of the Staff member you are reporting.",
style=discord.InputTextStyle.singleline
)
)
self.add_item(
InputText(
label="Reason of the report/What did this user do?",
placeholder="Describe the situation as much as you can, so we can help you better and faster.",
style=discord.InputTextStyle.paragraph
)
)
self.add_item(
InputText(
label="Do you possess evidence of what happened?",
placeholder="Recording, screenshots or witnesses can be considered as evidence ",
style=discord.InputTextStyle.paragraph,
min_length=2
)
)
self.option = option
async def callback(self, interaction) -> None:
""" Callback for the form modal. """
await interaction.response.defer()
reportee = self.children[0].value
text = self.children[1].value
evidence=self.children[2].value
member = interaction.user
if self.option == 'report_staff':
try:
exists = await self.cog.report_staff(interaction, reportee, text, evidence)
if exists is False:
return
except Exception as e:
print(e)
else:
return await self.cog.audio(member, 'case_alert')
elif self.option == 'Oopsie':
return #await interaction.followup.send("**All right, cya!**", ephemeral=True)
class TravelBuddyModal(Modal):
""" Class for the TravelBuddies feature. """
def __init__(self, client: commands.Bot, country_role: discord.Role) -> None:
""" Class init method. """
super().__init__(title="Travel Buddy Form")
self.client = client
self.country_role = country_role
self.cog: commands.Cog = client.get_cog('TravelBuddies')
self.add_item(
InputText(
label="Where",
placeholder="Where are you traveling to?",
style=discord.InputTextStyle.short
)
)
self.add_item(
InputText(
label="When",
placeholder="When are you traveling to that place and for how long?",
style=discord.InputTextStyle.short,
)
)
self.add_item(
InputText(
label="Lookin for a host",
placeholder="Are you looking for a host there?",
style=discord.InputTextStyle.short
)
)
self.add_item(
InputText(
label="Activities",
placeholder="What kind of activities are you planning or want to do there?",
style=discord.InputTextStyle.paragraph
)
)
async def callback(self, interaction: discord.Interaction) -> None:
""" Callback for the moderation application. """
member: discord.Member = interaction.user
current_time = await utils.get_time_now()
embed = discord.Embed(
title=f"__Travel Buddy__",
color=member.color,
timestamp=current_time
)
embed.set_thumbnail(url=member.display_avatar)
embed.add_field(name="Who's traveling:", value=member.mention, inline=False)
embed.add_field(name="Where", value=self.children[0].value, inline=False)
embed.add_field(name="When", value=self.children[1].value, inline=False)
embed.add_field(name="Looking for a host", value=self.children[2].value, inline=False)
embed.add_field(name="Activities", value=self.children[3].value, inline=False)
confirm_view = ConfirmButton(member, timeout=60)
await interaction.response.send_message(
content=f"Are you sure you want to post this, and ping the `{self.country_role.name}`?",
embed=embed, view=confirm_view, ephemeral=True)
await confirm_view.wait()
if confirm_view.value is None:
return await confirm_view.interaction.response.send_message(f"**{member.mention}, you took too long to answer...**", ephemeral=True)
if not confirm_view.value:
return await confirm_view.interaction.response.send_message(f"**Not doing it then, {member.mention}!**", ephemeral=True)
self.cog.cache[member.id] = await utils.get_timestamp()
message = await confirm_view.interaction.followup.send(
content=f"Hello, {self.country_role.mention}!", embed=embed, allowed_mentions=discord.AllowedMentions.all()
)
message.guild = interaction.guild
await message.create_thread(name=f"{member}'s Trip", auto_archive_duration=10080)
class BootcampFeedbackModal(Modal):
""" Class for the moderator application. """
def __init__(self, client: commands.Bot, view: discord.ui.View, questions: Dict[int, Dict[str, Any]], index_question: int = 1) -> None:
""" Class init method. """
super().__init__(title="Bootcamp Feedback")
self.client = client
self.view = view
self.questions = questions
self.index_question = index_question
self.add_question()
def add_question(self) -> None:
question = self.questions.get(self.index_question)
print(question)
self.children.clear() # Clear current inputs
# Add the question input
self.add_item(
InputText(
label=f"Question {self.index_question}",
placeholder=question["message"],
style=question["type"],
required=True,
max_length=question["max_length"],
)
)
# Add the rating input
self.add_item(
InputText(
label="Rating",
placeholder="Rate it from 0-5.",
style=discord.InputTextStyle.singleline,
required=True,
max_length=1,
)
)
async def callback(self, interaction: discord.Interaction) -> None:
""" Callback for the moderation application. """
self.questions[self.index_question]["answer"] = self.children[0].value
rating = 0
try:
rating = int(self.children[1].value)
except Exception:
pass
self.questions[self.index_question]["rating"] = rating
self.view.questions = self.questions
self.view.children[self.index_question-1].disabled = True
if self.index_question == len(self.questions):
self.view.children[-1].disabled = False
self.view.children[-1].style = discord.ButtonStyle.success
await interaction.response.edit_message(view=self.view)