-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathServerCommands.py
30 lines (24 loc) · 1.25 KB
/
ServerCommands.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
import requests
import time
import logging
class ServerCommands:
def __init__(self, config):
self.config = config
logging.basicConfig(level=logging.DEBUG, filename='mapvote.log', filemode='w', format='%(asctime)s - %(levelname)s - %(message)s')
def send_command(self, command):
header = {'Authorization': self.config['MapVoter']['bm_token']}
data = {"data":{"type":"rconCommand","attributes":{"command":"raw","options":{"raw":command}}}}
try:
requests.post(f"https://api.battlemetrics.com/servers/{self.config['MapVoter']['bm_server_id']}/command", headers=header, json=data)
except:
time.sleep(1)
try:
requests.post(f"https://api.battlemetrics.com/servers/{self.config['MapVoter']['bm_server_id']}/command", headers=header, json=data)
except:
logging.error(f'Error sending server command: {command}', exc_info=True)
def broadcast(self, message):
logging.info(f'[COMMAND] Broadcasting message: {message}')
self.send_command(f'AdminBroadcast "{message}"')
def set_map(self, map_name):
logging.info(f'[COMMAND] Setting next map to: {map_name}')
self.send_command(f'AdminSetNextMap "{map_name}"')