def send_chat_message(steam_id, bot_account, message): client = SteamClient() steam_id = int(steam_id) @client.on('connected') def log_in(): client.login(username=bot_account.login, password=bot_account.password) @client.on('logged_on') def send_message(): recipient = client.get_user(steam_id, fetch_persona_state=False) recipient.send_message(message) client.emit('cycle_finished') connect_with_retry(client) client.wait_event('cycle_finished')
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 wait_for_friend_request_answer(steam_id, bot_account, block=True): client = SteamClient() steam_id = int(steam_id) @client.on('connected') def log_in(): client.login(username=bot_account.login, password=bot_account.password) @client.friends.on('ready') @client.friends.on('friend_new') def check_friends(*args): nonlocal client friends = { int(friend.steam_id) for friend in client.friends if friend.relationship == EFriendRelationship.Friend } if steam_id in friends: client.emit('cycle_finished', True) elif not block: client.emit('cycle_finished', False) connect_with_retry(client) in_friends = client.wait_event('cycle_finished')[0] return in_friends
from __future__ import print_function from steam import SteamClient from steam.enums import EResult client = SteamClient() print("One-off login recipe") print("-"*20) result = client.cli_login() if result != EResult.OK: print("Failed to login: %s" % repr(result)) raise SystemExit print("-"*20) client.wait_event('logged_on') print("Logged on as:", client.user.name) print("Community profile:", client.steam_id.community_url) print("Last logon:", client.user.last_logon) print("Last logoff:", client.user.last_logoff) client.logout()
client = SteamClient() @client.on('error') def error(result): print("Logon result:", repr(result)) @client.on('auth_code_required') def auth_code_prompt(is_2fa, mismatch): if is_2fa: code = raw_input("Enter 2FA Code: ") client.login(two_factor_code=code, **LOGON_DETAILS) else: code = raw_input("Enter Email Code: ") client.login(auth_code=code, **LOGON_DETAILS) try: client.login(**LOGON_DETAILS) client.wait_event('logged_on') except: raise SystemExit print("-"*20) print("Logged on as:", client.user.name) print("Community profile:", client.steam_id.community_url) print("Last logon:", client.user.last_logon) print("Last logoff:", client.user.last_logoff) client.logout()