Skip to content

Commit

Permalink
Remove old population check
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhsm committed Jul 31, 2023
1 parent 013516f commit e58799b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
10 changes: 3 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"python.autoComplete.extraPaths": [
"./dictator"
],
"python.analysis.extraPaths": [
"./dictator"
]
}
"python.autoComplete.extraPaths": ["./dictator"],
"python.analysis.extraPaths": ["./dictator"],
}
41 changes: 9 additions & 32 deletions dictator/cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ async def on_ready(self) -> None:
async def stats_loop(self) -> None:
await self.update_stats()

async def update_stats(self) -> None:
server_info, families, family_count = await self.get_server_stats()
embed = discord.Embed(title="Stats", colour=0xffbb35)
embed.add_field(name="Online", value=server_info[0])
embed.add_field(name="Version", value=server_info[1])
embed.add_field(name="Individual families", value=family_count)
embed.add_field(name="Families", value=families, inline=False)
await self.stats_message.edit(embed=embed)

async def prepare_stats(self) -> bool:
channel = self.dictator.get_channel(STATS_CHANNEL_ID)

Expand All @@ -48,29 +39,15 @@ async def prepare_stats(self) -> bool:
embed = discord.Embed(title="Loading stats...", colour=0xffbb35)
self.stats_message = await channel.send(embed=embed)
return True

async def get_population(self) -> str:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
sock.settimeout(3.0)
sock.connect(("play.twohoursonelife.com", 8005))
fd = sock.makefile()

except ConnectionRefusedError:
app_info = await self.dictator.application_info()
owner = await self.dictator.fetch_user(app_info.team.owner_id)
await owner.send("Is the game server offline? it did not respond to a stats request.")
print("Server failed stats request, pinged my owner.")
return "Unknown"

else:
if "SN" in fd.readline(128):
count = fd.readline(128).split("/")
return f"{count[0]}"

finally:
sock.close()

async def update_stats(self) -> None:
server_info, families, family_count = await self.get_server_stats()
embed = discord.Embed(title="Stats", colour=0xffbb35)
embed.add_field(name="Online", value=server_info[0])
embed.add_field(name="Version", value=server_info[1])
embed.add_field(name="Individual families", value=family_count)
embed.add_field(name="Families", value=families, inline=False)
await self.stats_message.edit(embed=embed)

async def get_server_stats(self) -> str:
result = await self.player_list_request()
Expand Down

0 comments on commit e58799b

Please sign in to comment.