@@ -759,7 +759,7 @@ async def contact(
759759
760760 await ctx .send (embed = embed )
761761
762- @commands .command ( )
762+ @commands .group ( invoke_without_command = True )
763763 @checks .has_permissions (PermissionLevel .MODERATOR )
764764 @trigger_typing
765765 async def blocked (self , ctx ):
@@ -804,6 +804,63 @@ async def blocked(self, ctx):
804804
805805 await PaginatorSession (ctx , * embeds ).run ()
806806
807+ @blocked .command (name = "whitelist" )
808+ @checks .has_permissions (PermissionLevel .MODERATOR )
809+ @trigger_typing
810+ async def blocked_whitelist (self , ctx , * , user : User = None ):
811+ """
812+ Whitelist or un-whitelist a user from getting blocked.
813+
814+ Useful for preventing users from getting blocked by account_age/guild_age restrictions.
815+ """
816+ if user is None :
817+ thread = ctx .thread
818+ if thread :
819+ user = thread .recipient
820+ else :
821+ return await ctx .send_help (ctx .command )
822+
823+ mention = getattr (user , "mention" , f"`{ user .id } `" )
824+ msg = ""
825+
826+ if str (user .id ) in self .bot .config .blocked_whitelist :
827+ embed = discord .Embed (
828+ title = "Success" ,
829+ description = f"{ mention } is no longer whitelisted." ,
830+ color = self .bot .main_color ,
831+ )
832+ self .bot .config .blocked_whitelist .remove (str (user .id ))
833+ return await ctx .send (embed = embed )
834+
835+ self .bot .config .blocked_whitelist .append (str (user .id ))
836+
837+ if str (user .id ) in self .bot .blocked_users :
838+ msg = self .bot .blocked_users .get (str (user .id ))
839+ if msg is None :
840+ msg = ""
841+ del self .bot .config .blocked [str (user .id )]
842+
843+ await self .bot .config .update ()
844+
845+ if msg .startswith ("System Message: " ):
846+ # If the user is blocked internally (for example: below minimum account age)
847+ # Show an extended message stating the original internal message
848+ reason = msg [16 :].strip ().rstrip ("." ) or "no reason"
849+ embed = discord .Embed (
850+ title = "Success" ,
851+ description = f"{ mention } was previously blocked internally due to "
852+ f'"{ reason } ". { mention } is now whitelisted.' ,
853+ color = self .bot .main_color ,
854+ )
855+ else :
856+ embed = discord .Embed (
857+ title = "Success" ,
858+ color = self .bot .main_color ,
859+ description = f"{ mention } is now whitelisted." ,
860+ )
861+
862+ return await ctx .send (embed = embed )
863+
807864 @commands .command ()
808865 @checks .has_permissions (PermissionLevel .MODERATOR )
809866 @trigger_typing
@@ -832,6 +889,16 @@ async def block(
832889 else :
833890 raise commands .BadArgument (f'User "{ after .arg } " not found' )
834891
892+ mention = getattr (user , "mention" , f"`{ user .id } `" )
893+
894+ if str (user .id ) in self .bot .config .blocked_whitelist :
895+ embed = discord .Embed (
896+ title = "Error" ,
897+ description = f"Cannot block { mention } , user is whitelisted." ,
898+ color = discord .Color .red (),
899+ )
900+ return await ctx .send (embed = embed )
901+
835902 if after is not None :
836903 reason = after .arg
837904 if reason .startswith ("System Message: " ):
@@ -846,8 +913,6 @@ async def block(
846913 if not reason :
847914 reason = None
848915
849- mention = user .mention if hasattr (user , "mention" ) else f"`{ user .id } `"
850-
851916 extend = f" for `{ reason } `" if reason is not None else ""
852917 msg = self .bot .blocked_users .get (str (user .id ), "" )
853918
@@ -901,7 +966,7 @@ async def unblock(self, ctx, *, user: User = None):
901966 else :
902967 raise commands .MissingRequiredArgument (param (name = "user" ))
903968
904- mention = user . mention if hasattr (user , "mention" ) else f"`{ user .id } `"
969+ mention = getattr (user , "mention" , f"`{ user .id } `" )
905970
906971 if str (user .id ) in self .bot .blocked_users :
907972 msg = self .bot .blocked_users .get (str (user .id ))
@@ -920,6 +985,11 @@ async def unblock(self, ctx, *, user: User = None):
920985 f'"{ reason } ". { mention } is no longer blocked.' ,
921986 color = self .bot .main_color ,
922987 )
988+ embed .set_footer (
989+ text = "However, if the original system block reason still apply, "
990+ f"{ mention } will be automatically blocked again. Use "
991+ f'"{ self .bot .prefix } blocked whitelist { mention } " to whitelist the user.'
992+ )
923993 else :
924994 embed = discord .Embed (
925995 title = "Success" ,
0 commit comments