DeepBlue/cogs/api/steam.py

27 lines
959 B
Python
Raw Permalink Normal View History

2020-01-08 02:26:36 +01:00
'''
This cog can fetch data from the
Steam WebAPI
'''
2020-01-07 02:41:08 +01:00
import discord
from discord.ext import commands
from api import steam
class Steam(commands.Cog):
2020-01-08 02:26:36 +01:00
def __init__(self, client: discord.Client):
2020-01-07 02:41:08 +01:00
self.client = client
2020-01-08 21:18:17 +01:00
@commands.command(name="steamlevel", description="Finds the steam level of a user", usage="steamlevel <Vanity URL>", aliases=["level"])
2020-01-07 02:41:08 +01:00
@commands.cooldown(1, 2)
2020-01-08 02:26:36 +01:00
async def SteamLevel(self, ctx: commands.Context, vanity_url: str):
2020-01-07 02:41:08 +01:00
level = steam.get_steam_level(vanity_url)
2020-01-07 04:07:39 +01:00
if level is None:
2020-01-07 02:41:08 +01:00
await ctx.send(f"There is nobody named \"{vanity_url}\" on Steam, or their profile might be pivate.")
2020-01-07 04:07:39 +01:00
else:
percentile = round(float(steam.get_steam_level_distribution(level)), 2)
await ctx.send(f"{vanity_url} is level {level}! This makes him better than {percentile}% of Steam users!")
2020-01-07 02:41:08 +01:00
2020-01-08 02:26:36 +01:00
def setup(client: discord.Client):
2020-01-07 02:41:08 +01:00
client.add_cog(Steam(client))