Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My Custom Bot - (un)Python(ic)
- """
- Based on https://github.com/ValvePython/steam
- """
- import time
- import datetime as dt
- import gevent
- import json
- import re
- from bs4 import BeautifulSoup
- from steam import SteamClient
- from steam.enums.emsg import EMsg
- from steam.core.msg import MsgProto
- from steam.guard import SteamAuthenticator
- class CustomClass(object):
- def __init__(self, *args, **kwargs):
- super(CustomClass, self).__init__(*args, **kwargs)
- def custom_run_forever(self, sec):
- while 1:
- gevent.sleep(sec)
- def post_comment(self, steamid, comment):
- session = self.get_web_session()
- url = "http://steamcommunity.com/comment/Profile/post/{}/-1/".format(
- str(steamid))
- data = {"comment": "{}".format(comment),
- "count": 6,
- "sessionid": self._web_session_id}
- result = session.post(url, data=data)
- return result.json()
- def fetch_card_data(self):
- session = self.get_web_session()
- url = "http://steamcommunity.com/profiles/STEAMID64/badges/"
- result = session.get(url)
- return result.text
- def add_free_license(self, subid):
- session = self.get_web_session()
- url = "http://store.steampowered.com/checkout/addfreelicense/"
- data = {"sessionid": self._web_session_id,
- "action": "add_to_cart",
- "subid": subid}
- result = session.post(url, data=data)
- return result
- class MySteamClient(SteamClient, CustomClass):
- pass
- client = MySteamClient()
- client.set_credential_location(path)
- username = "username"
- password = "password"
- with open("path\secrets.json", "r") as data:
- secrets = json.load(data)
- sa = SteamAuthenticator(secrets)
- @client.on(EMsg.ClientFriendMsgIncoming)
- def onMessage(msg):
- messageText = msg.body.message.rstrip().strip("\0")
- if "idle" in messageText:
- while 1:
- soup = BeautifulSoup((client.fetch_card_data()), "html.parser")
- appids = []
- for link in soup.find_all("a"):
- result = isCardAvailable(link.get("href"))
- if result:
- appids.append(result.group(1))
- if not appids:
- sendMsg = MsgProto(EMsg.ClientFriendMsg)
- sendMsg.body.steamid = msg.body.steamid_from
- sendMsg.body.chat_entry_type = 1
- sendMsg.body.message = "No more games lef to idle."
- sendMsg.body.rtime32_server_timestamp = int(time.time())
- client.send(sendMsg)
- gevent.sleep(2)
- break
- else:
- sendMsg = MsgProto(EMsg.ClientFriendMsg)
- sendMsg.body.steamid = msg.body.steamid_from
- sendMsg.body.chat_entry_type = 1
- sendMsg.body.message = "Starts idling " + str(appids) + " at " + \
- dt.datetime.now().time().strftime("%H:%M:%S")
- sendMsg.body.rtime32_server_timestamp = int(time.time())
- client.games_played(appids)
- client.send(sendMsg)
- gevent.sleep(1800)
- client.disconnect()
- gevent.sleep(2)
- client.relogin()
- gevent.sleep(3)
- elif "stop" in messageText:
- sendMsg = MsgProto(EMsg.ClientFriendMsg)
- sendMsg.body.steamid = msg.body.steamid_from
- sendMsg.body.chat_entry_type = 1
- sendMsg.body.message = "Stops idling at " + \
- dt.datetime.now().time().strftime("%H:%M:%S")
- sendMsg.body.rtime32_server_timestamp = int(time.time())
- client.send(sendMsg)
- gevent.sleep(1)
- client.disconnect()
- elif isCdKey(messageText):
- cdkeyResult = client.register_product_key(messageText)
- sendMsg = MsgProto(EMsg.ClientFriendMsg)
- sendMsg.body.steamid = msg.body.steamid_from
- sendMsg.body.chat_entry_type = 1
- sendMsg.body.message = str(cdkeyResult)
- sendMsg.body.rtime32_server_timestamp = int(time.time())
- client.send(sendMsg)
- elif "addlicense" in messageText:
- result = client.add_free_license(messageText.replace("addlicense ", ""))
- sendMsg = MsgProto(EMsg.ClientFriendMsg)
- sendMsg.body.steamid = msg.body.steamid_from
- sendMsg.body.chat_entry_type = 1
- sendMsg.body.message = str(result)
- sendMsg.body.rtime32_server_timestamp = int(time.time())
- client.send(sendMsg)
- elif "rep" in messageText:
- sendMsg = MsgProto(EMsg.ClientFriendMsg)
- sendMsg.body.steamid = msg.body.steamid_from
- sendMsg.body.chat_entry_type = 1
- sendMsg.body.message = "You're welcome"
- sendMsg.body.rtime32_server_timestamp = int(time.time())
- client.post_comment(msg.body.steamid_from, "+ rep :)")
- client.send(sendMsg)
- elif messageText:
- sendMsg = MsgProto(EMsg.ClientFriendMsg)
- sendMsg.body.steamid = msg.body.steamid_from
- sendMsg.body.chat_entry_type = 1
- sendMsg.body.message = "Incorrect command line"
- sendMsg.body.rtime32_server_timestamp = int(time.time())
- client.send(sendMsg)
- @client.friends.on(client.friends.EVENT_FRIEND_INVITE)
- def handleFriend(friend):
- client.friends.add(friend.steam_id)
- @client.on(EMsg.ClientAddFriendResponse)
- def welcomeMessage(wel_message):
- greet = MsgProto(EMsg.ClientFriendMsg)
- greet.body.steamid = wel_message.body.steam_id_added
- greet.body.chat_entry_type = 1
- greet.body.message = "Thanks for adding me <3 [Auto generated message]"
- greet.body.rtime32_server_timestamp = int(time.time())
- client.send(greet)
- def isCdKey(cdkey):
- cdkey_regex = re.compile(r'^[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}$')
- return cdkey_regex.search(cdkey)
- def isCardAvailable(card):
- card_regex = re.compile(r'steam://run/([0-9]+)')
- return card_regex.search(card)
- if __name__ == "__main__":
- try:
- client.login(username, password, two_factor_code=sa.get_code())
- # client.cli_login()
- start_time = time.time()
- print "Online"
- client.custom_run_forever(3600)
- except KeyboardInterrupt:
- client.logout()
- print "Total time %s seconds" % (time.time() - start_time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement