Skip to content

Commit ee7b5f5

Browse files
committed
修复:markdown问题 feat:更改start id输出内容
1 parent fb53978 commit ee7b5f5

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

run.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,11 @@ async def extract_unique_code(text):
2222
async def send_welcome(message):
2323
unique_code = await extract_unique_code(message.text)
2424
if unique_code:
25-
r = await(PostRequest('https://api.v5.zhelper.net/api/detail/',
26-
j={'id':unique_code}))
27-
if r==1:
28-
await(bot.reply_to(message, 'Connection Error, please contact bot admin. \n\n连接出错,请联系管理员'))
29-
else:
30-
j = json.loads(str(r))
31-
file_name =j['title']+'_'+j['author']+'.'+j['extension']
32-
try:
33-
reply_content='\n'.join(['*RapidUpload_Code(BaiduNetDisk)*: `{}`'.format('{}#{}#{}_{}.{}'.format(j['md5'],j['filesize'],j['title'],j['author'],j['extension'])),
34-
'*IPFS_ID:* `{}`'.format(j['ipfs_cid']),
35-
'*IPFS_PUBLIC_GATEWAY0:* [LINK0(IPFS.IO)](https://ipfs.io/ipfs/{}?filename={})'.format(j['ipfs_cid'],file_name),
36-
'*IPFS_PUBLIC_GATEWAY1:* [LINK1(DWEB.LINK)](https://dweb.link/ipfs/{}?filename={})'.format(j['ipfs_cid'],file_name),
37-
'*WHETHER_FILE_IN_LIBGEN:* {}'.format(j['in_libgen'])])
38-
await(bot.reply_to(message, reply_content, parse_mode="Markdown"))
39-
except:
40-
await(bot.reply_to(message, 'Connection Error, please contact bot admin'))
25+
reply_content=await detail(unique_code)
26+
try:
27+
await(bot.reply_to(message, reply_content, parse_mode="Markdown"))
28+
except:
29+
await(bot.reply_to(message, 'Connection Error, please contact bot admin\n连接错误,请联系机器人管理员'))
4130
else:
4231
reply = """Welcome to Zhelper bot! Please type your book name and we will find the book for you.
4332
zhelper international group: https://t.me/zhelperorg
@@ -89,7 +78,7 @@ async def callback_query(call):
8978
reply_content=await v5(content,page)
9079
try:
9180
await bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
92-
text=reply_content, reply_markup=await gen_page_markup('v5.',content,page),parse_mode='Markdown')
81+
text=reply_content, reply_markup=await gen_page_markup('v5.',content,page),parse_mode='Markdownv2')
9382
except Exception as e:
9483
print(str(e))
9584
await bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,

search.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from req import PostRequest
33
import json,os
44
from dotenv import load_dotenv
5+
from telebot.formatting import escape_markdown
56

67
load_dotenv()
78
BOT_USERNAME = os.environ['BOT_USERNAME']
@@ -13,10 +14,11 @@ async def v5(content,page):
1314
return 'Connection Error, please contact bot admin'
1415
else:
1516
j = json.loads(str(r))
16-
reply_content='\n'.join([' '.join([
17-
str(x) for x in [i['title'],i['author'],i['publisher'],i['extension'],
18-
await(pybyte(i['filesize'])),'\n [Click here and start 点击这里并点击下方对话框start下载](https://t.me/'+BOT_USERNAME+'?start=',i['id'],')']])
19-
for i in j['data']])
17+
reply_content=""
18+
for i in j['data']:
19+
reply_content=reply_content+escape_markdown(' '.join([str(i['title']),str(i['author']),str(i['publisher']),str(i['extension'])]))
20+
reply_content=reply_content+escape_markdown(str(await pybyte(i['filesize'])))
21+
reply_content=reply_content+'\n[Click here and start 点击这里并点击下方对话框start下载](https://t.me/'+BOT_USERNAME+'?start='+str(i['id'])+')\n'
2022
return reply_content
2123

2224

@@ -39,17 +41,17 @@ async def detail(id):
3941
return 'Connection Error, please contact bot admin'
4042
else:
4143
j = json.loads(str(r))
42-
file_name =j['title']+'_'+j['author']+'.'+j['extension']
44+
file_name =escape_markdown(j['title']+'_'+j['author']+'.'+j['extension'])
4345
try:
4446
reply_content = []
4547
# 转义问题无法解决,会出现 奇怪的效果,见 /detail 3556456,这里先用 行内代码顶一下
4648
if j.get('md5') and j.get('filesize'):
47-
rapid_code = '{}#{}#{}_{}.{}'.format(j['md5'],j['filesize'],j['title'],j['author'],j['extension'])
48-
reply_content.append('*RapidUpload_Code(BaiduNetDisk)*: `https://rapidupload.1kbtool.com/{}`'.format(rapid_code))
49+
rapid_code = '{}#{}#{}.{}'.format(j['md5'],j['filesize'],j['title'],j['extension'])
50+
reply_content.append('*RapidUpload_Code(BaiduNetDisk)*: [点击此处跳转到秒传网页](https://rapidupload.1kbtool.com/{})'.format(rapid_code))
4951
if j.get('ipfs_cid'):
50-
reply_content.append('*IPFS:* `https://ipfs-checker.1kbtool.com/{}?filename={}`'.format(j['ipfs_cid'],file_name))
52+
reply_content.append('*IPFS:* [IPFS LINK | 点击此处跳转到IPFS](https://ipfs-checker.1kbtool.com/{}?filename={})'.format(j['ipfs_cid'],file_name))
5153
if j.get('in_libgen') and j.get('md5'):
52-
reply_content.append('*Libgen* `https://libgendown.1kbtool.com/{}`'.format(j['md5']))
54+
reply_content.append('*Libgen* [Libgeb LINK | 点击此处跳转到libgen](https://libgendown.1kbtool.com/{})'.format(j['md5']))
5355
# if j.get('md5') and j.get('filesize'):
5456
# rapid_code = '{}#{}#{}_{}.{}'.format(j['md5'],j['filesize'],j['title'],j['author'],j['extension'])
5557
# reply_content.append('*RapidUpload_Code(BaiduNetDisk)*: [RapidUpload GUI](https://rapidupload.1kbtool.com/{})'.format(rapid_code))
@@ -58,6 +60,6 @@ async def detail(id):
5860
# if j.get('in_libgen') and j.get('md5'):
5961
# reply_content.append('*Libgen*: [Libgen Tool](https://libgendown.1kbtool.com/{})'.format(j['md5']))
6062
reply_content='\n'.join(reply_content)
61-
await(bot.reply_to(message, reply_content, parse_mode="Markdown"))
63+
return reply_content
6264
except:
63-
await(bot.reply_to(message, 'Connection Error, please contact bot admin'))
65+
return 'Connection Error, please contact bot admin'

0 commit comments

Comments
 (0)