-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathcog.py
95 lines (79 loc) · 3.81 KB
/
cog.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
"""
Cog implementing anonymous reporting from users.
"""
import disnake
from disnake.ext import commands
from buttons.general import TrashView
from cogs.base import Base
from database.report import UserDB
from rubbergod import Rubbergod
from utils import cooldowns
from utils.checks import PermissionsCheck
from .messages_cz import MessagesCZ
from .modals import Modal
from .views import ReportAnonymView, ReportAnswerOnlyView, ReportGeneralView, ReportMessageView
class Report(Base, commands.Cog):
def __init__(self, bot: Rubbergod):
super().__init__()
self.bot = bot
@commands.Cog.listener("on_ready")
async def init_views(self):
"""Instantiate views for persistent interactions with bot"""
self.bot.add_view(ReportAnonymView(self.bot))
self.bot.add_view(ReportAnswerOnlyView(self.bot))
self.bot.add_view(ReportGeneralView(self.bot))
self.bot.add_view(ReportMessageView(self.bot))
async def check_blocked_bot(self, inter: disnake.Interaction) -> disnake.Message | None:
try:
dm_message = await inter.author.send(MessagesCZ.check_dm, view=TrashView())
return dm_message
except disnake.Forbidden:
await inter.send(MessagesCZ.blocked_bot(user=inter.author.id), ephemeral=True)
return None
@cooldowns.default_cooldown
@commands.message_command(name="Report message", guild_ids=[Base.config.guild_id])
async def app_report_message(self, inter: disnake.MessageCommandInteraction, message: disnake.Message):
if UserDB.is_banned(inter.author.id):
await inter.send(MessagesCZ.user_banned, ephemeral=True)
return
dm_message = await self.check_blocked_bot(inter)
if dm_message is None:
return
modal = Modal(self.bot, dm_message, "Message report", message)
await inter.response.send_modal(modal=modal)
@cooldowns.default_cooldown
@commands.slash_command(
name="report", description=MessagesCZ.report_brief, guild_ids=[Base.config.guild_id]
)
async def _report(self, inter: disnake.ApplicationCommandInteraction):
if UserDB.is_banned(inter.author.id):
await inter.send(MessagesCZ.user_banned, ephemeral=True)
return
@_report.sub_command(name="general", description=MessagesCZ.general_brief)
async def report_general(self, inter: disnake.ApplicationCommandInteraction):
dm_message = await self.check_blocked_bot(inter)
if dm_message is None:
return
modal = Modal(self.bot, dm_message)
await inter.response.send_modal(modal=modal)
@_report.sub_command(name="message", description=MessagesCZ.message_brief)
async def report_message(
self,
inter: disnake.ApplicationCommandInteraction,
message: disnake.Message = commands.Param(description=MessagesCZ.message_param),
):
dm_message = await self.check_blocked_bot(inter)
if dm_message is None:
return
modal = Modal(self.bot, dm_message, "Message report", message)
await inter.response.send_modal(modal=modal)
@_report.sub_command(name="google_form", description=MessagesCZ.google_form_brief)
async def report_google_form(self, inter: disnake.ApplicationCommandInteraction):
await inter.send(MessagesCZ.google_form, ephemeral=True)
@PermissionsCheck.is_submod_plus()
@commands.slash_command(name="report_mod", description=MessagesCZ.report_brief)
async def _report_mod(self, inter: disnake.ApplicationCommandInteraction): ...
@_report_mod.sub_command(name="unban", description=MessagesCZ.unban_user_brief)
async def report_unban_user(self, inter: disnake.ApplicationCommandInteraction, user: disnake.User):
UserDB.unban_user(user.id)
await inter.send(MessagesCZ.unban_user(user=user.mention))