JonnyPtn / zomboi

A discord bot for project zomboid multiplayer servers
50 stars 33 forks source link

Getting an error when loading. #29

Closed Hypertoken closed 2 years ago

Hypertoken commented 2 years ago

Bot only handles chat and disconnects. not perks, joins, or deaths. Maybe something with the regex on line 82 of perks.py

hours = re.search(r"Hours Survived: (\d+)", message).group(1)

2022-05-21 01:26:41,323:INFO:zomboi: Loading Perk history...
Ignoring exception in on_ready
Traceback (most recent call last):
  File "/home/zomboi/.local/lib/python3.10/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/home/zomboi/zomboi.py", line 69, in on_ready
    zomboi.add_cog(PerkHandler(zomboi, logPath))
  File "/home/zomboi/perks.py", line 16, in __init__
    self.loadHistory()
  File "/home/zomboi/perks.py", line 56, in loadHistory
    self.handleLog(*self.splitLine(line))
  File "/home/zomboi/perks.py", line 82, in handleLog
    hours = re.search(r"Hours Survived: (\d+)", message).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
Hypertoken commented 2 years ago

After further review; Looks like the regex is fine, it was the trimming of the string that wasn't going as planned. Since the timestamp for the string is handled already.

The issue is on line 62 of perks.py; message = message[message.find("[", 2) + 1 :]

Which should remove everything up to the 2nd square open bracket. Problem is that was intended for the timestamp which is already removed. So it was removing the User. This was a domino effect, causing the "Hours Played" to return "." a period.

So changing line 62 of perks.py to; message = message[message.find("[", 1) + 1 :]

Now it will properly parse the User, Type, and Hours

JonnyPtn commented 2 years ago

Is this on the 41.71? I haven't tested with that build yet so maybe the log format changed

I'll keep this open if that's the case then I'll remember to fix?