Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Builder System into Discord #88

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gigaclub_ban_system/models/gc_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand Down
41 changes: 23 additions & 18 deletions gigaclub_discord/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,7 +123,12 @@
embeds, view = self._generate_message(
message_record.content
)
sent_message = await channel.send(embeds=embeds, view=view)
sent_message = await channel.send(

Check warning on line 126 in gigaclub_discord/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

gigaclub_discord/controllers/main.py#L126

Added line #L126 was not covered by tests
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(
Expand Down Expand Up @@ -186,27 +191,27 @@

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)

Check warning on line 201 in gigaclub_discord/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

gigaclub_discord/controllers/main.py#L200-L201

Added lines #L200 - L201 were not covered by tests
# Create a button to close the modal
close_button = Button(

Check warning on line 203 in gigaclub_discord/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

gigaclub_discord/controllers/main.py#L203

Added line #L203 was not covered by tests
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)

Check warning on line 211 in gigaclub_discord/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

gigaclub_discord/controllers/main.py#L210-L211

Added lines #L210 - L211 were not covered by tests

# Send a message with the modal view
await interaction.message.edit(content="Modal content", view=view)

Check warning on line 214 in gigaclub_discord/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

gigaclub_discord/controllers/main.py#L214

Added line #L214 was not covered by tests

elif custom_id == "close_modal":
await interaction.message.delete()
Expand Down
4 changes: 4 additions & 0 deletions gigaclub_discord/i18n/gigaclub_discord.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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 ""

Expand Down
9 changes: 9 additions & 0 deletions gigaclub_discord/models/gc_discord_message_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 20 in gigaclub_discord/models/gc_discord_message_template.py

View check run for this annotation

Codecov / codecov/patch

gigaclub_discord/models/gc_discord_message_template.py#L20

Added line #L20 was not covered by tests

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<sheet>
<group>
<field name="name" />
<field name="content" />
<field name="embed_template_ids" />
<field name="view_id" />
</group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<field name="name">Task Template</field>
<field name="model_id" ref="model_project_task" />
<field name="view_id" ref="gc_discord_view_task" />
<field name="content" type="html">
<div>
@Builder
</div>
</field>
</record>

</odoo>
19 changes: 19 additions & 0 deletions gigaclub_translation/models/gc_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@
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(

Check warning on line 41 in gigaclub_translation/models/gc_translation.py

View check run for this annotation

Codecov / codecov/patch

gigaclub_translation/models/gc_translation.py#L41

Added line #L41 was not covered by tests
[("write_date", ">", date)]
)
else:
entries = self.env["gc.translation.entry"].search([])

Check warning on line 45 in gigaclub_translation/models/gc_translation.py

View check run for this annotation

Codecov / codecov/patch

gigaclub_translation/models/gc_translation.py#L45

Added line #L45 was not covered by tests
return [
{
"name": entry.translation_id.name,
"content": entry.content,
"lang": entry.lang,
}
for entry in entries
]
Loading