def run_register_command(update, context): chat_id = update.message.chat_id telegram_handle = update.message.from_user.username try: identifier = context.args[0] user = user_services.lookup_user_by_telegram_handle(telegram_handle) or User( telegram_handle, "", chat_id ) if SteamID(identifier).is_valid(): # If the identifier is a valid steamid, convert it and done account_id = SteamID(identifier).as_32 elif SteamID.from_url(identifier): # If the identifier is a link to a steam profile, get the id from there account_id = SteamID.from_url(identifier).as_32 else: # Check if the Steam API gives us a valid profile account_id_from_vanity = resolve_steam_vanity_url(identifier) if account_id_from_vanity is not None: account_id = account_id_from_vanity user.account_id = account_id save_user(user) update.message.reply_text( f"Successfully registered user {telegram_handle} as {SteamID(account_id).community_url}" ) except (IndexError, ValueError): update.message.reply_text("No dota friend ID was given") except (UnboundLocalError): update.message.reply_text( "I couldn't make sense of your profile ID! You can give me a Dota friend code, a Steam ID number, a link to your Steam profile or your custom URL." )
def getUsersFriends(apiKey, userId, includeOffline=False): steamId = SteamID.from_url(f'https://steamcommunity.com/id/{userId}') getFriendsUrl = f'http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key={apiKey}&steamid={steamId}&relationship=friend' friendlist = requests.get(getFriendsUrl).json()['friendslist']['friends'] steamidlist = [] # For each friend json item, retrieve the Steam ID of each friend and append it to a list/array for i in range(len(friendlist)): steamidlist.append(friendlist[i]['steamid']) # Convert the list/array to a comma-separated list of Steam user IDs for the API to retrieve. joinedsids = ','.join(steamidlist) userurl = f'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={apiKey}&steamids={joinedsids}' userget = requests.get(userurl).json()['response'] friendsRet = [] for i in range(len(userget['players'])): online = userget['players'][i]['personastate'] if (online == 1 or includeOffline): friend = {} friend["personaname"] = userget['players'][i]['personaname'] friend["steamid"] = userget['players'][i]['steamid'] friend["avatarmedium"] = userget['players'][i]['avatarmedium'] friendsRet.append(friend) else: # not online and not playing a game. continue to the next friend continue dictOut = {} dictOut['friends'] = friendsRet dictOut['thisuserid'] = str(steamId) return dictOut
def cmd_steamid(args): from steam.steamid import SteamID if args.s_input.startswith('http'): _LOG.debug("Input is URL. Making online request to resolve SteamID") s = SteamID.from_url(args.s_input) or SteamID() else: s = SteamID(args.s_input) lines = [ "SteamID: {s.as_64}", "Account ID: {s.as_32}", "Type: {s.type} ({stype})", "Universe: {s.universe} ({suniverse})", "Instance: {s.instance}", "Steam2: {s.as_steam2}", "Steam2Legacy: {s.as_steam2_zero}", "Steam3: {s.as_steam3}", ] if s.community_url: lines += ["Community URL: {s.community_url}"] lines += ["Valid: {is_valid}"] print("\n".join(lines).format( s=s, stype=str(s.type), suniverse=str(s.universe), is_valid=str(s.is_valid()), ))
async def steam_idfp(self, ctx: commands.Context, SteamProfile: str): """Enter a user's Steam Profile URL, and it will respond with their ID""" convert = SteamID.from_url(SteamProfile) try: await ctx.send("User's Steam64ID: \n {}".format(convert)) return except: await ctx.send("Profile Unavaible, or doesn't exist") return
def GET_IDs(profile): steam64 = 0 if profile[0] == 'h': #link steam64 = SteamID.from_url(profile).as_64 else: #simply a pasted steam64 steam64 = int(SteamID(profile)) steam3 = SteamID(steam64).as_steam3 steam1 = SteamID(steam64).as_steam2 return {'64': steam64, '3': steam3, '1': steam1}
def search(request, *args, **kwargs): payload = json.loads(request.body.decode()) if 'steam' in payload: steamid = SteamID.from_url('https://steamcommunity.com/id/' + payload['steam']) if not steamid: data = [] else: data = User.objects.filter(username=str(steamid.as_64)) if not data: user = User() user.is_steam = True user.is_active = False user.username = str(steamid.as_64) user.save() populate(user) data = [user] elif 'steam64' in payload: data = User.objects.filter(username=str(payload['steam64'])) if not data: user = User() user.is_steam = True user.is_active = False user.username = str(payload['steam64']) populate(user) data = [user] elif 'local' in payload: data = User.objects.filter(is_steam=True, namespace__icontains=payload['local']) data = list(data) elif 'steam' in payload: user = User() user.is_steam = False user.is_active = False user.username = payload['steam'] user.save() data = [user] return render(request, 'components/globals/dropdown/wrapper.pug', {'data': data[:settings.PAGE_SIZE]})
async def steamid(self, ctx, communityid: str): """Gets a steam user's steam id in all formats""" await ctx.channel.trigger_typing() steamID = SteamID.from_url( "http://steamcommunity.com/id/{}".format(communityid)) if steamID is None: steamID = SteamID(communityid) try: name = steamAPI.ISteamUser.GetPlayerSummaries_v2( steamids=steamID)["response"]["players"][0]["personaname"] except IndexError: await ctx.send( "User not found! Make sure you are using steam community IDs!") return await ctx.send( xl.format( "Steam ID formats for {}:\nSteamID2: {}\nSteamID2Zero: {}\nSteamID3: {}\nSteamID32: {}\nSteamID64: {}" ).format(name, steamID.as_steam2, steamID.as_steam2_zero, steamID.as_steam3, steamID.as_32, steamID.as_64))
while currentnumber <= pagenumbers: currentpage = url + str(currentnumber) print("Downloading page", currentnumber) page = requests.get(currentpage) soup = BeautifulSoup(page.content, 'html.parser') announceresults = soup.find_all( 'div', class_='announcement' ) #Preferred not to use find_all, but there was no better way if args.html: output_lines = [] #Gotta reset the list on every page urls = re.findall( 'https:\/\/steamcommunity\.com\/id\/[a-zA-Z0-9]+', str(announceresults)) #The following is very inefficent, it has no duplication detection. for found in urls: id64 = SteamID.from_url(found) urlf = re.sub(r'id\/[a-zA-Z0-9]+', r'profiles/%s' % id64, found, re.MULTILINE) output_lines.append(urlf) test = re.sub('https://steamcommunity.com\/id\/[a-zA-Z0-9]+', lambda _: output_lines.pop(0), str(announceresults), len(output_lines) or -1) print(test.strip(), file=open(args.output, "a+", encoding='utf-8')) currentnumber += 1 else: for all in announceresults: test = re.sub(r'([\r\n\t])+', r'\n', all.text) #Removes a bunch of blank lines print(test.strip(), file=open(args.output, "a+", encoding='utf-8')) currentnumber += 1
def input_steamid(): str = input("Enter steamid or profile url:") try: return SteamID(int(str)) except ValueError: return SteamID.from_url(str)
def get_steam_id_from_url(text): return SteamID.from_url(text)
def get_steamid3(url): steamid64 = int(SteamID.from_url(url)) group = SteamID(steamid64) return group.as_steam3
async def steamuser(self, ctx, communityid: str): """Gets steam profile information on a user with the specified community ID""" await ctx.channel.trigger_typing() steamID = SteamID.from_url( "http://steamcommunity.com/id/{}".format(communityid)) if steamID is None: steamID = communityid try: steamUser = steamAPI.ISteamUser.GetPlayerSummaries_v2( steamids=steamID)["response"]["players"][0] except IndexError: await ctx.send( "User not found! Make sure you are using steam community IDs! (steamcommunity.com/id/<ID>)" ) return bans = steamAPI.ISteamUser.GetPlayerBans_v1( steamids=steamID)["players"][0] vacBanned = bans["VACBanned"] communityBanned = bans["CommunityBanned"] ban_info = { "VAC Banned": vacBanned, "Community Banned": communityBanned } if vacBanned: ban_info["VAC Bans"] = bans["NumberOfVACBans"] ban_info["Days Since Last VAC Ban"] = bans["DaysSinceLastBan"] if steamUser["communityvisibilitystate"] != 3: embed = make_list_embed(ban_info) embed.description = "This profile is private." embed.title = steamUser["personaname"] embed.color = 0xFF0000 embed.url = steamUser["profileurl"] embed.set_thumbnail(url=steamUser["avatarfull"]) await ctx.send(embed=embed) return groupCount = len( steamAPI.ISteamUser.GetUserGroupList_v1( steamid=steamID)["response"]["groups"]) games = requests.get( "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key={}&steamid={}&include_played_free_games=1%format=json" .format(config._steamAPIKey, steamID)).json()["response"] gamesPlayed = games["game_count"] state = EPersonaState(steamUser["personastate"]).name gameName = None if "gameid" in steamUser.keys(): state = "In-game" gameID = steamUser["gameid"] gameName = requests.get( "http://store.steampowered.com/api/appdetails?appids={}". format(gameID)).json()[gameID]["data"]["name"] lastOnline = format_time( datetime.fromtimestamp(steamUser["lastlogoff"])) creationDate = format_time( datetime.fromtimestamp(steamUser["timecreated"])) fields = { "Status": state, "Created on": creationDate, "Group Count": groupCount, "Games Owned": gamesPlayed } if state == EPersonaState.Offline.name: fields["Last Online"] = lastOnline if gameName: fields["Currently Playing"] = gameName if "primaryclanid" in steamUser.keys(): fields["Primary Group Name"] = etree.fromstring( requests.get( "http://steamcommunity.com/gid/{}/memberslistxml".format( steamUser["primaryclanid"])).text).find( "groupDetails/groupName").text fields.update(ban_info) embed = make_list_embed(fields) embed.title = steamUser["personaname"] embed.color = 0xFF0000 embed.url = steamUser["profileurl"] embed.set_thumbnail(url=steamUser["avatarfull"]) await ctx.send(embed=embed)