def konachan_download(update, context): message = update.message try: post_id = int(context.args[0]) if post_id <= 0: message.reply_text('Invalid post id!') return imgs = moebooru.site('konachan.com').download(post_id) sendDocuments(update, context, imgs) except (IndexError, ValueError): message.reply_text('Usage: /konachan_download <post_id>') except NazurinError as error: message.reply_text(error.msg)
def pixiv_download(update, context): message = update.message try: # args[0] should contain the queried artwork id artwork_id = int(context.args[0]) if artwork_id < 0: message.reply_text('Invalid artwork id!') return imgs = pixiv.download_illust(artwork_id) sendDocuments(update, context, imgs) except (IndexError, ValueError): message.reply_text('Usage: /pixiv_download <artwork_id>') except NazurinError as error: message.reply_text(error.msg)
def collection_update(update, context): message = update.message message_id = message.message_id chat_id = message.chat_id bot = context.bot # Match URL if message.entities: entities = message.entities text = message.text elif message.caption_entities: entities = message.caption_entities text = message.caption else: message.reply_text('Error: URL not found') return # Telegram counts entity offset and length in UTF-16 code units text = text.encode('utf-16-le') urls = list() for item in entities: if item.type == 'text_link': urls.append(item.url) elif item.type == 'url': offset = item.offset length = item.length urls.append(text[offset * 2:(offset + length) * 2].decode('utf-16-le')) result = sites.match(urls) if not result: message.reply_text('Error: No source matched') return logger.info('Collection update: site=%s, match=%s', result['site'], result['match'].groups()) # Forward to gallery & Save to album bot.forwardMessage(config.GALLERY_ID, chat_id, message_id) chat_id = config.ALBUM_ID message_id = None # No need to reply to message try: imgs = sites.handle_update(result) sendDocuments(update, context, imgs, chat_id=chat_id) storage.store(imgs) message.reply_text('Done!') except NazurinError as error: message.reply_text(error.msg)