JonnyPtn / zomboi

A discord bot for project zomboid multiplayer servers
49 stars 32 forks source link

Make bot aware of server status #37

Closed 6-- closed 4 months ago

6-- commented 2 years ago

Hello,

Is it possible to send the stats of the server (restart/start/stop) to discord?

And if possible, it will notify on discord that there is a mod update and restart the server after a certain time (5 minutes, 10 minutes..etc)? something similar to https://github.com/Lu5ck/pz-server-tools-rcon

There are mods (https://steamcommunity.com/sharedfiles/filedetails/?id=2779169728) that can check for updates every given time and it will notify us in-game and also can restart the server, but sometimes it doesnt save very well and we have a tiny rollback.

Thank you for making this great tool!

CodedGold commented 2 years ago

This would also be helpful for our server as well!

Grim-reap3r commented 2 years ago

https://prnt.sc/_OZBx8jRZ1rF

https://prnt.sc/Z6uxskd80dwM

I have few bots running on my dedi.

6-- commented 2 years ago

did you add these features to zomboi bot?

JonnyPtn commented 2 years ago

Might be a bit tricky to implement as we rely on the log messages, which means if the server doesn't shutdown cleanly we may still think it's running.

Grim-reap3r commented 2 years ago

This would also be helpful for our server as well!

did you add these features to zomboi bot?

I have 3 bots running. 1 - checking every 15 mins steam workshop and inform on discord if any update. 2 - control panel start/stop/restart each server 3 - server status bot on channel and on user list time update restart .

petegilb commented 2 years ago

Might be a bit tricky to implement as we rely on the log messages, which means if the server doesn't shutdown cleanly we may still think it's running.

Agreed. In addition to checking the logs we could also ping the server to check for the status, but we would have to see if that's a reliable solution.

JonnyPtn commented 2 years ago

Yeah monitoring the process is feasible, but there's so many different ways people run their servers I don't see any way to make it reliable or consistent, and I think it's probably outside the scope of this bot a bit (unless we were to add a bunch of features related to actually managing the PZ server)

thefyLoX commented 2 years ago

I have a few scripts that handle reboots and notify players in advance through server messages. I wanted to capture these in a simple way and I decided to modify chat.py a bit by adding server alerts to the pattern so we get those in Discord as well (also modified the channel check because the server messages have their own, different structure compared to chat channels).

I'm sure there's a better way to do it, but I'm posting it in case someone finds a use for it:

[EDIT] Cleaned it up a bit and reinforced the RegEx checks to avoid false positives

This replaces the contents of the handleLog function in line 45:

  async def handleLog(self, timestamp: datetime, message: str):
        """Parse the given line from the logfile and mirror chat message in
        discord if necessary"""
        # Filter general and server channels
        match = re.search(r"^(?:\[info\] Message ChatMessage\{chat=General, author=| Server alert message: )\'", message)
        if  match and self.bot.channel is not None:
            # Extract the username and message body
            pattern = r"(?:] Message.*chat=General, author=\'|^ )(.*)(?:\', text=| alert message: )\'(.*)\'"
            match_data = re.search(pattern, message)
            # Use a webhook to make it look like we're the discord member
            # God bless stack overflow
            if self.bot.channel:
                for webhook in await self.bot.channel.webhooks():
                    if webhook.user == self.bot.user:
                        self.webhook = webhook
            if self.webhook is None:
                self.webhook = await self.bot.channel.create_webhook(name="zomboi")
            name = match_data.group(1)
            avatar_url = None
            for member in self.bot.get_all_members():
                if match_data.group(1) in member.name:
                    avatar_url = member.avatar_url
            await self.webhook.send(
                match_data.group(2), username=name, avatar_url=avatar_url
            )
Topdog1221 commented 1 year ago

Is there any update to this or alternative, I feel like I hit a dead end everytime. Zomboi works well, but has no option for restart, start, nor stop. https://github.com/rfalias/project_zomboid_bot is broken, https://github.com/egebilecen/PZServerDiscordBot is for windows, Half of the other discord bots dont have these options neither, some want me to reinstall my server instead of just specifying the locations of the files. And lastly half are just bugged. Grim-reap3r looks like he has a solution and right now thats the best I got, will this ever be a feature?

JonnyPtn commented 4 months ago

Latest version has server management feature which I think should cover most of this