Ejemplo n.º 1
0
    async def set(self, ctx, username):
        params = {
            "user": username,
            "api_key": os.getenv("LASTFM_API_KEY"),
            "format": "json",
            "method": "user.getInfo"
        }

        r = requests.get("http://ws.audioscrobbler.com/2.0/", params=params)
        data = r.json()
        try:
            username = data["user"]["name"]
        except KeyError:
            embed = discord.Embed(
                description=
                f"**Invalid Last.fm username** <a:DubuAngry:773329674679746610>",
                colour=0x4a5fc3)
            return await ctx.send(embed=embed)

        db.update_user(ctx.author.id, "lastfm_username", username)

        embed = discord.Embed(
            description=
            f"Your Last.fm username has been set as **{username}** <a:DubuFlirt:773331886461157427>",
            colour=0x4a5fc3)
        await ctx.send(f"{ctx.author.mention}", embed=embed)
Ejemplo n.º 2
0
    async def unset(self, ctx):
        """Unlink your last.fm."""
        if ctx.foreign_target:
            return await ctx.send(
                ":warning: You cannot unset someone else's lastfm username!")

        db.update_user(ctx.author.id, "lastfm_username", None)
        await ctx.send(
            ":broken_heart: Removed your last.fm username from the database")
Ejemplo n.º 3
0
    async def set(self, ctx, sign):
        """Set your sunsign."""
        hs = [
            'aries', 'taurus', 'gemini', 'cancer', 'leo', 'virgo', 'libra',
            'scorpio', 'sagittarius', 'capricorn', 'aquarius', 'pisces'
        ]
        sign = sign.lower()
        if sign not in hs:
            return await ctx.send(
                f"`{sign}` is not a valid sunsign! Use `>horoscope list` for a list of sunsigns."
            )

        db.update_user(ctx.author.id, "sunsign", sign)
        await ctx.send(f"Sunsign saved as `{sign}`")
Ejemplo n.º 4
0
    async def set(self, ctx, username):
        """Save your last.fm username."""
        if ctx.foreign_target:
            return await ctx.send(
                ":warning: You cannot set lastfm username for someone else!")

        content = await get_userinfo_embed(username)
        if content is None:
            return await ctx.send(
                f":warning: Invalid Last.fm username `{username}`")

        db.update_user(ctx.author.id, "lastfm_username", username)
        await ctx.send(f"{ctx.author.mention} Username saved as `{username}`",
                       embed=content)
Ejemplo n.º 5
0
    async def set(self, ctx, sign):
        """Set your sunsign."""
        hs = [
            "aries",
            "taurus",
            "gemini",
            "cancer",
            "leo",
            "virgo",
            "libra",
            "scorpio",
            "sagittarius",
            "capricorn",
            "aquarius",
            "pisces",
        ]
        sign = sign.lower()
        if sign not in hs:
            return await ctx.send(
                f"`{sign}` is not a valid sunsign! Use `>horoscope list` for a list of sunsigns."
            )

        db.update_user(ctx.author.id, "sunsign", sign)
        await ctx.send(f"Sunsign saved as `{sign}`")
Ejemplo n.º 6
0
    async def weather(self, ctx, *address):
        """Get weather of given location.

        Usage:
            >weather
            >weather <location>
            >weather save <location>
        """
        if len(address) == 0:
            userdata = db.userdata(ctx.author.id)
            location = userdata.location if userdata is not None else None
            if location is None:
                return await util.send_command_help(ctx)

        elif address[0] == "save":
            db.update_user(ctx.author.id, "location", " ".join(address[1:]))
            return await ctx.send(
                f"Saved your location as `{' '.join(address[1:])}`")

        else:
            location = " ".join(address)

        url = "https://maps.googleapis.com/maps/api/geocode/json"
        params = {'address': location, 'key': GOOGLE_API_KEY}
        async with aiohttp.ClientSession() as session:
            async with session.get(url, params=params) as response:
                json_data = await response.json()
        try:
            json_data = json_data['results'][0]
        except IndexError:
            return await ctx.send("Could not get that location.")

        formatted_name = json_data['formatted_address']
        lat = json_data['geometry']['location']['lat']
        lon = json_data['geometry']['location']['lng']
        country = "N/A"
        for comp in json_data['address_components']:
            if 'country' in comp['types']:
                country = comp['short_name'].lower()

        # we have lat and lon now, plug them into dark sky
        async with aiohttp.ClientSession() as session:
            url = f"https://api.darksky.net/forecast/{DARKSKY_API_KEY}/{lat},{lon}?units=si"
            async with session.get(url) as response:
                json_data = await response.json()

        current = json_data['currently']
        hourly = json_data['hourly']
        daily = json_data['daily']
        localtime = await get_timezone({'lat': lat, 'lon': lon})

        content = discord.Embed(color=await util.get_color(ctx, '#e1e8ed'))
        #content.set_thumbnail(url=f"http://flagpedia.net/data/flags/w580/{country}.png")
        content.title = f":flag_{country}: {formatted_name}"
        content.add_field(
            name=
            f"{weather_icons.get(current['icon'], '')} {hourly['summary']}",
            value=f":thermometer: Currently **{current['temperature']} °C** "
            f"( {current['temperature'] * (9.0 / 5.0) + 32:.2f} °F )\n"
            f":neutral_face: Feels like **{current['apparentTemperature']} °C** "
            f"( {current['apparentTemperature'] * (9.0 / 5.0) + 32:.2f} °F )\n"
            f":dash: Wind speed **{current['windSpeed']} m/s** with gusts of **{current['windGust']} m/s**\n"
            f":sweat_drops: Humidity **{int(current['humidity'] * 100)}%**\n"
            f":map: [See on map](https://www.google.com/maps/search/?api=1&query={lat},{lon})"
        )

        content.set_footer(text=f"🕐 Local time {localtime}")
        await ctx.send(embed=content)
Ejemplo n.º 7
0
def login(user_email, access_token):
    ''' add/update user information '''
    if database.exist_user(user_email):
        database.update_user(user_email, access_token)
    else:
        database.add_user(user_email, access_token)
Ejemplo n.º 8
0
async def update_member(before: discord.Member, after: discord.Member):
    if before.display_name != after.display_name \
            or before.name != after.name \
            or before.discriminator != after.discriminator:
        database.update_user(after)