示例#1
0
文件: tags.py 项目: jellz/jetski
 def fetch_tag(self, name, guild_id):
     try:
         tag = Tag.select(Tag).where((Tag.name == S(name))
                                     & (Tag.guild_id == guild_id)).get()
     except Tag.DoesNotExist:
         return
     return tag
示例#2
0
    def on_tags_list(self, event):
        tags = Tag.select(Tag, User).join(
            User, on=(User.user_id == Tag.author_id)).where(
                (Tag.guild_id == event.guild.id)).order_by(Tag.name)

        if not tags:
            raise CommandFail('No tags exist')

        embed = MessageEmbed()
        embed.title = 'Tags for {}'.format(event.guild.name)
        embed.description = '\n'.join(
            '- `{}` by {}'.format(tag.name, tag.user.name) for tag in tags)

        event.msg.reply(embed=embed)
示例#3
0
    def on_tags(self, event, name):
        try:
            tag = Tag.select(Tag, User).join(
                User, on=(User.user_id == Tag.author_id
                          )).where((Tag.guild_id == event.guild.id)
                                   & (Tag.name == S(name))).get()
        except Tag.DoesNotExist:
            raise CommandFail('no tag by that name exists')

        # Track the usage of the tag
        Tag.update(times_used=Tag.times_used +
                   1).where((Tag.guild_id == tag.guild_id)
                            & (Tag.name == tag.name)).execute()

        event.msg.reply(':information_source: {}'.format(tag.content))
示例#4
0
    def on_tags_remove(self, event, name):
        try:
            tag = Tag.select(Tag, User).join(
                User, on=(User.user_id == Tag.author_id
                          )).where((Tag.guild_id == event.guild.id)
                                   & (Tag.name == S(name))).get()
        except Tag.DoesNotExist:
            raise CommandFail('no tag by that name exists')

        if tag.author_id != event.author.id:
            if event.user_level <= event.config.min_level_remove_others:
                raise CommandFail(
                    'you do not have the required permissions to remove other users tags'
                )

        tag.delete_instance()
        raise CommandSuccess(u'ok, deleted tag `{}`'.format(tag.name))
示例#5
0
    def on_tags_info(self, event, name):
        try:
            tag = Tag.select(Tag, User).join(
                User, on=(User.user_id == Tag.author_id).alias('author')
            ).where(
                (Tag.guild_id == event.guild.id) &
                (Tag.name == S(name))
            ).get()
        except Tag.DoesNotExist:
            raise CommandFail('no tag by that name exists')

        embed = MessageEmbed()
        embed.title = tag.name
        embed.description = tag.content
        embed.add_field(name='Author', value=unicode(tag.author), inline=True)
        embed.add_field(name='Times Used', value=str(tag.times_used), inline=True)
        embed.timestamp = tag.created_at.isoformat()
        event.msg.reply(embed=embed)
示例#6
0
文件: tags.py 项目: jellz/jetski
    def on_tags_list(self, event, pattern=None):
        buff = u'Available tags: '
        query = Tag.select(Tag.name).where(Tag.guild_id == event.guild.id)
        tags = sorted([i[0] for i in query.tuples()])
        if not tags:
            return event.msg.reply('No tags found for this server.')
        found = 0
        for tag in tags:
            if pattern and tag.lower().find(pattern.lower()) == -1: continue
            tag = u'`{}`, '.format(S(tag, escape_codeblocks=True))
            if len(tag) + len(buff) > 1980:
                event.msg.reply(buff[:-2])
                buff = u''
            buff += tag
            found += 1

        if not found:
            return event.msg.reply('No tags found for this server.')
        return event.msg.reply(u'{} (total: {})'.format(buff[:-2], found))
示例#7
0
文件: tags.py 项目: jellz/jetski
    def on_tags_info(self, event, name):
        try:
            tag = Tag.select(Tag, User).join(
                User, on=(User.user_id == Tag.author_id).alias(
                    'author')).where((Tag.name == S(name))
                                     & (Tag.guild_id == event.guild.id)).get()
        except Tag.DoesNotExist:
            raise CommandFail('no tag exists by that name')

        content = tag.content
        source = self.source_re.search(content)
        if source:
            source = source.group(1).lower()
            url = self.remote_url.format(source)
            r = requests.get(url)
            r = self.import_parser.search(r.content)
            r = r.group(1).decode('utf8').strip('`\n') if r else ''
            data = {'here': '@here', 'everyone': '@everyone'}
            r = self.replace_variables(r, data)
            if not (r and content == r):
                source = None
                content = self.source_re.sub('', content)
                Tag.update(content=content).where((Tag.name == tag.name) & (
                    Tag.guild_id == tag.guild_id)).execute()

        embed = MessageEmbed()
        embed.title = tag.name
        embed.description = clamp(content, 2048)
        embed.add_field(name='Author', value=unicode(tag.author), inline=True)
        embed.add_field(name='Times Used',
                        value=str(tag.times_used),
                        inline=True)
        embed.add_field(
            name='Imported',
            inline=True,
            value='No' if not source else
            ('Yes: [{source}]'
             '(https://github.com/ThaTiemsz/RawgoatTags/blob/master/tags/{source}.md)'
             ).format(source=source))
        embed.timestamp = tag.created_at.isoformat()
        event.msg.reply(embed=embed)