From 4b11cabc67ad66e2a47c83f5b477dc2123a6d4cd Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Wed, 24 Oct 2018 21:19:08 +0100 Subject: [PATCH] add invite_code and url propeties to SteamID part of #159 --- steam/steamid.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/steam/steamid.py b/steam/steamid.py index be14063..6bf59f1 100644 --- a/steam/steamid.py +++ b/steam/steamid.py @@ -30,6 +30,10 @@ class ETypeChar(SteamIntEnum): ETypeChars = ''.join(ETypeChar.__members__.keys()) +_steam_invite_hex = "0123456789abcdef" +_steam_invite_valid_chrs = "0123456789abcdefghjkmnpqrtvw" +steam_invite_dictionary = dict(zip(_steam_invite_hex, "bcdfghjkmnpqrtvw")) + class SteamID(intBase): """ @@ -173,6 +177,31 @@ class SteamID(intBase): return '[%s]' % (':'.join(map(str, parts))) + @property + def as_invite_code(self): + """ + :return: s.team invite code format (e.g. ``ABCD-1234``) + :rtype: :class:`str` + """ + def repl_mapper(x): + return steam_invite_dictionary[x.group()] + + invite_code = re.sub("["+_steam_invite_hex+"]", repl_mapper, "%x" % self.id) + split_idx = len(invite_code) // 2 + + if split_idx: + invite_code = invite_code[:split_idx] + '-' + invite_code[split_idx:] + + return invite_code + + @property + def steam_invite_url(self): + """ + :return: e.g https://s.team/p/abcd-1234 + :rtype: :class:`str` + """ + return "https://s.team/p/" + self.as_invite_code + @property def community_url(self): """