增加通过bot上传js文件到/scripts目录并可以选择执行的交互

This commit is contained in:
iouAkira
2021-03-24 23:02:09 +08:00
parent b70b72a93b
commit 016477ede5

View File

@@ -951,6 +951,37 @@ def parseJDCookies(headers):
jd_cookie = f'pt_key={pt_key};pt_pin={pt_pin};'
def saveFile(update, context):
from_user_id = update.message.from_user.id
if admin_id == str(from_user_id):
js_file_name = update.message.document.file_name
if str(js_file_name).endswith(".js"):
save_path = f"{_base_dir}{js_file_name}"
try:
# logger.info(update.message)
file = context.bot.getFile(update.message.document.file_id)
file.download(save_path)
keyboard_line = [[InlineKeyboardButton('node 执行', callback_data='node %s ' % save_path),
InlineKeyboardButton('spnode 执行',
callback_data='spnode %s' % save_path)],
[InlineKeyboardButton('取消操作', callback_data='cancel')]]
reply_markup = InlineKeyboardMarkup(keyboard_line)
update.message.reply_text(
text='```{}```'.format(
helpers.escape_markdown(' ↓↓↓ %s 上传至/scripts完成请请选择需要的操作 ↓↓↓ ' % js_file_name)),
reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN_V2)
except Exception as e:
update.message.reply_text(text='```{}```'.format(
helpers.escape_markdown(" →→→ %s js上传至/scripts过程中出错请重新尝试。 ←←← " % js_file_name)),
parse_mode=ParseMode.MARKDOWN_V2)
else:
update.message.reply_text(text='```{}```'.format(
helpers.escape_markdown(" →→→ 抱歉暂时只开放上传js文件至/scripts目录 ←←← ")),
parse_mode=ParseMode.MARKDOWN_V2)
def unknown(update, context):
"""回复用户输入不存在的指令
"""
@@ -983,14 +1014,12 @@ def unknown(update, context):
else:
update.message.reply_text(text='此为私人使用bot,不能执行您的指令!')
def error(update, context):
"""Log Errors caused by Updates."""
logger.warning('Update "%s" caused error "%s"', update, context.error)
context.bot.send_message(
'Update "%s" caused error "%s"', update, context.error)
def main():
global admin_id, bot_token, crontab_list_file
@@ -1055,6 +1084,9 @@ def main():
# 通过 get_jd_cookie 函数 响应 '/eikooc_dj_teg' 命令 #别问为啥这么写,有意为之的
dp.add_handler(CommandHandler('eikooc_dj_teg', get_jd_cookie))
# 文件监听
dp.add_handler(MessageHandler(Filters.document, saveFile))
# 没找到对应指令
dp.add_handler(MessageHandler(Filters.command, unknown))
@@ -1066,7 +1098,6 @@ def main():
updater.start_polling()
updater.idle()
# 生成依赖安装列表
# pip3 freeze > requirements.txt
# 或者使用pipreqs