Esempio n. 1
0
 async def link(self, ctx: commands.Context, steamID_input: str):
     steamID = SteamID(steamID_input)
     if not steamID.is_valid():
         steamID = from_url(steamID_input, http_timeout=15)
         if steamID is None:
             steamID = from_url(
                 f'https://steamcommunity.com/id/{steamID_input}/',
                 http_timeout=15)
             if steamID is None:
                 raise commands.UserInputError(
                     message='Please enter a valid SteamID or community url.'
                 )
     db = Database('sqlite:///main.sqlite')
     await db.connect()
     await db.execute(
         '''
                     REPLACE INTO users (discord_id, steam_id)
                     VALUES( :discord_id, :steam_id )
                     ''', {
             "discord_id": str(ctx.author.id),
             "steam_id": str(steamID.as_steam2_zero)
         })
     embed = discord.Embed(
         description=
         f'Connected {ctx.author.mention} \n `{steamID.as_steam2}`',
         color=0x00FF00)
     await ctx.send(embed=embed)
Esempio n. 2
0
 async def link(self, ctx: commands.Context, steamID_input: str):
     self.logger.debug(
         f'{ctx.author}: {ctx.prefix}{ctx.invoked_with} {ctx.args[2:]}')
     steamID = SteamID(steamID_input)
     if not steamID.is_valid():
         steamID = from_url(steamID_input, http_timeout=15)
         if steamID is None:
             steamID = from_url(
                 f'https://steamcommunity.com/id/{steamID_input}/',
                 http_timeout=15)
             if steamID is None:
                 raise commands.UserInputError(
                     message='Please enter a valid SteamID or community url.'
                 )
     db = Database('sqlite:///main.sqlite')
     await db.connect()
     await db.execute(
         '''
                     REPLACE INTO users (discord_id, steam_id)
                     VALUES( :discord_id, :steam_id )
                     ''', {
             "discord_id": str(ctx.author.id),
             "steam_id": str(steamID.as_steam2_zero)
         })
     embed = discord.Embed(
         description=
         f'Connected {ctx.author.mention} \n [{steamID.as_steam2}]({steamID_input})',
         color=0x00FF00)
     await ctx.send(embed=embed)
     #add another way to add roles for the users after login.
     #await ctx.author.add_roles(ctx.guild.get_role(808304852676378624))
     self.logger.info(f'{ctx.author} connected to {steamID.as_steam2}')
Esempio n. 3
0
 def get_player_steamid(self, community_links):
     if isinstance(community_links, list):
         out = []
         for i in community_links:
             out.append(steamidapi.from_url(i).as_64)
         return out
     else:
         return str(steamidapi.from_url(community_links).as_64)
Esempio n. 4
0
    def test_from_url(self, s64_from_url):

        s64_from_url.return_value = None
        self.assertIsNone(steamid.from_url(None))

        s64_from_url.return_value = '76580280500085312'
        test_instance = steamid.from_url('76580280500085312')
        self.assertIsInstance(test_instance, SteamID)
        self.assertEqual(test_instance.as_64, 76580280500085312)
Esempio n. 5
0
    def test_from_url(self, s64_from_url):

        s64_from_url.return_value = None
        self.assertIsNone(steamid.from_url(None))

        s64_from_url.return_value = '76580280500085312'
        test_instance = steamid.from_url('76580280500085312')
        self.assertIsInstance(test_instance, SteamID)
        self.assertEqual(test_instance.as_64, 76580280500085312)