Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from csgo.client import CSGOClient
- from steam.client import SteamClient
- import discord_channels as credentials
- from write import write
- def to_steam_id(account_id):
- return int(account_id) + 76561197960265728
- def to_account_id(steam_id):
- return int(steam_id) - 76561197960265728
- def parse_match(response, match_number: int = 0):
- matches = str(response).split('}\n, ')
- if len(matches) - 1 < match_number:
- print(f'Found only {len(matches)}')
- match_number = 0
- infos = matches[match_number].split('\n')
- result = {}
- item_list = [info.split(': ') for info in infos if ': ' in info]
- for _key, _value in item_list:
- key = _key.replace(' ', '').replace('[', '').replace(']', '')
- value = _value.replace('"', '')
- if key not in result:
- result[key] = [value]
- else:
- result[key].append(value)
- # remove single item lists, convert all possible items to integers
- for key, _lists in result.items():
- try:
- lists = list(map(int, _lists))
- except ValueError:
- lists = _lists
- if len(lists) == 1:
- result[key] = lists[0]
- else:
- result[key] = lists
- return result
- client = SteamClient()
- cs = CSGOClient(client)
- def get_current_player(steam_id):
- cs.request_live_game_for_user(to_account_id(steam_id))
- r, = cs.wait_event('live_game_for_user')
- if r is not None:
- data = parse_match(r)
- if 'account_ids' in data:
- return list(map(to_steam_id, data['account_ids']))
- return None
- @client.on('logged_on')
- def start_csgo():
- write('Logged in to Steam')
- cs.launch()
- write('CS:GO game coordinator starting')
- @cs.on('ready')
- def gc_ready():
- write('CS:GO game coordinator running')
- # ready to call get_current_player() here
- # a discord bot should now listen for a eg. !steamid and call get_current_player()
- client.cli_login(username=credentials.username, password=credentials.password)
- client.run_forever()
Add Comment
Please, Sign In to add comment