Skip to content

Commit 7ac59e0

Browse files
committed
?blocked now no longers show blocks that have expired.
1 parent 6e62ce8 commit 7ac59e0

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s
2727
- Mentioned `competing` as an activity type. ([PR #2902](https://github.com/kyb3r/modmail/pull/2902))
2828
- Level permissions were not checked if command permissions were set.
2929
- Regex autotriggers were not working if term was in the middle of strings.
30+
- `?blocked` now no longers show blocks that have expired.
3031

3132
### Internal
3233

bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.7.14-dev5"
1+
__version__ = "3.7.14-dev6"
22

33

44
import asyncio

cogs/modmail.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,30 @@ async def blocked(self, ctx):
10501050

10511051
roles = []
10521052
users = []
1053+
now = ctx.message.created_at
1054+
1055+
blocked_users = list(self.bot.blocked_users.items())
1056+
for id_, reason in blocked_users:
1057+
# parse "reason" and check if block is expired
1058+
# etc "blah blah blah... until 2019-10-14T21:12:45.559948."
1059+
end_time = re.search(r"until ([^`]+?)\.$", reason)
1060+
if end_time is None:
1061+
# backwards compat
1062+
end_time = re.search(r"%([^%]+?)%", reason)
1063+
if end_time is not None:
1064+
logger.warning(
1065+
r"Deprecated time message for user %s, block and unblock again to update.",
1066+
id_,
1067+
)
1068+
1069+
if end_time is not None:
1070+
after = (datetime.fromisoformat(end_time.group(1)) - now).total_seconds()
1071+
if after <= 0:
1072+
# No longer blocked
1073+
self.bot.blocked_users.pop(str(id_))
1074+
logger.debug("No longer blocked, user %s.", id_)
1075+
continue
10531076

1054-
for id_, reason in self.bot.blocked_users.items():
10551077
user = self.bot.get_user(int(id_))
10561078
if user:
10571079
users.append((user.mention, reason))
@@ -1062,7 +1084,28 @@ async def blocked(self, ctx):
10621084
except discord.NotFound:
10631085
users.append((id_, reason))
10641086

1065-
for id_, reason in self.bot.blocked_roles.items():
1087+
blocked_roles = list(self.bot.blocked_roles.items())
1088+
for id_, reason in blocked_roles:
1089+
# parse "reason" and check if block is expired
1090+
# etc "blah blah blah... until 2019-10-14T21:12:45.559948."
1091+
end_time = re.search(r"until ([^`]+?)\.$", reason)
1092+
if end_time is None:
1093+
# backwards compat
1094+
end_time = re.search(r"%([^%]+?)%", reason)
1095+
if end_time is not None:
1096+
logger.warning(
1097+
r"Deprecated time message for role %s, block and unblock again to update.",
1098+
id_,
1099+
)
1100+
1101+
if end_time is not None:
1102+
after = (datetime.fromisoformat(end_time.group(1)) - now).total_seconds()
1103+
if after <= 0:
1104+
# No longer blocked
1105+
self.bot.blocked_roles.pop(str(id_))
1106+
logger.debug("No longer blocked, role %s.", id_)
1107+
continue
1108+
10661109
role = self.bot.guild.get_role(int(id_))
10671110
if role:
10681111
roles.append((role.mention, reason))
@@ -1175,7 +1218,7 @@ async def block(
11751218
after: UserFriendlyTime = None,
11761219
):
11771220
"""
1178-
Block a user from using Modmail.
1221+
Block a user or role from using Modmail.
11791222
11801223
You may choose to set a time as to when the user will automatically be unblocked.
11811224
@@ -1190,9 +1233,9 @@ async def block(
11901233
if thread:
11911234
user_or_role = thread.recipient
11921235
elif after is None:
1193-
raise commands.MissingRequiredArgument(SimpleNamespace(name="user"))
1236+
raise commands.MissingRequiredArgument(SimpleNamespace(name="user or role"))
11941237
else:
1195-
raise commands.BadArgument(f'User "{after.arg}" not found.')
1238+
raise commands.BadArgument(f'User or role "{after.arg}" not found.')
11961239

11971240
mention = getattr(user_or_role, "mention", f"`{user_or_role.id}`")
11981241

0 commit comments

Comments
 (0)