aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-01-16 18:55:26 +0100
committerGravatar Matteo Bertucci <[email protected]>2021-01-17 16:11:14 +0100
commiteb78b9c261ecbcea4b2ca5bb0d423f7b3bfb9a0f (patch)
treed078a0e3b04c058654a2dd329b785a6d169818f7
parentAdd an allow_moderation_roles argument to the wait_for_deletion() util (diff)
Restrict paginator usage to the author and moderators
-rw-r--r--bot/pagination.py13
-rw-r--r--bot/utils/messages.py2
2 files changed, 11 insertions, 4 deletions
diff --git a/bot/pagination.py b/bot/pagination.py
index 182b2fa76..09dbad7b5 100644
--- a/bot/pagination.py
+++ b/bot/pagination.py
@@ -8,6 +8,7 @@ from discord.abc import User
from discord.ext.commands import Context, Paginator
from bot import constants
+from bot.constants import MODERATION_ROLES
FIRST_EMOJI = "\u23EE" # [:track_previous:]
LEFT_EMOJI = "\u2B05" # [:arrow_left:]
@@ -210,6 +211,9 @@ class LinePaginator(Paginator):
Pagination will also be removed automatically if no reaction is added for five minutes (300 seconds).
+ The interaction will be limited to `restrict_to_user` (ctx.author by default) or
+ to any user with a moderation role.
+
Example:
>>> embed = discord.Embed()
>>> embed.set_author(name="Some Operation", url=url, icon_url=icon)
@@ -218,10 +222,10 @@ class LinePaginator(Paginator):
def event_check(reaction_: discord.Reaction, user_: discord.Member) -> bool:
"""Make sure that this reaction is what we want to operate on."""
no_restrictions = (
- # Pagination is not restricted
- not restrict_to_user
# The reaction was by a whitelisted user
- or user_.id == restrict_to_user.id
+ user_.id == restrict_to_user.id
+ # The reaction was by a moderator
+ or any(role.id in MODERATION_ROLES for role in user_.roles)
)
return (
@@ -242,6 +246,9 @@ class LinePaginator(Paginator):
scale_to_size=scale_to_size)
current_page = 0
+ if not restrict_to_user:
+ restrict_to_user = ctx.author
+
if not lines:
if exception_on_empty_embed:
log.exception("Pagination asked for empty lines iterable")
diff --git a/bot/utils/messages.py b/bot/utils/messages.py
index b0b6cbf82..832ad4d55 100644
--- a/bot/utils/messages.py
+++ b/bot/utils/messages.py
@@ -11,7 +11,7 @@ from discord.errors import HTTPException
from discord.ext.commands import Context
import bot
-from bot.constants import Emojis, NEGATIVE_REPLIES, MODERATION_ROLES
+from bot.constants import Emojis, MODERATION_ROLES, NEGATIVE_REPLIES
log = logging.getLogger(__name__)