diff --git a/gigaclub_ban_system/models/gc_user.py b/gigaclub_ban_system/models/gc_user.py index 3560d870..16a94986 100644 --- a/gigaclub_ban_system/models/gc_user.py +++ b/gigaclub_ban_system/models/gc_user.py @@ -49,7 +49,7 @@ def get_banned_players(self) -> list: { "ban_expiration_datetime": x.ban_expiration_datetime, "mc_uuid": x.mc_uuid, - "current_warning_id": x.current_warning_id.id, + "current_warning_id": x.current_warning_id.warning_type_id.id, } for x in self.env["gc.user"] .search([]) diff --git a/gigaclub_discord/controllers/main.py b/gigaclub_discord/controllers/main.py index 74e5c37e..2597d790 100644 --- a/gigaclub_discord/controllers/main.py +++ b/gigaclub_discord/controllers/main.py @@ -3,7 +3,7 @@ import threading import discord # noqa: W7936 -from discord import Embed +from discord import AllowedMentions, Embed from discord.ui import Button, View from odoo import _, api, http, registry @@ -123,7 +123,12 @@ async def on_ready(self): # noqa: C901 embeds, view = self._generate_message( message_record.content ) - sent_message = await channel.send(embeds=embeds, view=view) + sent_message = await channel.send( + embeds=embeds, + view=view, + content=message_record.content.get("content", ""), + allowed_mentions=AllowedMentions.all(), + ) message_record.message_id = sent_message.id message_record.sent = True # messages_to_edit = self.env["gc.discord.message"].search( @@ -186,27 +191,27 @@ def _create_embed(embed_data): async def on_interaction(self, interaction): custom_id = interaction.data.get("custom_id", "") - if custom_id == "open_modal": + if custom_id == "create_world": thread = await interaction.message.channel.create_thread( name="TEST", invitable=False, ) await thread.add_user(interaction.user) - # modal = MyModal(title="Modal via Button Click") - # await interaction.response.send_modal(modal) - # # Create a button to close the modal - # close_button = Button( - # style=discord.ButtonStyle.danger, - # label="Close", - # custom_id="close_modal", - # ) - # - # # Create a view and add the close button - # view = View() - # view.add_item(close_button) - # - # # Send a message with the modal view - # await interaction.message.edit(content="Modal content", view=view) + modal = MyModal(title="Modal via Button Click") + await interaction.response.send_modal(modal) + # Create a button to close the modal + close_button = Button( + style=discord.ButtonStyle.danger, + label="Close", + custom_id="close_modal", + ) + + # Create a view and add the close button + view = View() + view.add_item(close_button) + + # Send a message with the modal view + await interaction.message.edit(content="Modal content", view=view) elif custom_id == "close_modal": await interaction.message.delete() diff --git a/gigaclub_discord/i18n/gigaclub_discord.pot b/gigaclub_discord/i18n/gigaclub_discord.pot index 7e39fa34..98562862 100644 --- a/gigaclub_discord/i18n/gigaclub_discord.pot +++ b/gigaclub_discord/i18n/gigaclub_discord.pot @@ -146,6 +146,7 @@ msgstr "" #. module: gigaclub_discord #: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_message__content +#: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_message_template__content msgid "Content" msgstr "" @@ -577,6 +578,7 @@ msgstr "" #: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_embed_field_template__lang #: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_embed_footer_template__lang #: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_embed_template__lang +#: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_message_template__lang msgid "Language" msgstr "" @@ -829,6 +831,7 @@ msgstr "" #: model:ir.model.fields,help:gigaclub_discord.field_gc_discord_embed_field_template__lang #: model:ir.model.fields,help:gigaclub_discord.field_gc_discord_embed_footer_template__lang #: model:ir.model.fields,help:gigaclub_discord.field_gc_discord_embed_template__lang +#: model:ir.model.fields,help:gigaclub_discord.field_gc_discord_message_template__lang msgid "" "Optional translation language (ISO code) to select when sending out an " "email. If not set, the english version will be used. This should usually be " @@ -890,6 +893,7 @@ msgstr "" #: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_embed_field_template__render_model #: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_embed_footer_template__render_model #: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_embed_template__render_model +#: model:ir.model.fields,field_description:gigaclub_discord.field_gc_discord_message_template__render_model msgid "Rendering Model" msgstr "" diff --git a/gigaclub_discord/models/gc_discord_message_template.py b/gigaclub_discord/models/gc_discord_message_template.py index 2b9489bf..4b7a435c 100644 --- a/gigaclub_discord/models/gc_discord_message_template.py +++ b/gigaclub_discord/models/gc_discord_message_template.py @@ -4,18 +4,27 @@ class GCDiscordMessageTemplate(models.Model): _name = "gc.discord.message.template" + _inherit = "mail.render.mixin" _description = "GigaClub Discord Message Template" name = fields.Char() + content = fields.Html(render_engine="qweb", sanitize=False) embed_template_ids = fields.One2many( comodel_name="gc.discord.embed.template", inverse_name="message_template_id" ) view_id = fields.Many2one(comodel_name="gc.discord.view") model_id = fields.Many2one(comodel_name="ir.model") + def _compute_render_model(self): + for rec in self: + rec.render_model = rec.model_id.model + def create_message(self, channel, res_id): self.ensure_one() content = { + "content": html2plaintext( + self._render_field("content", [res_id]).get(res_id, "") + ), "embeds": [ { "title": html2plaintext( diff --git a/gigaclub_discord/views/gc_discord_message_template_views.xml b/gigaclub_discord/views/gc_discord_message_template_views.xml index d20251ab..4a7e6474 100644 --- a/gigaclub_discord/views/gc_discord_message_template_views.xml +++ b/gigaclub_discord/views/gc_discord_message_template_views.xml @@ -21,6 +21,7 @@ + diff --git a/gigaclub_discord_project/data/gc_discord_message_template_data.xml b/gigaclub_discord_project/data/gc_discord_message_template_data.xml index d9d6f3e8..579b75a5 100644 --- a/gigaclub_discord_project/data/gc_discord_message_template_data.xml +++ b/gigaclub_discord_project/data/gc_discord_message_template_data.xml @@ -5,6 +5,11 @@ Task Template + +
+ @Builder +
+
diff --git a/gigaclub_translation/models/gc_translation.py b/gigaclub_translation/models/gc_translation.py index fb462f6a..8ca41038 100644 --- a/gigaclub_translation/models/gc_translation.py +++ b/gigaclub_translation/models/gc_translation.py @@ -32,3 +32,22 @@ def get_translation_by_player_uuid(self, name, player_uuid, category=False): if entry: return entry.content return translation.name + + # retrieve all translations and if a date is set only retrieve + # translation entries that have been updated after that date + @api.model + def get_all_translations(self, date=False): + if date: + entries = self.env["gc.translation.entry"].search( + [("write_date", ">", date)] + ) + else: + entries = self.env["gc.translation.entry"].search([]) + return [ + { + "name": entry.translation_id.name, + "content": entry.content, + "lang": entry.lang, + } + for entry in entries + ]