def on_tags_raw(self, event, name): tag = self.fetch_tag(name, event.guild.id) if not tag: 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 r and content == r: return event.msg.reply(( 'This tag was imported from `{source}`: <https://github.com/ThaTiemsz' '/RawgoatTags/blob/master/tags/{source}.md>').format( source=source)) content = self.source_re.sub('', content) Tag.update(content=content).where((Tag.name == tag.name) & ( Tag.guild_id == tag.guild_id)).execute() if len(S(content, False, True)) > 1990: return event.msg.reply( 'This tag is too long. See attached file for the source.', attachments=[('tag_raw_{}.txt'.format(event.msg.id), content)]) event.msg.reply(u'```\n{}\n```'.format(S(content, False, True)))
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))
def on_tags(self, event, name, text='', debug=False): tag = self.fetch_tag(name, event.guild.id) if not tag: raise CommandFail('no tag exists by that name') # Track the usage of the tag Tag.update(times_used=Tag.times_used + 1).where((Tag.name == tag.name) & (Tag.guild_id == tag.guild_id)).execute() content = self.compile_tag(event, tag.content, text, debug) if not debug: event.msg.reply( clamp(u':information_source: {}'.format(content), 2000))
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)