Skip to content

Commit caeb962

Browse files
committed
trying to fix duplicate lines in 'leveling_debug'
1 parent 4a55c54 commit caeb962

2 files changed

Lines changed: 38 additions & 36 deletions

File tree

wall_e/extensions/ban.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self):
3333
self.logger.info("[Ban __init__()] initializing Ban")
3434
self.mod_channel = None
3535
self.bot_management_channel = None
36-
self.guild: discord.Guild = None
36+
self.guild: discord.Guild | None = None
3737
self.purge_messages_task.start()
3838

3939
@commands.Cog.listener(name="on_ready")

wall_e/utilities/log_channel.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,47 @@ async def write_to_bot_log_channel(logger, config, bot, file_path, chan_id, chan
2525
)
2626
f = open(file_path, 'r')
2727
f.seek(0)
28+
channels_with_rate_limit = channel_name in ['leveling_debug', 'role_commands_debug']
2829
incident_report_chanel_name = config.get_config_value('channel_names', 'INCIDENT_REPORT_CHANNEL')
2930
while not bot.is_closed():
3031
f.flush()
3132
line = f.readline()
32-
while line:
33-
if line.strip() != "":
34-
# this was done so that no one gets accidentally pinged from the bot log channel
35-
if channel.name != incident_report_chanel_name:
36-
line = line.replace("@", "[at]")
37-
if line[0] == ' ':
38-
line = f".{line}"
39-
output = line
40-
# done because discord has a character limit of 2000 for each message
41-
# so what basically happens is it first tries to send the full message, then if it cant, it
42-
# breaks it down into 2000 sizes messages and send them individually
43-
try:
44-
await channel.send(output)
45-
except (aiohttp.ClientError, discord.errors.HTTPException):
46-
finished = False
47-
first_index, last_index = 0, 2000
48-
while not finished:
49-
await channel.send(output[first_index:last_index])
50-
first_index = last_index
51-
last_index += 2000
52-
if len(output[first_index:last_index]) == 0:
53-
finished = True
54-
except RuntimeError:
55-
logger.debug(
56-
"[log_channel.py write_to_bot_log_channel()] encountered RuntimeError, "
57-
" will assume that the user is attempting to exit"
58-
)
59-
break
60-
except Exception as exc:
61-
exc_str = f'{type(exc).__name__}: {exc}'
62-
raise Exception(
63-
f'[log_channel.py write_to_bot_log_channel()] write to channel failed\n{exc_str}'
64-
)
65-
line = f.readline()
66-
if channel_name in ['leveling_debug', 'role_commands_debug']:
33+
if line and line.strip() != "":
34+
# this was done so that no one gets accidentally pinged from the bot log channel
35+
if channel.name != incident_report_chanel_name:
36+
line = line.replace("@", "[at]")
37+
if line[0] == ' ':
38+
line = f".{line}"
39+
output = line
40+
# done because discord has a character limit of 2000 for each message
41+
# so what basically happens is it first tries to send the full message, then if it cant, it
42+
# breaks it down into 2000 sizes messages and send them individually
43+
message_sent = False
44+
try:
45+
await channel.send(output)
46+
message_sent = True
47+
except (aiohttp.ClientError, discord.errors.HTTPException):
48+
finished = False
49+
first_index, last_index = 0, 2000
50+
while not finished:
51+
await channel.send(output[first_index:last_index])
52+
message_sent = True
53+
first_index = last_index
54+
last_index += 2000
55+
if len(output[first_index:last_index]) == 0:
56+
finished = True
57+
except RuntimeError:
58+
logger.debug(
59+
"[log_channel.py write_to_bot_log_channel()] encountered RuntimeError, "
60+
" will assume that the user is attempting to exit"
61+
)
62+
break
63+
except Exception as exc:
64+
exc_str = f'{type(exc).__name__}: {exc}'
65+
raise Exception(
66+
f'[log_channel.py write_to_bot_log_channel()] write to channel failed\n{exc_str}'
67+
)
68+
if message_sent and channels_with_rate_limit:
6769
# adding a sleep cause the amount of debug logs that I print due to the wall_e_models module can
6870
# trigger a Rate Limit exception if done too fast
6971
await asyncio.sleep(1)

0 commit comments

Comments
 (0)