4747)
4848from core .thread import ThreadManager
4949from core .time import human_timedelta
50- from core .utils import normalize_alias , parse_alias , truncate , tryint
50+ from core .utils import extract_block_timestamp , normalize_alias , parse_alias , truncate , tryint
5151
5252logger = getLogger (__name__ )
5353
@@ -735,21 +735,13 @@ def check_manual_blocked_roles(self, author: discord.Member) -> bool:
735735 if str (r .id ) in self .blocked_roles :
736736
737737 blocked_reason = self .blocked_roles .get (str (r .id )) or ""
738- now = discord .utils .utcnow ()
739-
740- # etc "blah blah blah... until 2019-10-14T21:12:45.559948."
741- end_time = re .search (r"until ([^`]+?)\.$" , blocked_reason )
742- if end_time is None :
743- # backwards compat
744- end_time = re .search (r"%([^%]+?)%" , blocked_reason )
745- if end_time is not None :
746- logger .warning (
747- r"Deprecated time message for role %s, block and unblock again to update." ,
748- r .name ,
749- )
738+
739+ try :
740+ end_time , after = extract_block_timestamp (blocked_reason , author .id )
741+ except ValueError :
742+ return False
750743
751744 if end_time is not None :
752- after = (datetime .fromisoformat (end_time .group (1 )) - now ).total_seconds ()
753745 if after <= 0 :
754746 # No longer blocked
755747 self .blocked_roles .pop (str (r .id ))
@@ -765,26 +757,19 @@ def check_manual_blocked(self, author: discord.Member) -> bool:
765757 return True
766758
767759 blocked_reason = self .blocked_users .get (str (author .id )) or ""
768- now = discord .utils .utcnow ()
769760
770761 if blocked_reason .startswith ("System Message:" ):
771762 # Met the limits already, otherwise it would've been caught by the previous checks
772763 logger .debug ("No longer internally blocked, user %s." , author .name )
773764 self .blocked_users .pop (str (author .id ))
774765 return True
775- # etc "blah blah blah... until 2019-10-14T21:12:45.559948."
776- end_time = re .search (r"until ([^`]+?)\.$" , blocked_reason )
777- if end_time is None :
778- # backwards compat
779- end_time = re .search (r"%([^%]+?)%" , blocked_reason )
780- if end_time is not None :
781- logger .warning (
782- r"Deprecated time message for user %s, block and unblock again to update." ,
783- author .name ,
784- )
766+
767+ try :
768+ end_time , after = extract_block_timestamp (blocked_reason , author .id )
769+ except ValueError :
770+ return False
785771
786772 if end_time is not None :
787- after = (datetime .fromisoformat (end_time .group (1 )) - now ).total_seconds ()
788773 if after <= 0 :
789774 # No longer blocked
790775 self .blocked_users .pop (str (author .id ))
@@ -891,7 +876,7 @@ async def add_reaction(
891876 if reaction != "disable" :
892877 try :
893878 await msg .add_reaction (reaction )
894- except (discord .HTTPException , discord .InvalidArgument ) as e :
879+ except (discord .HTTPException , discord .BadArgument ) as e :
895880 logger .warning ("Failed to add reaction %s: %s." , reaction , e )
896881 return False
897882 return True
@@ -1316,7 +1301,7 @@ async def handle_reaction_events(self, payload):
13161301 for msg in linked_messages :
13171302 await msg .remove_reaction (reaction , self .user )
13181303 await message .remove_reaction (reaction , self .user )
1319- except (discord .HTTPException , discord .InvalidArgument ) as e :
1304+ except (discord .HTTPException , discord .BadArgument ) as e :
13201305 logger .warning ("Failed to remove reaction: %s" , e )
13211306
13221307 async def handle_react_to_contact (self , payload ):
0 commit comments