Skip to content

Commit

Permalink
[ReTrigger] 2.29.0 Add toggle for including threads in allow/blocklist
Browse files Browse the repository at this point in the history
- Add `[p]retrigger edit includethreads` which will toggle whether or not an allow/blocklist channel will include threads within that channel to be allowed/blocked. Forum channels can only contain threads so this is not affected by that toggle.
  • Loading branch information
TrustyJAID committed Aug 19, 2024
1 parent 46cb029 commit 9991737
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 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.6.0 | <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.28.2 | <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.29.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.2 | <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/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ Edit various settings in a set trigger. under `[p]retrigger edit`
### readthreads
- Toggle whether a filter trigger will check thread titles.
- This only works in conjunction with delete triggers. If a thread is created with a title that would match the delete triggers pattern the thread will be deleted. This also requires the bot to have manage_threads permission in the channel the threads are created in.
### includethreads
- Toggle whether the allowlist/blocklist will include threads within the channel.
- This will allow a trigger to run only within a channel and not within threads if the channel is added to the allowlist or only run within threads in a channel if the channel is added to the blocklist. Forum channels can only have threads so are exempt from this toggle.
### nsfw
- Toggle whether a trigger is considered NSFW preventing it from activating in non Age Restricted channels.
### reply
Expand Down
17 changes: 13 additions & 4 deletions retrigger/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ class Trigger:
"nsfw",
"read_embeds",
"read_thread_title",
"include_threads",
"_created_at",
"thread",
"remove_roles",
Expand Down Expand Up @@ -348,6 +349,7 @@ def __init__(
self.nsfw: bool = kwargs.get("nsfw", False)
self.read_embeds: bool = kwargs.get("read_embeds", False)
self.read_thread_title: bool = kwargs.get("read_thread_title", True)
self.include_threads: bool = kwargs.get("include_threads", True)
self.thread: TriggerThread = kwargs.get("thread", TriggerThread())
self.remove_roles: List[int] = kwargs.get("remove_roles", [])
self.add_roles: List[int] = kwargs.get("add_roles", [])
Expand Down Expand Up @@ -466,8 +468,11 @@ async def check_bw_list(
can_run = True
if channel.category_id and channel.category_id in self.whitelist:
can_run = True
if isinstance(channel, (discord.Thread, discord.ForumChannel)):
if channel.parent.id in self.whitelist:
if isinstance(channel, discord.Thread):
include_threads = self.include_threads or isinstance(
channel.parent, discord.ForumChannel
)
if channel.parent.id in self.whitelist and include_threads:
# this is a thread
can_run = True
if author is not None:
Expand All @@ -484,8 +489,11 @@ async def check_bw_list(
can_run = False
if channel.category_id and channel.category_id in self.blacklist:
can_run = False
if isinstance(channel, (discord.Thread, discord.ForumChannel)):
if channel.parent.id in self.blacklist:
if isinstance(channel, discord.Thread):
include_threads = self.include_threads or isinstance(
channel.parent, discord.ForumChannel
)
if channel.parent.id in self.blacklist and include_threads:
# this is a thread
can_run = False
if author is not None:
Expand Down Expand Up @@ -566,6 +574,7 @@ async def to_json(self) -> dict:
"nsfw": self.nsfw,
"read_embeds": self.read_embeds,
"read_thread_title": self.read_thread_title,
"include_threads": self.include_threads,
"thread": self.thread.to_json(),
"remove_roles": self.remove_roles,
"add_roles": self.add_roles,
Expand Down
6 changes: 6 additions & 0 deletions retrigger/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,14 @@ async def format_page(self, view: ReTriggerMenu, trigger: Trigger):
info += _("__Roles Added__: Deleted Roles\n")
if whitelist_s:
info += _("__Allowlist__: ") + whitelist_s + "\n"
info += _("- Threads included: {true_or_false}\n").format(
true_or_false=trigger.include_threads
)
if blacklist_s:
info += _("__Blocklist__: ") + blacklist_s + "\n"
info += _("- Threads included: {true_or_false}\n").format(
true_or_false=trigger.include_threads
)
if trigger.cooldown:
time = trigger.cooldown["time"]
style = trigger.cooldown["style"]
Expand Down
31 changes: 30 additions & 1 deletion retrigger/retrigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ReTrigger(
"""

__author__ = ["TrustyJAID"]
__version__ = "2.28.2"
__version__ = "2.29.0"

def __init__(self, bot):
super().__init__()
Expand Down Expand Up @@ -879,6 +879,35 @@ async def toggle_read_threads(
)
await ctx.send(msg)

@_edit.command(name="includethreads")
@checks.mod_or_permissions(manage_messages=True)
@wrapped_additional_help()
async def toggle_include_threads(
self, ctx: commands.Context, trigger: Trigger = commands.parameter(converter=TriggerExists)
) -> None:
"""
Toggle whether the allowlist/blocklist will include threads within the channel.
`<trigger>` is the name of the trigger.
This will allow a trigger to run only within a channel and not within threads if
the channel is added to the allowlist or only run within threads in a channel if
the channel is added to the blocklist. Forum channels can only have threads
so are exempt from this toggle.
# Note: this only affects allowed/blocked triggers for specific channels.
"""
if type(trigger) is str:
return await self._no_trigger(ctx, trigger)

# trigger.read_thread_title = not trigger.read_thread_title
trigger.modify("include_threads", not trigger.include_threads, 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()
msg = _("Trigger {name} Include Threads: {read_threads}").format(
name=trigger.name, read_threads=trigger.include_threads
)
await ctx.send(msg)

@_edit.command(name="readfilenames", aliases=["filenames"])
@checks.mod_or_permissions(manage_messages=True)
@wrapped_additional_help()
Expand Down

0 comments on commit 9991737

Please sign in to comment.