Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import html
- import sys
- import os
- import random
- class SteamBot:
- """A simple Steam bot class"""
- def __init__(self, api_key):
- # creates a session
- self.session = requests.session()
- # sets sessions headers
- self.headers = {'User-Agent': 'Mozilla/5.0'}
- self.session.headers.update(self.headers)
- # sets 2captcha api key
- self.api_key = api_key
- def signup(self, username, password, email):
- while True:
- print('Attempting to create account: {}'.format(username))
- # gets valid captcha
- captcha = self.session.get('https://store.steampowered.com/join/refreshcaptcha/').json()
- print('Got captcha.')
- # gets captcha image
- image = self.session.get('https://store.steampowered.com/public/captcha.php', params=captcha).content
- print('Got captcha image.')
- # solves captcha
- print('Sending captcha to api...')
- response = self.__solve_captcha(image)
- print('Solved captcha.')
- # gets captcha gid
- captcha_gid = captcha['gid']
- # creates sign up headers
- headers = {'Referer': 'https://store.steampowered.com/join/?', 'X-Requested-With': 'XMLHttpRequest', 'X-Prototype-Version': '1.7'}
- # creates sign up payload
- payload = {'accountname': username, 'password': password, 'email': email, 'captchagid': captcha_gid, 'captcha_text': response, 'i_agree': '1', 'count': '10', 'it': '0'}
- # signs up on steam
- r = self.session.post('https://store.steampowered.com/join/createaccount/', data=payload, headers=headers)
- # validates account creation
- if r.json()['bSuccess']:
- # notifies user account has been created
- print('Account {} created.'.format(username))
- # gets steam id
- self.sId = self.session.cookies['steamLogin'].split('%7C%7C')[0]
- print('Got steam id: {}'.format(self.sId))
- # sets cookies for steam community
- self.session.cookies.set('steamCountry', self.session.cookies['steamCountry'], domain='steamcommunity.com', path='/')
- self.session.cookies.set('steamLogin', self.session.cookies['steamLogin'], domain='steamcommunity.com', path='/')
- self.session.cookies.set('steamLoginSecure', self.session.cookies['steamLoginSecure'], domain='steamcommunity.com', path='/')
- print('Successfully migrated cookies.')
- break
- else:
- # notify user of error
- print('There was a problem creating the account {}.'.format(username))
- # finds out error
- try:
- print(r.json()['details'])
- print('Retrying...')
- continue
- except KeyError:
- sys.exit('Account already exists.')
- break
- def upload_avatar(self, filename):
- # gets cookies
- r = self.session.get('http://steamcommunity.com/profiles/{}/edit'.format(self.sId), params={'welcomed': '1'})
- # gets session id
- sessionid = r.text.split('g_sessionID = "')[-1].split('";')[0]
- print('Got session id.')
- # readys profile picture for upload
- avatar = {'avatar': ('avatar.png', open(filename, 'rb'), 'image/png')}
- print('Successfully read avatar.')
- # creates avatar payload
- payload = {'MAX_FILE_SIZE': '1048576', 'type': 'player_avatar_image', 'sId': self.sId, 'sessionid': sessionid, 'doSub': '1', 'json': '1'}
- # uploads profile picture
- r = self.session.post('http://steamcommunity.com/actions/FileUploader', data=payload, files=avatar)
- # validates upload
- if r.json()['success']:
- # notifies user avatar uploaded
- print('Uploaded avatar for: {}'.format(self.sId))
- def make_private(self):
- # gets page for session id
- r = self.session.get('http://steamcommunity.com/profiles/{}/edit/settings'.format(self.sId))
- # gets session id
- sessionid = r.text.split('g_sessionID = "')[-1].split('";')[0]
- print('Got session id.')
- # creates make private payload
- payload = {'sessionID': sessionid, 'type': 'profileSettings', 'privacySetting': '1', 'commentSetting': 'commentfriendsonly', 'inventoryPrivacySetting': '2', 'inventoryGiftPrivacy': '1'}
- # posts make private data
- self.session.post('http://steamcommunity.com/profiles/{}/edit/settings'.format(self.sId), data=payload)
- # notifies user
- print('Profile {} has been made private.'.format(self.sId))
- def join_group(self, name):
- # gets group page for session id
- r = self.session.get('http://steamcommunity.com/groups/{}'.format(name))
- # extracts session id
- sessionid = r.text.split('g_sessionID = "')[-1].split('";')[0]
- print('Got session id.')
- # creates join payload
- payload = {'action': 'join', 'sessionID': sessionid}
- # posts join group data
- self.session.post('http://steamcommunity.com/groups/{}'.format(name), data=payload)
- # notifies user
- print('Joined steam group: {}'.format(name))
- def __solve_captcha(self, captcha):
- # creates captcha payload
- payload = {'method': 'post', 'key': self.api_key, 'json': '1'}
- # readys file for upload
- data = {'file': ('captcha.png', captcha, 'image/png')}
- # sends request to 2captcha api to solve captcha
- r = requests.post('http://2captcha.com/in.php', data=payload, files=data)
- # creates payload
- payload = {'key': self.api_key, 'action': 'get', 'id': r.json()['request'], 'json': '1'}
- # loops until it gets response
- while True:
- # sends request to api
- capacha_response = requests.get('http://2captcha.com/res.php', params=payload)
- # checks if the captcha is ready
- if capacha_response.json()['request'] != 'CAPCHA_NOT_READY':
- # decodes and returns response
- return html.unescape(capacha_response.json()['request'])
- if __name__ == '__main__':
- # gets filename from user
- filename = input('Please enter the name of your combo list: ')
- # reads file
- try:
- # tries to open file
- with open(filename, 'r') as f:
- combos = [x.split(':') for x in f.read().split('\n')]
- except IOError:
- # exits
- sys.exit('There was a problem reading the combo file.')
- # notifies user the file was read
- print('Successfully read combo list.')
- # gets group name from user
- group = input('Please enter the name of the group to join: ')
- # gets avatars
- avatars = ['avatars\\' + x for x in os.listdir("avatars")]
- print('Loaded avatars.')
- print('Bot has started.')
- # iterates through list and creates accounts
- for username, password, email in combos:
- # instantiates bot
- bot = SteamBot(api_key='')
- # signs up on steam
- bot.signup(username=username, password=password, email=email)
- # uploads random avatar
- bot.upload_avatar(filename=random.choice(avatars))
- # makes profile private
- bot.make_private()
- # joins group
- bot.join_group(name=group)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement