-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservers.py
31 lines (24 loc) · 1.09 KB
/
servers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
from discord.utils import escape_markdown
class SteamServer():
def __init__(self, data):
self.name = data.get('name', None)
self.address = data.get('addr', None)
self.players = data.get('players', None)
self.maxPlayers = data.get('max_players', None)
self.map = data.get('map', None)
def __str__(self):
return ('> %s <steam://connect/%s>\n> %s (%s / %s)' % (escape_markdown(self.name), self.address, self.map, self.players, self.maxPlayers))
class SteamServerBrowser():
def __init__(self, apiKey, appID):
self.apiKey = apiKey
self.appID = appID
def get(self, limit=30):
result = requests.get('https://api.steampowered.com/IGameServersService/GetServerList/v1/?key=%s&limit=%s&filter=appid\%s' % (self.apiKey, limit, self.appID))
if result.status_code != 200:
return []
try:
result = result.json()
return sorted([SteamServer(server) for server in result['response']['servers']], key=lambda x: x.players, reverse=True)
except:
return []