-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for SCP: Secret Laboratory protocol
- Added new protocol implementation for SCP: Secret Laboratory in protocols/scpsl.py. - Updated games.csv to include SCP: Secret Laboratory entry. - Modified main.py to handle additional query parameters for SCP: Secret Laboratory servers. - Added the line 'from .scpsl import SCP_SL' to protocols/__init__.py. Changes: - discordgsm/games.csv: 1 addition - discordgsm/main.py: 1 addition - discordgsm/protocols/__init__.py: 1 addition - discordgsm/protocols/scpsl.py: 42 additions
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import time | ||
from typing import TYPE_CHECKING | ||
|
||
import aiohttp | ||
|
||
from discordgsm.protocols.protocol import Protocol | ||
|
||
if TYPE_CHECKING: | ||
from discordgsm.gamedig import GamedigResult | ||
|
||
class SCP_SL(Protocol): | ||
name = 'scp_sl' | ||
|
||
async def query(self): | ||
token, accountid, servername = str(self.kv['_token']), str(self.kv['_accountid']), str(self.kv['_servername']) | ||
|
||
url = f'https://api.scpslgame.com/serverinfo.php?id={accountid}&key={token}&lo=true&players=true&list=true&version=true&flags=true&online=true' | ||
|
||
start = time.time() | ||
|
||
async with aiohttp.ClientSession() as session: | ||
async with session.get(url) as response: | ||
data = await response.json() | ||
|
||
server_info = data.get("Servers", [])[0] if data.get("Servers") else {} | ||
ping = int((time.time() - time.mktime(time.strptime(server_info.get('LastOnline', '1970-01-01'), "%Y-%m-%d"))) * 1000) | ||
|
||
result: GamedigResult = { | ||
'name': f'{servername} - SCP SL Server {server_info.get("ID", "Offline")}', | ||
'map': '', | ||
'password': False, | ||
'numplayers': int(server_info.get("Players", "0/0").split("/")[0]), | ||
'numbots': 0, | ||
'maxplayers': int(server_info.get("Players", "0/0").split("/")[1]), | ||
'players': [{'name': player, 'raw': player} for player in server_info.get('PlayersList', [])], | ||
'bots': None, | ||
'connect': None, | ||
'ping': ping, | ||
'raw': data | ||
} | ||
|
||
return result |