def photo_from_telegram(bot, update): if update.message: tg_group_id = update.message.chat_id # telegram group id qq_group_id, _, forward_index = get_forward_index(tg_group_id=int(tg_group_id)) file_id = update.message.photo[-1].file_id pic_url = tg_get_pic_url(file_id, 'jpg') if JQ_MODE: text = '[CQ:image,file=' + file_id + '.jpg]' else: text = '[ 图片, 请点击查看' + pic_url + ' ]' if update.message.caption: text += update.message.caption cq_send(update, text, qq_group_id) elif update.edited_message: tg_group_id = update.edited_message.chat_id # telegram group id qq_group_id, _, forward_index = get_forward_index(tg_group_id=int(tg_group_id)) file_id = update.edited_message.photo[-1].file_id pic_url = tg_get_pic_url(file_id, 'jpg') if JQ_MODE: text = '[CQ:image,file=' + file_id + '.jpg]' else: text = '[图片, 请点击查看' + pic_url + ' ]' if update.edited_message.caption: text += update.edited_message.caption cq_send(update, text, qq_group_id, edited=True)
def text_from_telegram(bot, update): tg_group_id = update.message.chat_id # telegram group id qq_group_id, _, forward_index = get_forward_index( tg_group_id=int(tg_group_id)) text = update.message.text if text.startswith('//'): # feature, comment will no be send to qq return else: cq_send(update, text, qq_group_id)
def sticker_from_telegram(bot, update): tg_group_id = update.message.chat_id # telegram group id qq_group_id, _, forward_index = get_forward_index(tg_group_id=int(tg_group_id)) if PIC_LINK_MODE[forward_index]: file_id = update.message.sticker.file_id pic_url = tg_get_pic_url(file_id, 'png') if JQ_MODE: text = '[CQ:image,file=' + file_id + '.png]' else: text = '[ ' + update.message.sticker.emoji + ' sticker, 请点击查看' + pic_url + ' ]' else: text = '[' + update.message.sticker.emoji + ' sticker]' cq_send(update, text, qq_group_id)
def link_from_telegram(bot, update): tg_group_id = update.message.chat_id # telegram group id qq_group_id, _, forward_index = get_forward_index( tg_group_id=int(tg_group_id)) link_regex = re.compile( r'^https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]$') text = update.message.text if link_regex.match(text): # feature, comment will no be send to qq article = Article(text) article.download() article.parse() sender_name = trim_emoji( get_full_user_name(update.message.from_user) ) + ':' # unicode emoji cannot pass into create_cq_share msg = create_cq_share(text, sender_name, article.title, article.top_image if article.top_image else '') cq_send(update, msg, qq_group_id) raise DispatcherHandlerStop()
def document_from_telegram(bot, update): tg_group_id = update.message.chat_id # telegram group id qq_group_id, _, forward_index = get_forward_index(tg_group_id=int(tg_group_id)) text = '[文件]' cq_send(update, text, qq_group_id)