Skip to content

Commit 937d6fd

Browse files
committed
Fix block
1 parent b3875bb commit 937d6fd

File tree

3 files changed

+47
-52
lines changed

3 files changed

+47
-52
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ however, insignificant breaking changes does not guarantee a major version bump,
99

1010
# v3.3.0-dev2
1111

12+
13+
### Important
14+
15+
- Recommend all users to unblock and re-block all blocked users upon updating to this release.
16+
1217
### Added
1318

1419
- Three new config vars:
@@ -39,6 +44,7 @@ however, insignificant breaking changes does not guarantee a major version bump,
3944
- Add travis checks for 3.6 in Linux and 3.7 for MacOS and Windows.
4045
- Eval commands are logged in debug logs.
4146
- Presence updates 30 minutes instead of 45 now.
47+
- Fixed an assortment of problems to do with block.
4248

4349
### Internal
4450

bot.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.3.0-dev2"
1+
__version__ = "3.3.0-dev3"
22

33
import asyncio
44
import logging
@@ -676,16 +676,26 @@ async def _process_blocked(self, message: discord.Message) -> bool:
676676
self.blocked_users.pop(str(message.author.id))
677677
else:
678678
reaction = blocked_emoji
679-
end_time = re.search(r"%(.+?)%", reason)
679+
# etc "blah blah blah... until 2019-10-14T21:12:45.559948."
680+
end_time = re.search(r"until ([^`]+?)\.$", reason)
681+
if end_time is None:
682+
# backwards compat
683+
end_time = re.search(r"%([^%]+?)%", reason)
684+
if end_time is not None:
685+
logger.warning(r"Deprecated time message for user %s, block and unblock again to update.",
686+
message.author)
687+
680688
if end_time is not None:
681-
logger.debug("No longer blocked, user %s.", message.author.name)
682689
after = (
683690
datetime.fromisoformat(end_time.group(1)) - now
684691
).total_seconds()
685692
if after <= 0:
686693
# No longer blocked
687694
reaction = sent_emoji
688695
self.blocked_users.pop(str(message.author.id))
696+
logger.debug("No longer blocked, user %s.", message.author.name)
697+
else:
698+
logger.debug("User blocked, user %s.", message.author.name)
689699
else:
690700
logger.debug("User blocked, user %s.", message.author.name)
691701
else:

cogs/modmail.py

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -953,15 +953,15 @@ async def blocked(self, ctx):
953953
else:
954954
try:
955955
user = await self.bot.fetch_user(id_)
956-
users.append((str(user), reason))
956+
users.append((user.mention, reason))
957957
except discord.NotFound:
958-
pass
958+
users.append((id_, reason))
959959

960960
if users:
961961
embed = embeds[0]
962962

963963
for mention, reason in users:
964-
line = mention + f" - `{reason or 'No reason provided'}`\n"
964+
line = mention + f" - {reason or 'No Reason Provided'}\n"
965965
if len(embed.description) + len(line) > 2048:
966966
embed = discord.Embed(
967967
title="Blocked Users (Continued)",
@@ -1008,20 +1008,18 @@ async def blocked_whitelist(self, ctx, *, user: User = None):
10081008
self.bot.blocked_whitelisted_users.append(str(user.id))
10091009

10101010
if str(user.id) in self.bot.blocked_users:
1011-
msg = self.bot.blocked_users.get(str(user.id))
1012-
if msg is None:
1013-
msg = ""
1011+
msg = self.bot.blocked_users.get(str(user.id)) or ""
10141012
self.bot.blocked_users.pop(str(user.id))
10151013

10161014
await self.bot.config.update()
10171015

10181016
if msg.startswith("System Message: "):
10191017
# If the user is blocked internally (for example: below minimum account age)
10201018
# Show an extended message stating the original internal message
1021-
reason = msg[16:].strip().rstrip(".") or "no reason"
1019+
reason = msg[16:].strip().rstrip(".")
10221020
embed = discord.Embed(
10231021
title="Success",
1024-
description=f"{mention} was previously blocked internally due to "
1022+
description=f"{mention} was previously blocked internally for "
10251023
f'"{reason}". {mention} is now whitelisted.',
10261024
color=self.bot.main_color,
10271025
)
@@ -1051,8 +1049,6 @@ async def block(
10511049
`duration` may be a simple "human-readable" time text. See `{prefix}help close` for examples.
10521050
"""
10531051

1054-
reason = ""
1055-
10561052
if user is None:
10571053
thread = ctx.thread
10581054
if thread:
@@ -1064,8 +1060,6 @@ async def block(
10641060

10651061
mention = getattr(user, "mention", f"`{user.id}`")
10661062

1067-
moderator = ctx.author.name
1068-
10691063
if str(user.id) in self.bot.blocked_whitelisted_users:
10701064
embed = discord.Embed(
10711065
title="Error",
@@ -1074,53 +1068,38 @@ async def block(
10741068
)
10751069
return await ctx.send(embed=embed)
10761070

1071+
reason = f"by {escape_markdown(ctx.author.name)}#{ctx.author.discriminator}"
1072+
10771073
if after is not None:
1078-
reason = f"{after.arg} by {moderator}"
1079-
if reason.startswith("System Message: "):
1080-
raise commands.BadArgument(
1081-
"The reason cannot start with `System Message:`."
1082-
)
10831074
if "%" in reason:
10841075
raise commands.BadArgument('The reason contains illegal character "%".')
1076+
if after.arg:
1077+
reason += f" for `{after.arg}`"
10851078
if after.dt > after.now:
1086-
reason = f"{reason} %{after.dt.isoformat()}% by {moderator}"
1079+
reason += f" until {after.dt.isoformat()}"
10871080

1088-
if not reason:
1089-
reason = f"Blocked by {moderator}"
1081+
reason += "."
10901082

1091-
extend = f" for `{reason}`" if reason is not None else ""
10921083
msg = self.bot.blocked_users.get(str(user.id))
10931084
if msg is None:
10941085
msg = ""
10951086

1096-
if (
1097-
str(user.id) not in self.bot.blocked_users
1098-
or reason is not None
1099-
or msg.startswith("System Message: ")
1100-
):
1101-
if str(user.id) in self.bot.blocked_users:
1102-
1103-
old_reason = msg.strip().rstrip(".") or f"Blocked by {moderator}"
1104-
embed = discord.Embed(
1105-
title="Success",
1106-
description=f"{mention} was previously blocked for "
1107-
f'"{old_reason}". {mention} is now blocked{extend}.',
1108-
color=self.bot.main_color,
1109-
)
1110-
else:
1111-
embed = discord.Embed(
1112-
title="Success",
1113-
color=self.bot.main_color,
1114-
description=f"{mention} is now blocked{extend}.",
1115-
)
1116-
self.bot.blocked_users[str(user.id)] = reason
1117-
await self.bot.config.update()
1087+
if str(user.id) in self.bot.blocked_users and msg:
1088+
old_reason = msg.strip().rstrip(".")
1089+
embed = discord.Embed(
1090+
title="Success",
1091+
description=f"{mention} was previously blocked "
1092+
f'{old_reason}.\n{mention} is now blocked {reason}',
1093+
color=self.bot.main_color,
1094+
)
11181095
else:
11191096
embed = discord.Embed(
1120-
title="Error",
1121-
color=self.bot.error_color,
1122-
description=f"{mention} is already blocked.",
1097+
title="Success",
1098+
color=self.bot.main_color,
1099+
description=f"{mention} is now blocked {reason}",
11231100
)
1101+
self.bot.blocked_users[str(user.id)] = reason
1102+
await self.bot.config.update()
11241103

11251104
return await ctx.send(embed=embed)
11261105

@@ -1156,12 +1135,12 @@ async def unblock(self, ctx, *, user: User = None):
11561135
reason = msg[16:].strip().rstrip(".") or "no reason"
11571136
embed = discord.Embed(
11581137
title="Success",
1159-
description=f"{mention} was previously blocked internally due to "
1160-
f'"{reason}". {mention} is no longer blocked.',
1138+
description=f"{mention} was previously blocked internally "
1139+
f'{reason}.\n{mention} is no longer blocked.',
11611140
color=self.bot.main_color,
11621141
)
11631142
embed.set_footer(
1164-
text="However, if the original system block reason still apply, "
1143+
text="However, if the original system block reason still applies, "
11651144
f"{name} will be automatically blocked again. Use "
11661145
f'"{self.bot.prefix}blocked whitelist {user.id}" to whitelist the user.'
11671146
)

0 commit comments

Comments
 (0)