hopefully fix regex implementation

This commit is contained in:
Nayan
2025-08-26 12:45:43 -04:00
parent 7e83bd5ede
commit 7aa40a5c46

26
bot.py
View File

@@ -164,32 +164,18 @@ async def _read_from_pipe(servername, channel_id, bot_instance):
continue continue
# print(f"Raw server output: {line}") # Debugging raw output # print(f"Raw server output: {line}") # Debugging raw output
global regex_list
global fprint_list
regex = None for i in range(len(regex_list)):
capture = None match = regex_list[i].match(line)
if (FILE_REGEX):
try:
with open('config.json', 'r') as f:
config = json.load(f)
tempregex = config['config']['regex'][0]['match']
regex = re.compile(tempregex)
capture = config['config']['regex'][0]['capture']
except Exception as e:
print(f"Error in regex compilation for {servername}: {e}")
regex = MINECRAFT_CHAT_REGEX
capture = "**[{groups[0]}]**: {groups[2]}"
else:
regex = MINECRAFT_CHAT_REGEX
capture = "**[{groups[0]}]**: {groups[2]}"
match = regex.match(line)
if match: if match:
groups = match.groups() groups = match.groups()
discord_message = capture.format(groups=groups) discord_message = fprint_list[i].format(groups=groups)
# Limit message length for Discord if necessary # Limit message length for Discord if necessary
if len(discord_message) > 2000: if len(discord_message) > 2000:
discord_message = discord_message[:1997] + "..." discord_message = discord_message[:1997] + "..."
print(discord_message) print(discord_message)
await bot.loop.create_task(channel.send("Message sending..."))
await bot.loop.create_task(channel.send(discord_message)) await bot.loop.create_task(channel.send(discord_message))
# else: # else:
# # Optionally, you can log other server output to a debug channel or console # # Optionally, you can log other server output to a debug channel or console