Exemplo n.º 1
0
    async def top12(self, ctx):
        channel_id = ctx.message.channel.id
        author_id = ctx.message.author.id

        bad_permissions = "Sorry, you cannot use that command here."
        bad_username = "******"
        bad_mention = ("Either you have not mentioned a user or that user " +
                       "has not set a lastfm username.")

        channels = permissions_data.get_allowed_channels("compare top12")
        if channel_id not in channels:
            await self.bot.say(bad_permissions)
            return

        user = lastfm_data.get_user(author_id)
        if not user:
            await self.bot.say(bad_username)
            return

        top12 = most_similar(user)
        description = ""
        count = 0
        for similar_user in top12:
            count += 1
            description += str(count) + ": " + similar_user + "\n"

        embed = discord.Embed(color=0xFFFFFF,
                              title=user + "'s similar users",
                              description=description)

        await self.bot.say(embed=embed)
Exemplo n.º 2
0
    async def scrobbles(self, ctx, *args):
        """Display the number of times a user has scrobbled an artist"""
        artist = ""
        for word in args:
            artist += word + " "
        artist = artist[:-1]

        channel_id = ctx.message.channel.id
        author_id = ctx.message.author.id
        author_name = ctx.message.author.name

        bad_permissions = "Sorry, you cannot use that command here."
        bad_username = "******"

        channels = permissions_data.get_allowed_channels("lastfm scrobbles")
        if channel_id not in channels:
            await self.bot.say(bad_permissions)
            return

        user = lastfm_data.get_user(author_id)
        if not user:
            await self.bot.say(bad_username)
            return

        num_scrobbles = get_num_scrobbles_of_artist(user, artist)
        await self.bot.say(author_name + " has scrobbled " + artist + " " +
                           str(num_scrobbles) + " times.")
Exemplo n.º 3
0
    async def lastfm(self, ctx):
        """Display last played, number of artist scrobbles, and top artists"""
        channel_id = ctx.message.channel.id
        author_id = ctx.message.author.id

        bad_permissions = "Sorry, you cannot use that command here."
        bad_username = ("Please set a lastfm username in <#245685218055290881> first, "
                        "using .fm set username.")
        bad_last_played = "I could not find your last played song."

        # Invokes any subcommand given.
        subcommand = ctx.invoked_subcommand
        if subcommand:
            return

        # Bad channel permissions.
        if channel_id not in permissions_data.get_allowed_channels("lastfm"):
            await self.bot.say(bad_permissions)
            return

        user = lastfm_data.get_user(author_id)
        if user is None:
            await self.bot.say(bad_username)
            return

        last_played = get_last_played(user)
        if last_played is None:
            await self.bot.say(bad_last_played)
            return
        
        if ctx.message.channel.id == "243129311421399050":
            await commands.Command.invoke(self.embed_last_played, ctx)
        else:
            await commands.Command.invoke(self.embed_last_played_no_cooldown, ctx)
Exemplo n.º 4
0
    async def compare(self, ctx):
        """Find the similarity of oneself to a target user"""
        channel_id = ctx.message.channel.id
        author_id = ctx.message.author.id

        bad_permissions = "Sorry, you cannot use that command here."
        bad_username = "******"
        bad_mention = ("Either you have not mentioned a user or that user " +
                       "has not set a lastfm username.")

        subcommand = ctx.invoked_subcommand
        if subcommand:
            return

        channels = permissions_data.get_allowed_channels("compare")
        if channel_id not in channels:
            await self.bot.say(bad_permissions)
            return

        try:
            target_id = ctx.message.mentions[0].id
        except:
            await self.bot.say(bad_mention)
            return

        user = lastfm_data.get_user(author_id)
        if not user:
            await self.bot.say(bad_username)
            return

        target = lastfm_data.get_user(target_id)
        if not target:
            await self.bot.say(bad_mention)
            return

        sim = compare_users(user, target)
        if not sim:
            await self.bot.say("Unknown error occurred.")
            return

        await self.bot.say(sim)
Exemplo n.º 5
0
    async def embed_last_played_no_cooldown(self, ctx):
        """Create an embed from last played data"""
        author = ctx.message.author
        author_id = author.id
        avatar_url = author.avatar_url

        user = lastfm_data.get_user(author_id)
        last_played = get_last_played(user)

        name, artist, album, image_url = last_played
        if album == '':
            album = '\u200b'

        user_search_url = "https://www.last.fm/user/{}".format(user)

        color = get_primary_color(image_url)

        embed = discord.Embed(colour=color, description=name)
        embed.add_field(name=artist, value=album)

        embed.set_author(name=user, icon_url=avatar_url, url=user_search_url)
        embed.set_thumbnail(url=image_url)

        await self.bot.say(embed=embed)