@@ -1745,38 +1745,40 @@ 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"""
17521752 guild = self .modmail_guild
17531753
17541754 if force_null :
1755- name = new_name = "null"
1755+ return "null"
17561756 else :
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 = new_name = digest .hexdigest ()[- 8 :]
1760+ name = digest .hexdigest ()[- 8 :]
17611761 elif self .config ["use_user_id_channel_name" ]:
1762- name = new_name = str (author .id )
1762+ name = str (author .id )
17631763 elif self .config ["use_timestamp_channel_name" ]:
1764- name = new_name = author .created_at .isoformat (sep = "-" , timespec = "minutes" )
1764+ name = author .created_at .isoformat (sep = "-" , timespec = "minutes" )
17651765 else :
17661766 if self .config ["use_nickname_channel_name" ]:
17671767 author_member = self .guild .get_member (author .id )
1768- name = author_member .display_name .lower ()
1768+ if author_member is None :
1769+ name = author .display_name .lower ()
1770+ else :
1771+ name = author_member .display_name .lower ()
17691772 else :
17701773 name = author .name .lower ()
17711774
1772- if force_null :
1773- name = "null"
1774-
17751775 name = "" .join (l for l in name if l not in string .punctuation and l .isprintable ()) or "null"
17761776 if author .discriminator != "0" :
17771777 name += f"-{ author .discriminator } "
1778- new_name = name
17791778
1779+ return ensure_unique_channel_name (name , guild , excluse_channel )
1780+
1781+ def ensure_unique_channel_name (self , name , guild , exclude_channel ) -> str :
17801782 counter = 1
17811783 existed = set (c .name for c in guild .text_channels if c != exclude_channel )
17821784 while new_name in existed :
0 commit comments