@@ -1745,38 +1745,40 @@ async def log_expiry(self):
1745
1745
1746
1746
logger .info (f"Deleted { expired_logs .deleted_count } expired logs." )
1747
1747
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 ):
1749
1749
"""Sanitises a username for use with text channel names
1750
1750
1751
1751
Placed in main bot class to be extendable to plugins"""
1752
1752
guild = self .modmail_guild
1753
1753
1754
1754
if force_null :
1755
- name = new_name = "null"
1755
+ return "null"
1756
1756
else :
1757
1757
if self .config ["use_random_channel_name" ]:
1758
1758
to_hash = self .token .split ("." )[- 1 ] + str (author .id )
1759
1759
digest = hashlib .md5 (to_hash .encode ("utf8" ), usedforsecurity = False )
1760
- name = new_name = digest .hexdigest ()[- 8 :]
1760
+ name = digest .hexdigest ()[- 8 :]
1761
1761
elif self .config ["use_user_id_channel_name" ]:
1762
- name = new_name = str (author .id )
1762
+ name = str (author .id )
1763
1763
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" )
1765
1765
else :
1766
1766
if self .config ["use_nickname_channel_name" ]:
1767
1767
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 ()
1769
1772
else :
1770
1773
name = author .name .lower ()
1771
1774
1772
- if force_null :
1773
- name = "null"
1774
-
1775
1775
name = "" .join (l for l in name if l not in string .punctuation and l .isprintable ()) or "null"
1776
1776
if author .discriminator != "0" :
1777
1777
name += f"-{ author .discriminator } "
1778
- new_name = name
1779
1778
1779
+ return ensure_unique_channel_name (name , guild , excluse_channel )
1780
+
1781
+ def ensure_unique_channel_name (self , name , guild , exclude_channel ) -> str :
1780
1782
counter = 1
1781
1783
existed = set (c .name for c in guild .text_channels if c != exclude_channel )
1782
1784
while new_name in existed :
0 commit comments