diff --git a/cogs/report/features.py b/cogs/report/features.py index 615dd6cd5..e81071fe8 100644 --- a/cogs/report/features.py +++ b/cogs/report/features.py @@ -17,7 +17,9 @@ def extract_report_id(inter: disnake.MessageInteraction) -> int: return int(report_id) -async def convert_url(inter, message_url) -> Optional[disnake.Message]: +async def convert_url( + inter: disnake.ApplicationCommandInteraction, message_url: str +) -> Optional[disnake.Message]: """converts a message url to a message object""" try: message: disnake.Message = await commands.MessageConverter().convert(inter, message_url) @@ -34,15 +36,18 @@ async def set_tag(forum: disnake.ForumChannel, forum_thread: disnake.Thread, tag break -async def embed_resolved(self, author: str, embed: dict, report_type: str, resolved: bool) -> disnake.Embed: +async def embed_resolved( + children: list[disnake.ui.Button], author: str, embed: dict, report_type: str, resolved: bool +) -> disnake.Embed: """Changes the embed to a resolved embed or back to a report embed""" + print(children) if resolved: embed["color"] = disnake.Color.green() embed["title"] = "Resolved" for field in embed["fields"]: if field["name"] == "Resolved by": field["value"] = author - for child in self.children: + for child in children: child.disabled = True if child.custom_id == "report:resolve": child.label = "Resolved" @@ -55,7 +60,7 @@ async def embed_resolved(self, author: str, embed: dict, report_type: str, resol for field in embed["fields"]: if field["name"] == "Resolved by": field["value"] = "---" - for child in self.children: + for child in children: child.disabled = False if child.custom_id == "report:resolve": child.label = "Resolve" @@ -65,7 +70,7 @@ async def embed_resolved(self, author: str, embed: dict, report_type: str, resol return embed -def answer_embed(title, inter: disnake.ModalInteraction, report: ReportDB, answer: str) -> disnake.Embed: +def answer_embed(title: str, inter: disnake.ModalInteraction, report: ReportDB, answer: str) -> disnake.Embed: """creates an embed template for the submitted answer""" description = MessagesCZ.embed_answered(last_answer=report.last_answer, answer=answer) embed = disnake.Embed(title=title, description=description, color=disnake.Color.yellow()) diff --git a/cogs/report/modals.py b/cogs/report/modals.py index 36bdbd511..af3cc847b 100644 --- a/cogs/report/modals.py +++ b/cogs/report/modals.py @@ -6,10 +6,10 @@ import utils from cogs.report.views import ReportGeneralView, ReportMessageView from config.app_config import config -from config.messages import Messages from database.report import ReportDB, UserDB from . import features as report_features +from .messages_cz import MessagesCZ class Modal(disnake.ui.Modal): @@ -27,7 +27,7 @@ def __init__( components = [ disnake.ui.TextInput( label="Report reason", - placeholder=Messages.report_modal_placeholder, + placeholder=MessagesCZ.modal_placeholder, custom_id="reason", style=disnake.TextInputStyle.long, required=True, @@ -83,7 +83,7 @@ async def edit_or_send(self, inter: disnake.ModalInteraction, embed: disnake.Emb async def report_general(self, inter: disnake.ModalInteraction) -> None: """add general report to db and send it to the report room""" - await inter.send(Messages.report_modal_success, ephemeral=True) + await inter.send(MessagesCZ.modal_success, ephemeral=True) report_reason = inter.text_values["reason"] UserDB.add_user(inter.author.id) report_id = ReportDB.add_report(type="general", author_id=inter.author.id, reason=report_reason) @@ -102,8 +102,8 @@ async def report_general(self, inter: disnake.ModalInteraction) -> None: async def report_message(self, inter: disnake.ModalInteraction) -> None: """add message report to db and send it to the report room""" - await inter.send(Messages.report_modal_success, ephemeral=True) - report_reason = Messages.report_message_embed( + await inter.send(MessagesCZ.modal_success, ephemeral=True) + report_reason = MessagesCZ.message_embed( content=self.message.content, reason=inter.text_values["reason"] ) UserDB.add_user(inter.author.id) @@ -140,7 +140,7 @@ async def report_message(self, inter: disnake.ModalInteraction) -> None: content = "" if attachments_too_big: - content = Messages.report_files_too_big(files="\n- ".join(attachments_too_big)) + content = MessagesCZ.attachment_too_big(files="\n- ".join(attachments_too_big)) await thread.send(content=content, files=files) diff --git a/cogs/report/views.py b/cogs/report/views.py index 1172fa07c..c1bf7b863 100644 --- a/cogs/report/views.py +++ b/cogs/report/views.py @@ -29,10 +29,10 @@ async def set_view_resolved(self, embed: dict, author_id: int, report_id: int) - report = ReportDB.get_report(report_id) if report.resolved: - embed = await report_features.embed_resolved(self, "Anonym", embed, report.type, False) + embed = await report_features.embed_resolved(self.children, "Anonym", embed, report.type, False) report.set_resolved(report_id, author_id, False) else: - embed = await report_features.embed_resolved(self, "Anonym", embed, report.type, True) + embed = await report_features.embed_resolved(self.children, "Anonym", embed, report.type, True) report.set_resolved(report_id, author_id, True) return embed @@ -55,7 +55,7 @@ async def set_spam( for child in self.children: if child.custom_id == "report:resolve": embed = await report_features.embed_resolved( - self, resolved_author, embed, report.type, False + self.children, resolved_author, embed, report.type, False ) button.label = "Mark spam" button.style = disnake.ButtonStyle.red @@ -68,7 +68,9 @@ async def set_spam( ReportDB.set_fake_report(report.id, inter.author.id, True) for child in self.children: if child.custom_id == "report:resolve": - embed = await report_features.embed_resolved(self, resolved_author, embed, "Spam", True) + embed = await report_features.embed_resolved( + self.children, resolved_author, embed, "Spam", True + ) child.disabled = True button.disabled = False button.label = f"Spam marked by @{inter.author.name}" @@ -91,7 +93,9 @@ async def resolve(self, button: disnake.ui.Button, inter: disnake.MessageInterac resolved_by = f"{inter.author.mention} `@{inter.author.name}`" if report.resolved: - embed = await report_features.embed_resolved(self, resolved_by, embed, report.type, False) + embed = await report_features.embed_resolved( + self.children, resolved_by, embed, report.type, False + ) report.set_resolved(report_id, inter.author.id, False) content = MessagesCZ.report_unresolved( id=report_id, author=inter.author.mention, author_name=inter.author.name @@ -100,7 +104,7 @@ async def resolve(self, button: disnake.ui.Button, inter: disnake.MessageInterac await report_author.send(content) await inter.message.channel.send(content, allowed_mentions=disnake.AllowedMentions.none()) else: - embed = await report_features.embed_resolved(self, resolved_by, embed, report.type, True) + embed = await report_features.embed_resolved(self.children, resolved_by, embed, report.type, True) report.set_resolved(report_id, inter.author.id, True) await report_features.set_tag(self.report_channel, inter.message.channel, "resolved")