@@ -759,7 +759,7 @@ async def contact(
759
759
760
760
await ctx .send (embed = embed )
761
761
762
- @commands .command ( )
762
+ @commands .group ( invoke_without_command = True )
763
763
@checks .has_permissions (PermissionLevel .MODERATOR )
764
764
@trigger_typing
765
765
async def blocked (self , ctx ):
@@ -804,6 +804,63 @@ async def blocked(self, ctx):
804
804
805
805
await PaginatorSession (ctx , * embeds ).run ()
806
806
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
+
807
864
@commands .command ()
808
865
@checks .has_permissions (PermissionLevel .MODERATOR )
809
866
@trigger_typing
@@ -832,6 +889,16 @@ async def block(
832
889
else :
833
890
raise commands .BadArgument (f'User "{ after .arg } " not found' )
834
891
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
+
835
902
if after is not None :
836
903
reason = after .arg
837
904
if reason .startswith ("System Message: " ):
@@ -846,8 +913,6 @@ async def block(
846
913
if not reason :
847
914
reason = None
848
915
849
- mention = user .mention if hasattr (user , "mention" ) else f"`{ user .id } `"
850
-
851
916
extend = f" for `{ reason } `" if reason is not None else ""
852
917
msg = self .bot .blocked_users .get (str (user .id ), "" )
853
918
@@ -901,7 +966,7 @@ async def unblock(self, ctx, *, user: User = None):
901
966
else :
902
967
raise commands .MissingRequiredArgument (param (name = "user" ))
903
968
904
- mention = user . mention if hasattr (user , "mention" ) else f"`{ user .id } `"
969
+ mention = getattr (user , "mention" , f"`{ user .id } `" )
905
970
906
971
if str (user .id ) in self .bot .blocked_users :
907
972
msg = self .bot .blocked_users .get (str (user .id ))
@@ -920,6 +985,11 @@ async def unblock(self, ctx, *, user: User = None):
920
985
f'"{ reason } ". { mention } is no longer blocked.' ,
921
986
color = self .bot .main_color ,
922
987
)
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
+ )
923
993
else :
924
994
embed = discord .Embed (
925
995
title = "Success" ,
0 commit comments