Ejemplo n.º 1
0
    async def l(self, ctx, p: int = 1):
        """Get a list of tags on the current server sorted by uses"""
        guild = guilds.find_one({'id': ctx.guild.id})
        if not 'tags' in guild:
            return await ctx.send(
                'Seems like this server doesn\'t have any tags!')

        s = sorted(
            zip([x[1]['name'] for x in guild['tags']],
                [x[1]['uses'] for x in guild['tags']]))

        if len(guild['tags']) == 0:
            return await ctx.send(
                'Seems like this server doesn\'t have any tags!')

        if math.ceil(len(guild["tags"]) / 10) < p:
            return await ctx.send("Invalid page")

        tags = [f'Tag `{n}` with `{u}` uses' for n, u in s]

        if len(guild['tags']) <= 10:
            return await ctx.send(embed=self._build_embed(ctx, tags, p))

        def make_embed(page, embed, pages):
            return self._build_embed(ctx, tags, page)

        await Paginator(ctx,
                        tags,
                        func=make_embed,
                        max_pages=math.ceil(len(tags) / 10)).start()
Ejemplo n.º 2
0
    def __init__(self, guild_id: int, tag_name: str):
        guild = guilds.find_one({'id': guild_id})
        if guild is None:
            self.found = False
            return
        if not 'tags' in guild:
            self.found = False
            return

        self.tags: list = guild['tags']
        if not tag_name.lower() in [r[0] for r in self.tags]:
            self.found = False
            return

        indx: int = [r[0] for r in self.tags].index(tag_name.lower())
        tag = self.tags[indx]

        self.guild_id = guild_id
        self.found = True
        self.name = tag[1][
            'name']  # By saving it that way it is non case sensitive when searching but keeps case sensitivity when displayed
        self.created_at = tag[1]['created_at']
        self.owner = tag[1]['owner']
        self.content = tag[1]['content']
        self.uses = tag[1]['uses']
Ejemplo n.º 3
0
    async def create(self, ctx, *, tag_name: str):
        """Create a tag with this command! After first using the command it will ask you for the content of the tag"""
        guild = guilds.find_one({'id': ctx.guild.id})
        member = Member(ctx.author.id, ctx.guild.id)
        if not Tag(ctx.guild.id, tag_name).found is False:
            tag = Tag(ctx.guild.id, tag_name)
            user = self.client.fetch_user(tag.owner)
            return await ctx.send(
                f'This tag already exists and is owned by {user}')

        if 'tags' in guild:
            tags = guild['tags']
        else:
            tags = []

        if len(tags) >= 50:
            return await ctx.send('Your server has reached the limit of tags!')
        if member.has_tags:
            if len(member.tags) > 15:
                return await ctx.send(
                    'You can\'t own more than 15 tags on a guild, consider deleting one'
                )
        if len(tag_name) > 30:
            return await ctx.send('The tag title has too many characters!')

        ms = await ctx.send('What should the description of the tag be?')

        def check(m):
            return m.author == ctx.author and m.channel == ctx.channel

        try:
            msg = await self.client.wait_for('message',
                                             check=check,
                                             timeout=120)
        except asyncio.TimeoutError:
            await ms.delete()
            return await ctx.send('Too late, aborting...', delete_after=5)
        else:
            await ms.delete()
            await msg.delete()
            if len(msg.content) > 2000:
                return await ctx.send('Too many characters!')
            tags.append([
                tag_name.lower(), {
                    'name': tag_name,
                    'created_at': datetime.utcnow(),
                    'owner': ctx.author.id,
                    'content': msg.content,
                    'uses': 0
                }
            ])
            guilds.update_one({'id': ctx.guild.id}, {'$set': {'tags': tags}})
            return await ctx.send(f'Successfully created tag `{tag_name}`')
Ejemplo n.º 4
0
 async def info(self, ctx, *, tag_name: str):
     """Get information about any tag"""
     tag = Tag(ctx.guild.id, tag_name.lower())
     if tag.found is False:
         return await ctx.send('There is no tag with that name!')
     guild = guilds.find_one({'id': ctx.guild.id})
     owner = await self.client.fetch_user(tag.owner)
     s = sorted(
         zip([x[0] for x in guild['tags']],
             [x[1]['uses'] for x in guild['tags']]))
     rank = [x[0] for x in s].index(tag_name.lower()) + 1
     embed = discord.Embed.from_dict({
         'title': f'Information about tag "{tag.name}"',
         'description':
         f'**Tag owner:** `{str(owner)}`\n\n**Created on**: <t:{int(tag.created_at.timestamp())}>\n\n**Uses:** `{tag.uses}`\n\n**Tag rank:** `{rank}`',
         'color': 0x1400ff,
         'thumbnail': {
             'url': str(owner.avatar.url)
         }
     })
     await ctx.send(embed=embed)
Ejemplo n.º 5
0
    def __init__(self, user_id: int, guild_id: int):
        guild = guilds.find_one({'id': guild_id})

        if guild is None:
            self.has_tags = False
            return

        if not 'tags' in guild:
            self.has_tags = False
            return

        tags: list = guild['tags']
        if not user_id in [r[1]['owner'] for r in tags]:
            self.has_tags = False
            return

        owned_tags: list = []
        for x in tags:
            owned_tags.append([x[1]['name'], [x[1]['uses']]])

        self.tags = owned_tags
        self.has_tags = True