@@ -291,14 +291,41 @@ def log_category(channel): return (
291291
292292 @classmethod
293293 async def fix_text_channel_positioning (cls , logger , guild ):
294- position_edited = True
295- while position_edited :
294+ duplicate_channels = {} # used to find and report text log channels that share the same name
295+
296+ logs_category = discord .utils .get (guild .channels , name = wall_e_category_name )
297+ channels_under_category = [
298+ channel for channel in guild .channels
299+ if type (channel ) == discord .channel .TextChannel and channel .category == logs_category
300+ ]
301+
302+ for channel_under_category in channels_under_category :
303+ if channel_under_category .name not in duplicate_channels :
304+ duplicate_channels [channel_under_category .name ] = 1
305+ else :
306+ duplicate_channels [channel_under_category .name ] += 1
307+
308+ # ensure that there are no channels that should not exist
309+ if channel_under_category .name not in BotChannelManager .log_positioning :
310+ await channel_under_category .delete ()
311+ duplicate_channels = [
312+ channel_name
313+ for channel_name , number_of_occurrences in duplicate_channels .items ()
314+ if number_of_occurrences > 1
315+ ]
316+ if len (duplicate_channels ) > 0 :
317+ duplicate_channels = ", " .join (duplicate_channels )
318+ logger .error (
319+ f"[bot_channel_manager.py fix_text_channel_positioning()] following duplicate text log channels"
320+ f" detected: { duplicate_channels } "
321+ )
322+ number_of_clean_passes = 0
323+ while number_of_clean_passes < 3 :
296324 # encapsulating the whole thing in a while loop cause sometimes a channel might erroneously get pushed to
297325 # the bottom while the repositioning is happening, which necessitates another sweep-through
298326 # as such, I am going to make the code keep going over the channels until all the positions are verified
299327 # as what they should be
300328 position_edited = False
301- logs_category = discord .utils .get (guild .channels , name = wall_e_category_name )
302329 for text_channel_name , index in BotChannelManager .log_positioning .items ():
303330 text_channel = discord .utils .get (guild .channels , name = text_channel_name )
304331 while text_channel is None :
@@ -323,10 +350,13 @@ async def fix_text_channel_positioning(cls, logger, guild):
323350 position_edited = True
324351 await text_channel .edit (position = index )
325352 if position_edited :
353+ number_of_clean_passes = 0
326354 logger .warn (
327355 "[bot_channel_manager.py fix_text_channel_positioning()] doing another sweep of the log text "
328356 "channels positioning"
329357 )
358+ else :
359+ number_of_clean_passes += 1
330360 logger .debug (
331361 "[bot_channel_manager.py fix_text_channel_positioning()] done with sweep of the log text channels "
332362 "positioning"
0 commit comments