Skip to content

Commit

Permalink
[ReTrigger] 2.28.0 Add a setting to let triggers suppress embeds on t…
Browse files Browse the repository at this point in the history
…he message
  • Loading branch information
TrustyJAID committed Mar 8, 2024
1 parent df77827 commit 3f29eba
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TrustyJAID's Cogs for [Red-DiscordBot](https://github.com/Cog-Creators/Red-Disc
| NotSoBot | 2.5.5 | <details><summary>Some working commands from NotSoBot</summary>Magick, trigger and manipulate images with many commands from NotSoSuper's NotSoBot. This cog has a lot of requirements, view the [cog README.md](https://github.com/TrustyJAID/Trusty-cogs/blob/master/notsobot/README.md) for details. </details> | NotSoSuper and TrustyJAID |
| Reddit | 1.2.0 | <details><summary>A cog to post updates from reddit.</summary>Reddit commands for getting updates on specified subreddits.</details> | TrustyJAID |
| Rekt | 1.0.0 | <details><summary>Get REKT</summary>Are you REKT?</details> | TrustyJAID |
| ReTrigger | 2.27.1 | <details><summary>Trigger events via Regular Expressions!</summary>Trigger events based on regex! Check out <https://regex101.com/> and <https://github.com/TrustyJAID/Trusty-cogs/blob/master/retrigger/README.md> for help setting up the cog. Note: This cog can become quite resource heavy. Optional features are available if the requirements are present such as pillow for image resizing and pytesseract to scan images for text (OCR).</details> | TrustyJAID |
| ReTrigger | 2.28.0 | <details><summary>Trigger events via Regular Expressions!</summary>Trigger events based on regex! Check out <https://regex101.com/> and <https://github.com/TrustyJAID/Trusty-cogs/blob/master/retrigger/README.md> for help setting up the cog. Note: This cog can become quite resource heavy. Optional features are available if the requirements are present such as pillow for image resizing and pytesseract to scan images for text (OCR).</details> | TrustyJAID |
| RoleTools | 1.5.12 | <details><summary>Various role related tools.</summary>Various role utility commands. Including Reaction roles, Sticky roles, and Auto role.</details> | TrustyJAID |
| runescape | 1.5.1 | <details><summary>Show your Runescape stats in discord!</summary>A cog to grab Runescape and OSRS stats and profile information.</details> | TrustyJAID |
| ServerStats | 1.8.0 | <details><summary>A plethora of potentially useful commands for any bot owner.</summary>A plethora of potentially useful commands for any bot owner. Includes a way to track the bot joining new servers, find cheaters on global economies, get user avatars and even larger emojis.</details> | TrustyJAID and Preda |
Expand Down
3 changes: 3 additions & 0 deletions retrigger/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class Trigger:
"_last_modified_by",
"_last_modified_at",
"_last_modified",
"suppress",
)

def __init__(
Expand Down Expand Up @@ -314,6 +315,7 @@ def __init__(
self._last_modified_by: Optional[int] = kwargs.get("_last_modified_by", None)
self._last_modified_at: Optional[int] = kwargs.get("_last_modified_at", None)
self._last_modified: Optional[str] = kwargs.get("_last_modified", None)
self.suppress: bool = kwargs.get("suppress", False)

def enable(self):
"""Explicitly enable this trigger"""
Expand Down Expand Up @@ -526,6 +528,7 @@ async def to_json(self) -> dict:
"_last_modified_by": self._last_modified_by,
"_last_modified_at": self._last_modified_at,
"_last_modified": self._last_modified,
"suppress": self.suppress,
}

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions retrigger/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ async def format_page(self, view: ReTriggerMenu, trigger: Trigger):
pattern = trigger._raw_regex
if trigger.read_embeds:
info += _("__Read Embeds__: **Enabled**\n")
if trigger.suppress:
info += _("__Suppress Embeds__: **Enabled**\n")
if embeds:
# info += _("__Regex__: ") + box(trigger.regex.pattern, lang="bf")
em = discord.Embed(
Expand Down
29 changes: 28 additions & 1 deletion retrigger/retrigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ReTrigger(
"""

__author__ = ["TrustyJAID"]
__version__ = "2.27.1"
__version__ = "2.28.0"

def __init__(self, bot):
super().__init__()
Expand Down Expand Up @@ -813,6 +813,33 @@ async def toggle_read_embeds(
)
await ctx.send(msg)

@_edit.command(name="suppress")
@checks.mod_or_permissions(manage_messages=True)
@wrapped_additional_help()
async def toggle_suppress_embeds(
self, ctx: commands.Context, trigger: Trigger = commands.parameter(converter=TriggerExists)
) -> None:
"""
Toggle whether a trigger will suppress original message embeds.
This will cause the original message embeds to be disabled for everyone.
Useful if you're wanting to remove the embed of a url and replace with a new url.
`<trigger>` is the name of the trigger.
"""
if type(trigger) is str:
return await self._no_trigger(ctx, trigger)

# trigger.read_embeds = not trigger.read_embeds
trigger.modify("suppress", not trigger.suppress, ctx.author, ctx.message.id)
async with self.config.guild(ctx.guild).trigger_list() as trigger_list:
trigger_list[trigger.name] = await trigger.to_json()
# await self.remove_trigger_from_cache(ctx.guild.id, trigger)
# self.triggers[ctx.guild.id].append(trigger)
msg = _("Trigger {name} suppress embeds set to: {embeds}").format(
name=trigger.name, embeds=trigger.suppress
)
await ctx.send(msg)

@_edit.command(name="readthreads", aliases=["readthread"])
@checks.mod_or_permissions(manage_messages=True)
@wrapped_additional_help()
Expand Down
8 changes: 8 additions & 0 deletions retrigger/triggerhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,14 @@ async def perform_trigger(
reason = _("Trigger response: {trigger}").format(trigger=trigger.name)
own_permissions = channel.permissions_for(guild.me)
# is_thread_message = getattr(message, "is_thread", False)
if trigger.suppress and message.embeds and own_permissions.manage_messages:
try:
await message.edit(suppress=True)
except Exception:
log.exception(
"Error suppressing embeds on a message: %r with trigger %r", message, trigger
)

if isinstance(channel, discord.TextChannel):
# currently only text channels are capable of creating threads from
# a message being sent. Forum Chanels can't have sent messages by
Expand Down

0 comments on commit 3f29eba

Please sign in to comment.