def invite(steam_ids, bot_account, lobby_name): client = SteamClient() dota = Dota2Client(client) steam_ids = [int(steamid) for steamid in steam_ids] yielded = set() @client.on('connected') def log_in(): client.login(username=bot_account.login, password=bot_account.password) @client.on('logged_on') def start_dota(): dota.launch() @dota.once('ready') def create_a_lobby(): dota.create_practice_lobby(password=token_hex(16), options={ 'game_name': lobby_name, }) @dota.once('lobby_new') def setup_and_invite_all(lobby): client.emit('info', 'lobby_created', random.choice(steam_ids)) for steam_id in steam_ids: dota.invite_to_lobby(steam_id) @dota.on('lobby_changed') def handle_change(lobby): in_lobby = {member.id for member in lobby.members if member.id in steam_ids} pending = {steamid for steamid in lobby.pending_invites if steamid in steam_ids} leavers = set(steam_ids) - (in_lobby | pending) nonlocal yielded to_yield = in_lobby - yielded for steam_id in to_yield: yielded.add(steam_id) client.emit('info', 'in_lobby', steam_id) if len(in_lobby) == len(steam_ids): dota.leave_practice_lobby() if leavers: leaver_id = list(leavers)[0] dota.destroy_lobby() client.emit('info', 'leaver', leaver_id) @dota.on('lobby_removed') def finish_cycle(lobby): client.emit('info', 'cycle_finished') connect_with_retry(client) while True: args = client.wait_event('info') if args[0] == 'cycle_finished': return else: assert len(args) == 2 yield args
def __init__(self, username, password, wait_dota=True): self.username = username self.password = password self.steam = SteamClient() self.dota = Dota2Client(self.steam) self.steam.on('logged_on', self.on_logged_on) self.dota.on('ready', self.on_dota_ready) self._login(wait_dota)
from gevent import monkey monkey.patch_ssl() from steam import SteamClient from dota2 import Dota2Client from dota2.enums import EDOTAGCMsg from steam import WebAPI import time client = SteamClient() dota = Dota2Client(client) OPEN_SPEED = 0.2 api_key = '' api = '' print("\n\nDue to limitations imposed by valve (f**k you skin gambling) you will need:") print("\t1. An API KEY") print("\t2. Your profile and inventory temporarily set to public") print("API keys can be optained easily from: http://steamcommunity.com/dev/apikey\n\n") while True: api_key = input("Enter your API key: ") try: api = WebAPI(key = api_key) break except: print("invalid key") print("You will now be prompted to log in. You will not see any input when entering password.")