JonnyPtn / zomboi

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

Python 3.10 requirement #6

Closed Reagy closed 2 years ago

Reagy commented 2 years ago

Currently I can't run 3.10 on my server as I'm still sticking with Debian 9 (got certain reasons for not moving to 10/11 currently) which unfortunately doesn't have OpenSSL 1.1.1 in its repo, which is required to build 3.10's SSL module (I'm aware can manually build it from source but I've got a lot of stuff on this server that relies upon the current OpenSSL install, rather not brick it accidentally for a single python script).

Is there any chance you'll support 3.9? Currently its the match-case which is stopping this from running as that was something introduced with 3.10. I'm not a python person so I'm not really sure how to rewrite those to make them work with the older version. I could look into running it under a docker image but then it means I can't manage it under pufferpanel without having to redo all its environment stuff and I'm an absolute novice when it comes to docker.

Also some feedback for the config file, it'd be a good idea to add in the ability to set the rcon port as not everyone uses the default, especially in my case where there is over 20 servers running off the same box.

Edited:

Had a look into it and managed to convert it over, so far works fine on 3.9.9. Requires editing perks.py if anyone else is looking at this. Swap out the "match type:" block for this.

    def switch(type):   
        # check if the argument matches the cases
        if type == "Died":
            user.died.append(timestamp)
            if timestamp > self.lastUpdateTimestamp:
                self.bot.log.info(f"{user.name} died")
                return f":zombie: {user.name} died after surviving {user.hoursAlive} hours :dizzy_face:"

        elif type == "Login":
            if timestamp > self.lastUpdateTimestamp:
                user.online = True
                self.bot.log.info(f"{user.name} login")
                return f":zombie: {user.name} has arrived, survived for {user.hoursAlive} hours so far..."

        elif type == "Level Changed":
            for perk in user.perks:
                if perk in message:
                    match = re.search(r'\[(\d+)\]', message)
                    level = match.group(1)
                    user.perks[perk] = level
                    if timestamp > self.lastUpdateTimestamp:
                        self.bot.log.info(
                            f"{user.name} {perk} changed to {level}")
                        return f":chart_with_upwards_trend: {user.name} reached {perk} level {level}"

        else:
            # Must be a list of perks following a login/player creation
            for perk in user.perks:
                match = re.search(fr'{perk}=(\d+)', type)
                if match is not None:
                    user.perks[perk] = match.group(1)
laurigates commented 2 years ago

Alternatively you could use something like pyenv to deal with newer versions of python, if that seems like a fit for your environment.

JonnyPtn commented 2 years ago

Yeah, the 3.10 requirement was purely because that's what I happened to be using when I wrote this. I think you're right it's only the pattern matching which is actually requiring this version, so I'll look to remove that and support older versions

Thanks!

JonnyPtn commented 2 years ago

This should be fixed in 0ece466960ef66b813908bcc719a1270e266b7c7 to support 3.8+