|
@ -33,10 +33,14 @@ class SteamID(object): |
|
|
SteamID(id=12345, type='Invalid', universe='Invalid', instance=0) |
|
|
SteamID(id=12345, type='Invalid', universe='Invalid', instance=0) |
|
|
SteamID(103582791429521412) # steam64 |
|
|
SteamID(103582791429521412) # steam64 |
|
|
SteamID('103582791429521412') |
|
|
SteamID('103582791429521412') |
|
|
|
|
|
SteamID('STEAM_1:0:2') # steam2 |
|
|
SteamID('[g:1:4]') # steam3 |
|
|
SteamID('[g:1:4]') # steam3 |
|
|
SteamID('https://steamcommunity.com/id/drunkenf00l') # vanity url |
|
|
|
|
|
SteamID('http://steamcommunity.com/profiles/76561197968459473') |
|
|
SteamID('http://steamcommunity.com/profiles/76561197968459473') |
|
|
|
|
|
|
|
|
|
|
|
# WARNING: vainty url resolving is fragile |
|
|
|
|
|
# it might break if community profile page changes |
|
|
|
|
|
# you should use the WebAPI to resolve them reliably |
|
|
|
|
|
SteamID('https://steamcommunity.com/id/drunkenf00l') |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
largs = len(args) |
|
|
largs = len(args) |
|
@ -89,6 +93,20 @@ class SteamID(object): |
|
|
|
|
|
|
|
|
# textual input e.g. [g:1:4] |
|
|
# textual input e.g. [g:1:4] |
|
|
else: |
|
|
else: |
|
|
|
|
|
# try steam2 |
|
|
|
|
|
match = re.match(r"^STEAM_(?P<universe>\d+)" |
|
|
|
|
|
r":(?P<reminder>[0-1])" |
|
|
|
|
|
r":(?P<id>\d+)$", value |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if match: |
|
|
|
|
|
self.id = (int(match.group('id')) << 1) | int(match.group('reminder')) |
|
|
|
|
|
self.universe = EUniverse(int(match.group('universe'))) |
|
|
|
|
|
self.type = EType(1) |
|
|
|
|
|
self.instance = 1 |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
# try steam3 |
|
|
typeChars = ''.join(self.ETypeChar.values()) |
|
|
typeChars = ''.join(self.ETypeChar.values()) |
|
|
match = re.match(r"^\[" |
|
|
match = re.match(r"^\[" |
|
|
r"(?P<type>[%s]):" # type char |
|
|
r"(?P<type>[%s]):" # type char |
|
@ -97,23 +115,24 @@ class SteamID(object): |
|
|
r"(:(?P<instance>\d+))?" # instance |
|
|
r"(:(?P<instance>\d+))?" # instance |
|
|
r"\]$" % typeChars, value |
|
|
r"\]$" % typeChars, value |
|
|
) |
|
|
) |
|
|
if not match: |
|
|
if match: |
|
|
raise ValueError("Expected a number or textual SteamID" |
|
|
self.id = int(match.group('id')) |
|
|
" (e.g. [g:1:4]), got %s" % repr(value) |
|
|
self.universe = EUniverse(int(match.group('universe'))) |
|
|
) |
|
|
inverseETypeChar = dict((b, a) for (a, b) in self.ETypeChar.items()) |
|
|
|
|
|
self.type = EType(inverseETypeChar[match.group('type')]) |
|
|
self.id = int(match.group('id')) |
|
|
self.instance = match.group('instance') |
|
|
self.universe = EUniverse(int(match.group('universe'))) |
|
|
if self.instance is None: |
|
|
inverseETypeChar = dict((b, a) for (a, b) in self.ETypeChar.items()) |
|
|
if self.type in (EType.Individual, EType.GameServer): |
|
|
self.type = EType(inverseETypeChar[match.group('type')]) |
|
|
self.instance = 1 |
|
|
self.instance = match.group('instance') |
|
|
else: |
|
|
if self.instance is None: |
|
|
self.instance = 0 |
|
|
if self.type in (EType.Individual, EType.GameServer): |
|
|
|
|
|
self.instance = 1 |
|
|
|
|
|
else: |
|
|
else: |
|
|
self.instance = 0 |
|
|
self.instance = int(self.instance) |
|
|
else: |
|
|
return |
|
|
self.instance = int(self.instance) |
|
|
|
|
|
|
|
|
raise ValueError("Expected a number or textual SteamID" |
|
|
|
|
|
" (e.g. [g:1:4], STEAM_0:1:1234), got %s" % repr(value) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
elif lkwargs > 0: |
|
|
elif lkwargs > 0: |
|
|
if 'id' not in kwargs: |
|
|
if 'id' not in kwargs: |
|
@ -156,7 +175,8 @@ class SteamID(object): |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def as_steam2(self): |
|
|
def as_steam2(self): |
|
|
return "STEAM_0:%s:%s" % ( |
|
|
return "STEAM_%s:%s:%s" % ( |
|
|
|
|
|
self.universe.value, |
|
|
self.id % 2, |
|
|
self.id % 2, |
|
|
self.id >> 1, |
|
|
self.id >> 1, |
|
|
) |
|
|
) |
|
|