Skip to content

Commit

Permalink
[RoleTools] 1.5.13 Allow sending buttons without content
Browse files Browse the repository at this point in the history
- Rename message to text when sending buttons and/or select menus and make the text optional.
  • Loading branch information
TrustyJAID committed Sep 13, 2024
1 parent 7d4f246 commit 4555676
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TrustyJAID's Cogs for [Red-DiscordBot](https://github.com/Cog-Creators/Red-Disc
| 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.29.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 |
| 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 |
| RoleTools | 1.5.13 | <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 |
| Spotify | 1.7.3 | <details><summary>Control Spotify through Discord!</summary>This cog allows you to control Spotify via OAuth through the bot on discord. Use `[p]spotify` to see available commands.</details> | TrustyJAID and NeuroAssassin |
Expand Down
24 changes: 13 additions & 11 deletions roletools/messages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import List
from typing import List, Optional

import discord
from red_commons.logging import getLogger
Expand Down Expand Up @@ -45,7 +45,7 @@ async def send_message(
buttons: commands.Greedy[ButtonRoleConverter],
menus: commands.Greedy[SelectRoleConverter],
*,
message: str,
text: Optional[str] = None,
) -> None:
"""
Send a select menu to a specified channel for role assignment
Expand All @@ -54,7 +54,7 @@ async def send_message(
`[buttons]...` - The names of the buttons you want included in the
`[menus]...` - The names of the select menus you want included in the
message up to a maximum of 5.
`<message>` - The message to be included with the select menu.
`[text]` - The text to be included with the select menu.
Note: There is a maximum of 25 slots available on one message. Each menu
uses up 5 slots while each button uses up 1 slot.
Expand All @@ -77,8 +77,8 @@ async def send_message(
new_view.add_item(select)
for button in buttons:
new_view.add_item(button)

msg = await channel.send(content=message[:2000], view=new_view)
content = text[:2000] if text else None
msg = await channel.send(content=content, view=new_view)
message_key = f"{msg.channel.id}-{msg.id}"

await self.save_settings(ctx.guild, message_key, buttons=buttons, select_menus=menus)
Expand Down Expand Up @@ -176,15 +176,15 @@ async def send_select(
channel: discord.TextChannel,
menus: commands.Greedy[SelectRoleConverter],
*,
message: str,
text: Optional[str] = None,
) -> None:
"""
Send a select menu to a specified channel for role assignment
`<channel>` - the channel to send the button role buttons to.
`[menus]...` - The names of the select menus you want included in the
message up to a maximum of 5.
`<message>` - The message to be included with the select menu.
`[text]` - The text to be included with the select menu.
"""
if not channel.permissions_for(ctx.me).send_messages:
await ctx.send(
Expand All @@ -207,7 +207,8 @@ async def send_select(
return
for select in menus:
new_view.add_item(select)
msg = await channel.send(content=message, view=new_view)
content = text[:2000] if text else None
msg = await channel.send(content=content, view=new_view)
message_key = f"{msg.channel.id}-{msg.id}"

await self.save_settings(ctx.guild, message_key, buttons=[], select_menus=menus)
Expand Down Expand Up @@ -257,15 +258,15 @@ async def send_buttons(
channel: discord.TextChannel,
buttons: commands.Greedy[ButtonRoleConverter],
*,
message: str,
text: Optional[str] = None,
) -> None:
"""
Send buttons to a specified channel with optional message.
`<channel>` - the channel to send the button role buttons to.
`[buttons]...` - The names of the buttons you want included in the
message up to a maximum of 25.
`<message>` - The message to be included with the buttons.
`[text]` - The text to be included with the buttons.
"""
if not channel.permissions_for(ctx.me).send_messages:
await ctx.send(
Expand All @@ -282,7 +283,8 @@ async def send_buttons(
log.verbose("send_buttons buttons: %s", buttons)
for button in buttons:
new_view.add_item(button)
msg = await channel.send(content=message, view=new_view)
content = text[:2000] if text else None
msg = await channel.send(content=content, view=new_view)
message_key = f"{msg.channel.id}-{msg.id}"

await self.save_settings(ctx.guild, message_key, buttons=buttons, select_menus=[])
Expand Down
2 changes: 1 addition & 1 deletion roletools/roletools.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class RoleTools(
"""

__author__ = ["TrustyJAID"]
__version__ = "1.5.12"
__version__ = "1.5.13"

def __init__(self, bot: Red):
self.bot = bot
Expand Down

0 comments on commit 4555676

Please sign in to comment.