mirror of
https://github.com/opus-tango/minecraft-server-discord-bot.git
synced 2026-03-20 03:55:20 +00:00
hopefully fix regex implementation
This commit is contained in:
26
bot.py
26
bot.py
@@ -164,32 +164,18 @@ async def _read_from_pipe(servername, channel_id, bot_instance):
|
||||
continue
|
||||
|
||||
# print(f"Raw server output: {line}") # Debugging raw output
|
||||
|
||||
|
||||
regex = None
|
||||
capture = None
|
||||
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)
|
||||
global regex_list
|
||||
global fprint_list
|
||||
for i in range(len(regex_list)):
|
||||
match = regex_list[i].match(line)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
discord_message = capture.format(groups=groups)
|
||||
discord_message = fprint_list[i].format(groups=groups)
|
||||
# Limit message length for Discord if necessary
|
||||
if len(discord_message) > 2000:
|
||||
discord_message = discord_message[:1997] + "..."
|
||||
print(discord_message)
|
||||
await bot.loop.create_task(channel.send("Message sending..."))
|
||||
await bot.loop.create_task(channel.send(discord_message))
|
||||
# else:
|
||||
# # Optionally, you can log other server output to a debug channel or console
|
||||
|
||||
Reference in New Issue
Block a user