Пример #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)
Пример #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.")
Пример #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)
Пример #4
0
    async def search(self, ctx, *, name):
        """Search tags by name"""
        channel_id = ctx.message.channel.id

        bad_permissions = "Sorry, you cannot use that command here."
        if channel_id not in permissions_data.get_allowed_channels(
                "tag search"):
            await self.bot.say(bad_permissions)
            return

        tags = tag_data.search_tags(name)

        await self.bot.say("; ".join(tags))
Пример #5
0
    async def set(self, ctx, *, content):
        """Set content of tag owner is currently editing"""
        if "Regular" not in [x.name for x in ctx.message.author.roles]:
            await self.bot.say(
                "You need to have the Regular role to use that command.")
            return
        channel_id = ctx.message.channel.id

        bad_permissions = "Sorry, you cannot use that command here."
        if channel_id not in permissions_data.get_allowed_channels("tag set"):
            await self.bot.say(bad_permissions)
            return

        tag_data.set_tag_content(ctx.message.author.id, content)
        await self.bot.say("Tag successfully set.")
Пример #6
0
    async def owner(self, ctx, *, name):
        """Find owner of a tag"""
        channel_id = ctx.message.channel.id

        bad_permissions = "Sorry, you cannot use that command here."
        if channel_id not in permissions_data.get_allowed_channels(
                "tag owner"):
            await self.bot.say(bad_permissions)
            return

        owner_id = tag_data.find_tag_owner(name)
        owner = ctx.message.server.get_member(owner_id)

        await self.bot.say("Tag belongs to " + owner.name + "#" +
                           owner.discriminator)
Пример #7
0
    async def setrym(self, ctx, *, content):
        if "Regular" not in [x.name for x in ctx.message.author.roles]:
            await self.bot.say(
                "You need to have the Regular role to use that command.")
            return
        """Set content of rym"""
        channel_id = ctx.message.channel.id

        bad_permissions = "Sorry, you cannot use that command here."
        if channel_id not in permissions_data.get_allowed_channels(
                "chart set"):
            await self.bot.say(bad_permissions)
            return

        tag_data.set_rym_content(ctx.message.author.id, content)
        await self.bot.say("RYM successfully set.")
Пример #8
0
    async def delete(self, ctx, *, name):
        """Delete a tag"""
        channel_id = ctx.message.channel.id

        bad_permissions = "Sorry, you cannot use that command here."
        if channel_id not in permissions_data.get_allowed_channels(
                "tag delete"):
            await self.bot.say(bad_permissions)
            return

        owner_id = tag_data.find_tag_owner(name)
        if owner_id == ctx.message.author.id:
            tag_data.delete_tag(name)
            await self.bot.say("Tag successfully deleted.")
        else:
            await self.bot.say("Sorry, you are not the owner of that tag.")
Пример #9
0
    async def tag(self, ctx):
        """Handle tag commands"""
        subcommand = ctx.invoked_subcommand
        if subcommand:
            return
        """Display any tag content from name"""
        channel_id = ctx.message.channel.id

        bad_permissions = "Sorry, you cannot use that command here."
        if channel_id not in permissions_data.get_allowed_channels("tag"):
            await self.bot.say(bad_permissions)
            return

        name = " ".join(ctx.message.content.split(" ")[1:])

        content = tag_data.get_tag_content(name)
        await self.bot.say(content)
Пример #10
0
    async def list(self, ctx, *, owner):
        """Display tag names belonging to an owner"""
        channel_id = ctx.message.channel.id

        bad_permissions = "Sorry, you cannot use that command here."
        if channel_id not in permissions_data.get_allowed_channels("tag list"):
            await self.bot.say(bad_permissions)
            return

        member = discord.utils.find(lambda m: owner.lower() in m.name.lower(),
                                    ctx.message.channel.server.members)
        if member is None:
            member = discord.utils.find(
                lambda m: owner.lower() in m.display_name.lower(),
                ctx.message.channel.server.members)

        tags = tag_data.list_tags(member.id)

        await self.bot.say("; ".join(tags))
Пример #11
0
    async def set(self, ctx, user):
        """Add a user's lastfm username to table"""
        channel_id = ctx.message.channel.id
        author_id = ctx.message.author.id

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

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

        if not is_username(user):
            await self.bot.say(bad_username)
            return

        lastfm_data.add_user(author_id, user)
        await self.bot.say("Username successfully set!")
Пример #12
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)
Пример #13
0
    async def edit(self, ctx, *, name):
        """Switch to a tag to edit"""
        if "Regular" not in [x.name for x in ctx.message.author.roles]:
            await self.bot.say(
                "You need to have the Regular role to use that command.")
            return
        channel_id = ctx.message.channel.id

        bad_permissions = "Sorry, you cannot use that command here."
        bad_owner = "Sorry, you are not the owner of that tag."

        if channel_id not in permissions_data.get_allowed_channels("tag edit"):
            await self.bot.say(bad_permissions)
            return

        owner = tag_data.get_tag_owner(name)
        if ctx.message.author.id != owner and owner != None:
            await self.bot.say(bad_owner)
            return

        tag_data.edit_tag(ctx.message.author.id, name)
        await self.bot.say("Editing tag.")
Пример #14
0
    async def rym(self, ctx):
        """Display any rym content from owner"""
        channel_id = ctx.message.channel.id

        bad_permissions = "Sorry, you cannot use that command here."
        if channel_id not in permissions_data.get_allowed_channels("chart"):
            await self.bot.say(bad_permissions)
            return

        if len(ctx.message.content.split(" ")) == 1:
            member = ctx.message.author
        else:
            owner = ctx.message.content[7:]
            member = discord.utils.find(
                lambda m: owner.lower() in m.name.lower(),
                ctx.message.channel.server.members)
            if member is None:
                member = discord.utils.find(
                    lambda m: owner.lower() in m.display_name.lower(),
                    ctx.message.channel.server.members)

        content = tag_data.get_rym_content(member.id)
        await self.bot.say("https://rateyourmusic.com/~" + content)