@@ -1050,8 +1050,30 @@ async def blocked(self, ctx):
1050
1050
1051
1051
roles = []
1052
1052
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
1053
1076
1054
- for id_ , reason in self .bot .blocked_users .items ():
1055
1077
user = self .bot .get_user (int (id_ ))
1056
1078
if user :
1057
1079
users .append ((user .mention , reason ))
@@ -1062,7 +1084,28 @@ async def blocked(self, ctx):
1062
1084
except discord .NotFound :
1063
1085
users .append ((id_ , reason ))
1064
1086
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
+
1066
1109
role = self .bot .guild .get_role (int (id_ ))
1067
1110
if role :
1068
1111
roles .append ((role .mention , reason ))
@@ -1175,7 +1218,7 @@ async def block(
1175
1218
after : UserFriendlyTime = None ,
1176
1219
):
1177
1220
"""
1178
- Block a user from using Modmail.
1221
+ Block a user or role from using Modmail.
1179
1222
1180
1223
You may choose to set a time as to when the user will automatically be unblocked.
1181
1224
@@ -1190,9 +1233,9 @@ async def block(
1190
1233
if thread :
1191
1234
user_or_role = thread .recipient
1192
1235
elif after is None :
1193
- raise commands .MissingRequiredArgument (SimpleNamespace (name = "user" ))
1236
+ raise commands .MissingRequiredArgument (SimpleNamespace (name = "user or role " ))
1194
1237
else :
1195
- raise commands .BadArgument (f'User "{ after .arg } " not found.' )
1238
+ raise commands .BadArgument (f'User or role "{ after .arg } " not found.' )
1196
1239
1197
1240
mention = getattr (user_or_role , "mention" , f"`{ user_or_role .id } `" )
1198
1241
0 commit comments