@@ -1745,7 +1745,7 @@ async def log_expiry(self):
17451745
17461746 logger .info (f"Deleted { expired_logs .deleted_count } expired logs." )
17471747
1748- def format_channel_name (self , author , exclude_channel = None , force_null = False ):
1748+ def format_channel_name (self , author , exclude_channel = None , force_null = False ):
17491749 """Sanitises a username for use with text channel names
17501750
17511751 Placed in main bot class to be extendable to plugins"""
@@ -1757,7 +1757,7 @@ def format_channel_name(self, author, exclude_channel=None, force_null=False):
17571757 if self .config ["use_random_channel_name" ]:
17581758 to_hash = self .token .split ("." )[- 1 ] + str (author .id )
17591759 digest = hashlib .md5 (to_hash .encode ("utf8" ), usedforsecurity = False )
1760- name = digest .hexdigest ()[- 8 :]
1760+ name = digest .hexdigest ()[- 8 :]
17611761 elif self .config ["use_user_id_channel_name" ]:
17621762 name = str (author .id )
17631763 elif self .config ["use_timestamp_channel_name" ]:
@@ -1772,12 +1772,16 @@ def format_channel_name(self, author, exclude_channel=None, force_null=False):
17721772 else :
17731773 name = author .name .lower ()
17741774
1775- sanitized_name = "" .join (l for l in name if l not in string .punctuation and l .isprintable ()) or "null"
1776- if author .discriminator != "0" :
1777- sanitized_name += f"-{ author .discriminator } "
1775+ sanitized_name = self .sanitize_name (name )
1776+
1777+ if author .discriminator != "0" :
1778+ sanitized_name += f"-{ author .discriminator } "
17781779
17791780 return ensure_unique_channel_name (sanitized_name , guild , excluse_channel )
17801781
1782+ def sanitize_name (self , name : str ) -> str :
1783+ return "" .join (l for l in name if l not in string .punctuation and l .isprintable ()) or "null"
1784+
17811785 def ensure_unique_channel_name (self , name , guild , exclude_channel ) -> str :
17821786 counter = 1
17831787 existed = set (c .name for c in guild .text_channels if c != exclude_channel )
0 commit comments