How to use the steam.enums.EType function in steam

To help you get started, we’ve selected a few steam examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ValvePython / steam / tests / test_steamid.py View on Github external
def test_arg_steam3(self):
        self.assertIsNone(steamid.steam3_to_tuple('invalid_format'))
        self.assertIsNone(steamid.steam3_to_tuple(''))
        self.assertIsNone(steamid.steam3_to_tuple(' '))
        self.assertIsNone(steamid.steam3_to_tuple('[U:5:1234]'))
        self.assertIsNone(steamid.steam3_to_tuple('[i:5:1234]'))

        self.assertEqual(steamid.steam3_to_tuple("[i:1:1234]"),
                         (1234, EType.Invalid, EUniverse.Public, 0)
                         )
        self.assertEqual(steamid.steam3_to_tuple("[I:1:1234]"),
                         (1234, EType.Invalid, EUniverse.Public, 0)
                         )
        self.assertEqual(steamid.steam3_to_tuple("[U:0:1234]"),
                         (1234, EType.Individual, EUniverse.Invalid, 1)
                         )

        self.assertEqual(steamid.steam3_to_tuple("[U:1:1234]"),
                         (1234, EType.Individual, EUniverse.Public, 1)
                         )
        self.assertEqual(steamid.steam3_to_tuple("[G:1:1234]"),
                         (1234, EType.GameServer, EUniverse.Public, 1)
                         )
        self.assertEqual(steamid.steam3_to_tuple("[g:1:4]"),
                         (4, EType.Clan, EUniverse.Public, 0)
                         )
        self.assertEqual(steamid.steam3_to_tuple("[A:1:4]"),
                         (4, EType.AnonGameServer, EUniverse.Public, 0)
github ValvePython / steam / tests / test_steamid.py View on Github external
def test_as_invite_url(self):
        self.assertEqual(SteamID(0     , EType.Individual, EUniverse.Public, instance=1).invite_url, None)
        self.assertEqual(SteamID(123456, EType.Individual, EUniverse.Public, instance=1).invite_url, 'https://s.team/p/cv-dgb')
        self.assertEqual(SteamID(123456, EType.Individual, EUniverse.Beta  , instance=1).invite_url, 'https://s.team/p/cv-dgb')
        self.assertEqual(SteamID(123456, EType.Invalid   , EUniverse.Public, instance=1).invite_url, None)
        self.assertEqual(SteamID(123456, EType.Clan      , EUniverse.Public, instance=1).invite_url, None)
github ValvePython / steam / steam / steamid.py View on Github external
Returns steam64 from various other representations.

    .. code:: python

        make_steam64()  # invalid steamid
        make_steam64(12345)  # accountid
        make_steam64('12345')
        make_steam64(id=12345, type='Invalid', universe='Invalid', instance=0)
        make_steam64(103582791429521412)  # steam64
        make_steam64('103582791429521412')
        make_steam64('STEAM_1:0:2')  # steam2
        make_steam64('[g:1:4]')  # steam3
    """

    accountid = id
    etype = EType.Invalid
    universe = EUniverse.Invalid
    instance = None

    if len(args) == 0 and len(kwargs) == 0:
        value = str(accountid)

        # numeric input
        if value.isdigit():
            value = int(value)

            # 32 bit account id
            if 0 < value < 2**32:
                accountid = value
                etype = EType.Individual
                universe = EUniverse.Public
            # 64 bit
github ValvePython / steam / steam / steamid.py View on Github external
def is_valid(self):
        """
        Check whether this SteamID is valid

        :rtype: :py:class:`bool`
        """
        if self.type == EType.Invalid or self.type >= EType.Max:
            return False

        if self.universe == EUniverse.Invalid or self.universe >= EUniverse.Max:
            return False

        if self.type == EType.Individual:
            if self.id == 0 or self.instance > 4:
                return False

        if self.type == EType.Clan:
            if self.id == 0 or self.instance != 0:
                return False

        if self.type == EType.GameServer:
            if self.id == 0:
                return False
github ValvePython / steam / steam / steamid.py View on Github external
def community_url(self):
        """
        :return: e.g https://steamcommunity.com/profiles/123456789
        :rtype: :class:`str`
        """
        suffix = {
            EType.Individual: "profiles/%s",
            EType.Clan: "gid/%s",
        }
        if self.type in suffix:
            url = "https://steamcommunity.com/%s" % suffix[self.type]
            return url % self.as_64

        return None
github ValvePython / steam / steam / steamid.py View on Github external
def as_steam3(self):
        """
        :return: steam3 format (e.g ``[U:1:1234]``)
        :rtype: :class:`str`
        """
        typechar = str(ETypeChar(self.type))
        instance = None

        if self.type in (EType.AnonGameServer, EType.Multiseat):
            instance = self.instance
        elif self.type == EType.Individual:
            if self.instance != 1:
                instance = self.instance
        elif self.type == EType.Chat:
            if self.instance & EInstanceFlag.Clan:
                typechar = 'c'
            elif self.instance & EInstanceFlag.Lobby:
                typechar = 'L'
            else:
                typechar = 'T'

        parts = [typechar, int(self.universe), self.id]

        if instance is not None:
            parts.append(instance)
github ValvePython / steam / steam / steamid.py View on Github external
length = len(args)
        if length == 1:
            etype, = args
        elif length == 2:
            etype, universe = args
        elif length == 3:
            etype, universe, instance = args
        else:
            raise TypeError("Takes at most 4 arguments (%d given)" % length)

    if len(kwargs) > 0:
        etype = kwargs.get('type', etype)
        universe = kwargs.get('universe', universe)
        instance = kwargs.get('instance', instance)

    etype = (EType(etype)
             if isinstance(etype, (int, EType))
             else EType[etype]
             )

    universe = (EUniverse(universe)
                if isinstance(universe, (int, EUniverse))
                else EUniverse[universe]
                )

    if instance is None:
        instance = 1 if etype in (EType.Individual, EType.GameServer) else 0

    assert instance <= 0xffffF, "instance larger than 20bits"

    return (universe << 56) | (etype << 52) | (instance << 32) | accountid
github ValvePython / steam / steam / steamid.py View on Github external
steam32 = int(match.group('id'))
    universe = EUniverse(int(match.group('universe')))
    typechar = match.group('type').replace('i', 'I')
    etype = EType(ETypeChar[typechar])
    instance = match.group('instance')

    if typechar in 'gT':
        instance = 0
    elif instance is not None:
        instance = int(instance)
    elif typechar == 'L':
        instance = EInstanceFlag.Lobby
    elif typechar == 'c':
        instance = EInstanceFlag.Clan
    elif etype in (EType.Individual, EType.GameServer):
        instance = 1
    else:
        instance = 0

    instance = int(instance)

    return (steam32, etype, universe, instance)