fix spam + add player disconnect message
All checks were successful
Build and Push Docker Image / build (push) Successful in 12s
All checks were successful
Build and Push Docker Image / build (push) Successful in 12s
This commit is contained in:
parent
60ad27126b
commit
5e216862a6
@ -34,6 +34,14 @@ class ConsoleCog(commands.Cog):
|
|||||||
raise FileNotFoundError("Server console file doesn't exist, task cancelled.")
|
raise FileNotFoundError("Server console file doesn't exist, task cancelled.")
|
||||||
|
|
||||||
async with aiofiles.open(CONSOLE_FILE_PATH, "r", encoding="utf-8") as file:
|
async with aiofiles.open(CONSOLE_FILE_PATH, "r", encoding="utf-8") as file:
|
||||||
|
|
||||||
|
# If we are at 0, restarting the bot would cause rapid fire of all log lines,
|
||||||
|
# instead lets grab the latest line, to prevent spam.
|
||||||
|
if self._last_line_number == 0:
|
||||||
|
await file.seek(0, 2)
|
||||||
|
self._last_line_number = await file.tell()
|
||||||
|
return
|
||||||
|
|
||||||
await file.seek(self._last_line_number)
|
await file.seek(self._last_line_number)
|
||||||
lines = await file.readlines()
|
lines = await file.readlines()
|
||||||
if not lines:
|
if not lines:
|
||||||
@ -59,7 +67,7 @@ class ConsoleCog(commands.Cog):
|
|||||||
log.debug("mod update instruction: %s", line)
|
log.debug("mod update instruction: %s", line)
|
||||||
|
|
||||||
async def handle_player_joined(self, line: str):
|
async def handle_player_joined(self, line: str):
|
||||||
# example
|
# example for connect:
|
||||||
# ConnectionManager: [fully-connected] "" connection: guid=1733487070761473 ip=192.168.1.23 steam-id=76561198202697217 access=admin username="corbz" connection-type="UDPRakNet"
|
# ConnectionManager: [fully-connected] "" connection: guid=1733487070761473 ip=192.168.1.23 steam-id=76561198202697217 access=admin username="corbz" connection-type="UDPRakNet"
|
||||||
re_pattern = r"guid=(\d+) ip=([\d\.]+) steam-id=(\d+) access=(\w+) username=\"([^\"]+)\" connection-type=\"([^\"]+)\""
|
re_pattern = r"guid=(\d+) ip=([\d\.]+) steam-id=(\d+) access=(\w+) username=\"([^\"]+)\" connection-type=\"([^\"]+)\""
|
||||||
re_match = re.search(re_pattern, line)
|
re_match = re.search(re_pattern, line)
|
||||||
@ -82,9 +90,28 @@ class ConsoleCog(commands.Cog):
|
|||||||
await channel.send(content=f"Player Joined: **{data['username']}**")
|
await channel.send(content=f"Player Joined: **{data['username']}**")
|
||||||
|
|
||||||
async def handle_player_left(self, line: str):
|
async def handle_player_left(self, line: str):
|
||||||
# example
|
# Example for disconnect:
|
||||||
# ConnectionManager: [disconnect] "receive-disconnect" connection: guid=1733487070761473 ip=192.168.1.23 steam-id=76561198202697217 access=admin username="corbz" connection-type="Disconnected"
|
# ConnectionManager: [disconnect] "receive-disconnect" connection: guid=1733487070761473 ip=192.168.1.23 steam-id=76561198202697217 access=admin username="corbz" connection-type="Disconnected"
|
||||||
pass
|
|
||||||
|
re_pattern = r"guid=(\d+) ip=([\d\.]+) steam-id=(\d+) access=(\w+) username=\"([^\"]+)\" connection-type=\"([^\"]+)\""
|
||||||
|
re_match = re.search(re_pattern, line)
|
||||||
|
if not re_match:
|
||||||
|
log.warning("failed to parse player data: %s", line)
|
||||||
|
return
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"guid": re_match.group(1),
|
||||||
|
"ip": re_match.group(2),
|
||||||
|
"steam_id": re_match.group(3),
|
||||||
|
"access": re_match.group(4),
|
||||||
|
"username": re_match.group(5),
|
||||||
|
"connection_type": re_match.group(6),
|
||||||
|
}
|
||||||
|
|
||||||
|
channel = self.bot.get_channel(self.bot.in_game_channel_id)
|
||||||
|
channel = await self.bot.fetch_channel(self.bot.in_game_channel_id) if not channel else channel
|
||||||
|
|
||||||
|
await channel.send(content=f"Player Left: **{data['username']}**")
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot: commands.Bot):
|
async def setup(bot: commands.Bot):
|
||||||
|
Reference in New Issue
Block a user