This commit is contained in:
Faker 2022-09-13 10:09:46 +08:00
parent 29ec308505
commit 29041c2f24
16 changed files with 887 additions and 930 deletions

File diff suppressed because one or more lines are too long

21
jd_card_force.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -25,26 +25,24 @@ let vender=''
let num=0
let shopname=''
const token = [
"1F00BB7363612C2383557E0270B2970E",
"C71B8EE9D6C7F2B0DF3AF65E3829DAA4",
"91A41C0A7B4F22EDF887D47F168555FD",
"FAE250D8456681EDBD6BB57AF1FC7BC2",
"ED130D17BCE3FA96DAD611A2A2ABD170",
"42061FBDA6C967439D321F7D486421ED",
"2DC699241BEA638476AD834668CE68C7",
"8500B16BACB6E88500C0F24A1106EF26",
"CE2645E1DB3648186A51CE4B9C0A1EF9",
"E2BBCFB0AB8EC48F003B86C4323E2717",
"07E913C217F4A260A2525793769E0FA7",
"98A309279322102F1C0B73D19FF28E19",
"6E866708B29EB404975EF6692F2B77D6",
"F8771E215FB565AC5CB001AD68870BFA",
"E92431BDF2EE7E630C48B4FB1E440427",
"F30279867E8D74DF33E90DAC33738165",
"A49EE21FD3AAAF20F71BDF96A72E7326",
"7A43D1847847DD1857A2BA1F27FBF638",
"D07F1272CA61B9D4FD45082B19DADC54",
"10D78DB822E2A8F13816A601E5729367",
"36B2476C222357AB2E08B9D7EE2A319A",
"1F34207EEB6D381E88F36F58FA260092",
"C2F1EE1845057F573BA89C4CB370EB56",
"FBFF1D26CD47CA07DE296A8D5C7464A5",
"8500B16BACB6E88500C0F24A1106EF26",
"A91FA0869F8D6DC14D824F85176BFAC0",
"B70A83AD9737E1B3DD78FC1A69F35323",
"0CE352C49E77D6354F8F12DD5D6745ED",
"ED130D17BCE3FA96DAD611A2A2ABD170"
"0CE352C49E77D6354F8F12DD5D6745ED"
]
if ($.isNode()) {

13
jd_gehugame.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

352
jd_lotterys.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

74
jd_opencardDPLHTY.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,123 +1,287 @@
{
"api_id": 3741859,
"api_hash": "f81a30b542215b3d578",
"bot_id": 1657544667,
"bot_id": 1657667,
"bot_token": "1657544667:AAGO7sit_k_0u_C1w7U",
"user_id": 951306588,
"user_id": 9513088,
"proxy": true,
"proxy_type": "socks5",
"proxy_addr": "127.0.0.1",
"proxy_port": 7890,
"command": "task",
"log_path": "/jd/log",
"proxy_username": "",
"proxy_password": "",
"proxy_secret": "如果proxy_type是MTProxy,则该值必填",
"log_path": "/ql/log",
"log_send": true,
"monitor_cache_size": 30,
"log_send_id 你日志要发给谁就填谁id": 1,
"log_send_id": -1657544,
"monitor_cache_size": 100,
"monitor_cars 是你要监控的对象需要填上自己bot的id和线报频道或群组id": 1,
"monitor_cars": [
-1001718319262,
-1001533334185,
1657544667
-1001718319262
],
"monitor_auto_stops": [
"jd_AutoOpenCard"
],
"monitor_scripts_path 填写与面板上一样的路径": 1,
"monitor_scripts_path": "/jd/scripts",
"monitor_black_keywords 黑名单关键词基于正则表达式实现": 1,
"monitor_black_keywords": [
"(ShopToken)"
],
"monitor_converters_whitelist_keywords 不转换关键词基于正则表达式实现": 1,
"monitor_converters_whitelist_keywords": [
"(M_WX_)"
],
"monitor_converters 转换关键词基于正则表达式实现": 1,
"monitor_converters": {
"^(?=(.|\\n)*jd_zdjr_activityId)(?=(.|\\n)*cjhy)(.|\\n)*$": {
"env": "export M_WX_TEAM_URL=\"https://cjhydz-isv.isvjcloud.com/wxTeam/activity?activityId=%s\""
},
"^(?=(.|\\n)*jd_zdjr_activityId)(?=(.|\\n)*lzkj)(.|\\n)*$": {
"env": "export M_WX_TEAM_URL=\"https://lzkjdz-isv.isvjcloud.com/wxTeam/activity2/875406?activityId=%s\""
},
"(jd_zpcj|(?=.*jd_task_zp_custom)(?=.*https)^.*$)": {
"env": "export M_WX_LUCK_DRAW_URL=\"%s\""
},
"((?=.*jd_task_jg_custom)(?=.*https)^.*$)": {
"env": "export M_WX_ADD_CART_URL=\"%s\""
},
"((?=.*jd_task_gz_custom)(?=.*https)^.*$)": {
"env": "export M_WX_FOLLOW_DRAW_URL=\"%s\""
}
},
"monitor_scripts": {
"M_WX_WDZ_ID": {
"name": "M微定制",
"file": "m_jd_wx_microDz.js",
"M_WX_TEAM_URL": {
"name": "M组队瓜分京豆",
"task 就是你面板上的那个任务,想怎么写就怎么写 或者 你手动怎么执行就怎么写": 1,
"task": "task /ql/scripts/m_jd_wx_team.js now",
"wait": 0,
"queue": false,
"queue_name": "M_WX_TEAM_URL",
"enable": true
},
"M_WX_TEAM_JF_URL": {
"name": "M组队瓜分积分",
"task": "task /ql/scripts/m_jd_wx_team.js now",
"wait": 0,
"queue": true,
"queue_name": "M_WX_WDZ_ID",
"queue_name": "M_WX_TEAM_JF_URL",
"enable": true
},
"M_WX_SECOND_DRAW_URL": {
"name": "M读秒手速",
"file": "m_jd_wx_secondDraw.js",
"wait": 0,
"queue": false,
"queue_name": "M_WX_SECOND_DRAW_URL",
"M_WX_LEVEL_BIRTH_URL": {
"name": "M等级生日礼包",
"task": "task /ql/scripts/m_jd_wx_levelBirth.js now",
"wait": 5,
"queue": true,
"queue_name": "M_WX_LEVEL_BIRTH_URL",
"enable": true
},
"M_WX_BUILD_DRAW_URL": {
"name": "M盖楼领奖",
"file": "m_jd_wx_buildDraw.js",
"M_JOY_INVITE_URL": {
"name": "M邀请有礼JOY",
"task": "task /ql/scripts/m_jd_joy_invite.js now",
"wait": 0,
"queue": false,
"queue_name": "M_WX_BUILD_DRAW_URL",
"queue_name": "M_JOY_INVITE_URL",
"enable": true
},
"M_WX_LEVEL_BIRTH_BEAN_NUM": {
"name": "M等级/生日礼包",
"file": "m_jd_wx_levelBirth.js",
"M_WX_KNOWLEDGE_URL": {
"name": "知识超人",
"task": "task /ql/scripts/m_jd_wx_knowledge.js now",
"wait": 0,
"queue": false,
"queue_name": "M_WX_LEVEL_BIRTH_BEAN_NUM",
"queue_name": "M_WX_KNOWLEDGE_URL",
"enable": true
},
"M_WX_SHOP_GIFT_URL": {
"name": "M关注有礼无线",
"file": "m_jd_wx_shopGift.js",
"M_LOREAL_INVITE_URL": {
"name": "M邀请有礼LOREAL",
"task": "task /ql/scripts/m_jd_loreal_invite.js now",
"wait": 0,
"queue": false,
"queue_name": "M_WX_SHOP_GIFT_URL",
"enable": true
},
"M_WX_FOLLOW_DRAW_URL": {
"name": "M关注抽奖",
"file": "m_jd_wx_followDraw.js",
"wait": 0,
"queue": false,
"queue_name": "M_WX_FOLLOW_DRAW_URL",
"queue_name": "M_LOREAL_INVITE_URL",
"enable": true
},
"M_WX_ADD_CART_URL": {
"name": "M加购有礼",
"file": "m_jd_wx_addCart.js",
"task": "task /ql/scripts/m_jd_wx_addCart.js now",
"wait": 0,
"queue": false,
"queue_name": "M_WX_ADD_CART_URL",
"enable": true
},
"M_GYG_SHOP_ARGV": {
"name": "M店铺刮奖",
"task": "task /ql/scripts/m_jd_shop_gyg.js now",
"wait": 0,
"queue": false,
"queue_name": "M_GYG_SHOP_ARGV",
"enable": true
},
"M_SHOP_POINT_EXCHANGE_ARGV": {
"name": "M店铺积分兑换",
"task": "task /ql/scripts/m_jd_shop_pointExchange.js now",
"wait": 0,
"queue": true,
"queue_name": "M_SHOP_POINT_EXCHANGE_ARGV",
"enable": true
},
"M_WX_LUCK_DRAW_URL": {
"name": "M幸运抽奖",
"file": "m_jd_wx_luckDraw.js",
"wait": 5,
"task": "task /ql/scripts/m_jd_wx_luckDraw.js now",
"wait": 10,
"queue": true,
"queue_name": "M_WX_LUCK_DRAW_URL",
"enable": true
},
"M_WX_COMPLETE_DRAW_URL": {
"name": "M完善有礼",
"task": "task /ql/scripts/m_jd_wx_completeDraw.js now",
"wait": 30,
"queue": true,
"queue_name": "M_WX_COMPLETE_DRAW_URL",
"enable": true
},
"M_WX_CENTER_DRAW_URL": {
"name": "M老虎机抽奖",
"file": "m_jd_wx_centerDraw.js",
"task": "task /ql/scripts/m_jd_wx_centerDraw.js now",
"wait": 30,
"queue": true,
"queue_name": "M_WX_CENTER_DRAW_URL",
"enable": true
},
"M_WX_GAME_URL": {
"name": "M无线游戏",
"task": "task /ql/scripts/m_jd_wx_game.js now",
"wait": 0,
"queue": true,
"queue_name": "M_WX_GAME_URL",
"enable": true
},
"M_WX_SHOP_GIFT_URL": {
"name": "M关注有礼无线",
"task": "task /ql/scripts/m_jd_wx_shopGift.js now",
"wait": 30,
"queue": true,
"queue_name": "M_WX_SHOP_GIFT_URL",
"enable": true
},
"M_WX_UNPACK_DRAW_URL": {
"name": "M分享福袋",
"task": "task /ql/scripts/m_jd_wx_unPackDraw.js now",
"wait": 0,
"queue": false,
"queue_name": "M_WX_CENTER_DRAW_URL",
"queue_name": "M_WX_UNPACK_DRAW_URL",
"enable": true
},
"M_WX_DAILY_GIFT_URL": {
"name": "M每日领奖",
"task": "task /ql/scripts/m_jd_wx_dailyGift.js now",
"wait": 0,
"queue": false,
"queue_name": "M_WX_DAILY_GIFT_URL",
"enable": true
},
"M_WX_SHOP_SIGN_URL": {
"name": "M签到有礼",
"task": "task /ql/scripts/m_jd_wx_shopSign.js now",
"wait": 10,
"queue": true,
"queue_name": "M_WX_SHOP_SIGN_URL",
"enable": true
},
"M_WX_POINT_DRAW_URL": {
"name": "M积分兑换",
"task": "task /ql/scripts/m_jd_wx_pointDraw.js now",
"wait": 0,
"queue": true,
"queue_name": "M_WX_POINT_DRAW_URL",
"enable": true
},
"M_WX_BUILD_DRAW_URL": {
"name": "M盖楼领奖",
"task": "task /ql/scripts/m_jd_wx_buildDraw.js now",
"wait": 30,
"queue": true,
"queue_name": "DEFAULT_WX_QUEUE",
"enable": true
},
"M_WX_CARTKOI_URL": {
"name": "M购物车锦鲤",
"task": "task /ql/scripts/m_jd_wx_cartKoi.js now",
"wait": 0,
"queue": false,
"queue_name": "M_WX_CARTKOI_URL",
"enable": true
},
"M_WX_SECOND_DRAW_URL": {
"name": "M读秒手速",
"task": "task /ql/scripts/m_jd_wx_secondDraw.js now",
"wait": 10,
"queue": true,
"queue_name": "DEFAULT_WX_QUEUE",
"enable": true
},
"M_WX_FANS_DRAW_URL": {
"name": "M粉丝互动",
"task": "task /ql/scripts/m_jd_wx_fansDraw.js now",
"wait": 30,
"queue": true,
"queue_name": "DEFAULT_WX_QUEUE",
"enable": true
},
"M_FAV_SHOP_ARGV": {
"name": "M收藏有礼",
"file": "m_jd_fav_shop_gift.js",
"task": "task /ql/scripts/m_jd_fav_shop_gift.js now",
"wait": 0,
"queue": false,
"queue_name": "M_FAV_SHOP_ARGV",
"enable": true
},
"M_WX_FOLLOW_DRAW_URL": {
"name": "M关注抽奖",
"task": "task /ql/scripts/m_jd_wx_followDraw.js now",
"wait": 10,
"queue": true,
"queue_name": "M_WX_FOLLOW_DRAW_URL",
"enable": true
},
"M_FOLLOW_SHOP_ARGV": {
"name": "M关注有礼",
"file": "m_jd_follow_shop.js",
"task": "task /ql/scripts/m_jd_follow_shop.js now",
"wait": 0,
"queue": false,
"queue_name": "M_FOLLOW_SHOP_ARGV",
"enable": true
},
"M_FANS_RED_PACKET_URL": {
"name": "M粉丝红包",
"file": "m_jd_fans_redPackt.js",
"M_OPEN_CARD_ARGV": {
"name": "M入会有礼",
"task": "task /ql/scripts/m_jd_open_card.js now",
"wait": 0,
"queue": true,
"queue_name": "M_OPEN_CARD_ARGV",
"enable": true
},
"M_OPEN_CARD_FORCE_ARGV": {
"name": "M强制入会",
"task": "task /ql/scripts/m_jd_open_card_force.js now",
"wait": 0,
"queue": true,
"queue_name": "M_OPEN_CARD_FORCE_ARGV",
"enable": true
},
"M_WX_SHARE_URL": {
"name": "M分享有礼",
"task": "task /ql/scripts/m_jd_wx_share.js now",
"wait": 0,
"queue": false,
"queue_name": "M_FANS_RED_PACKET_URL",
"queue_name": "M_WX_SHARE_URL",
"enable": true
},
"M_WX_DADOUDOU_URL": {
"name": "M打豆豆",
"task": "task /ql/scripts/m_jd_wx_dadoudou.js now",
"wait": 0,
"queue": false,
"queue_name": "M_WX_DADOUDOU_URL",
"enable": true
}
}

240
magic.py
View File

@ -4,6 +4,7 @@ import json
import logging
import os
import re
import time
from urllib import parse
from cacheout import FIFOCache
@ -43,7 +44,7 @@ with open(_ConfigCar, 'r', encoding='utf-8') as f:
properties = json.loads(magic_json)
# 缓存
cache = FIFOCache(maxsize=properties.get("monitor_cache_size"))
cache = FIFOCache(maxsize=properties.get("monitor_cache_size"), ttl=0, timer=time.time)
# Telegram相关
api_id = properties.get("api_id")
@ -52,28 +53,51 @@ bot_id = properties.get("bot_id")
bot_token = properties.get("bot_token")
user_id = properties.get("user_id")
# 监控相关
monitor_cars = properties.get("monitor_cars")
command = properties.get("command")
log_path = properties.get("log_path")
log_send = properties.get("log_send")
log_send = properties.get("log_send", True)
log_send_id = properties.get("log_send_id")
monitor_cars = properties.get("monitor_cars")
logger.info(f"监控的频道或群组-->{monitor_cars}")
monitor_scripts_path = properties.get("monitor_scripts_path")
logger.info(f"监控的文件目录-->{monitor_scripts_path}")
monitor_converters = properties.get("monitor_converters")
logger.info(f"监控转换器-->{monitor_converters}")
monitor_converters_whitelist_keywords = properties.get("monitor_converters_whitelist_keywords")
logger.info(f"不转换白名单关键字-->{monitor_converters_whitelist_keywords}")
monitor_black_keywords = properties.get("monitor_black_keywords")
logger.info(f"黑名单关键字-->{monitor_black_keywords}")
monitor_scripts = properties.get("monitor_scripts")
monitor_auto_stops = properties.get("monitor_auto_stops")
logger.info(f"监控的自动停车-->{monitor_auto_stops}")
if properties.get("proxy"):
if properties.get("proxy_type") == "MTProxy":
proxy = {
'addr': properties.get("proxy_addr"),
'port': properties.get("proxy_port"),
'proxy_secret': properties.get('proxy_secret', "")
}
else:
proxy = {
'proxy_type': properties.get("proxy_type"),
'addr': properties.get("proxy_addr"),
'port': properties.get("proxy_port")
'port': properties.get("proxy_port"),
'username': properties.get('proxy_username', ""),
'password': properties.get('proxy_password', "")
}
client = TelegramClient("magic", api_id, api_hash, proxy=proxy, auto_reconnect=True, retry_delay=1, connection_retries=99999).start()
else:
client = TelegramClient("magic", api_id, api_hash, auto_reconnect=True, retry_delay=1, connection_retries=99999).start()
def rest_of_day():
"""
:return: 截止到目前当日剩余时间
"""
today = datetime.datetime.strptime(str(datetime.date.today()), "%Y-%m-%d")
tomorrow = today + datetime.timedelta(days=1)
nowTime = datetime.datetime.now()
return (tomorrow - nowTime).seconds - 90 # 获取秒
def rwcon(arg):
if arg == "str":
with open(_ConfigSh, 'r', encoding='utf-8') as f1:
@ -132,13 +156,13 @@ async def handler(event):
# 设置变量
@client.on(events.NewMessage(chats=monitor_cars, pattern='^在吗$'))
@client.on(events.NewMessage(chats=[bot_id], pattern='^在吗$'))
async def handler(event):
await client.send_message(bot_id, f'老板啥事?')
# 设置变量
@client.on(events.NewMessage(chats=monitor_cars, pattern='^清理缓存$'))
@client.on(events.NewMessage(chats=[bot_id], pattern='^清理缓存$'))
async def handler(event):
b_size = cache.size()
logger.info(f"清理前缓存数量,{b_size}")
@ -148,8 +172,33 @@ async def handler(event):
await client.send_message(bot_id, f'清理缓存结束 {b_size}-->{a_size}')
# 监听事件
@client.on(events.NewMessage(chats=monitor_cars))
async def get_activity_info(text):
result = re.findall(r'((http|https)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])', text)
if len(result) <= 0:
return None, None
url = re.search('((http|https)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])', text)[0]
params = parse.parse_qs(parse.urlparse(url).query)
ban_rule_list = [
'activityId',
'giftId',
'actId',
'tplId',
'token',
'code',
'a',
'id']
activity_id = ''
for key in ban_rule_list:
activity_id = params.get(key)
logger.info(activity_id)
if activity_id is not None:
activity_id = params.get(key)
activity_id = activity_id[0]
break
return activity_id, url
@client.on(events.NewMessage(chats=monitor_cars, pattern=r'((export\s)?\w*=(".*"|\'.*\')|[/ikun])'))
async def handler(event):
origin = event.message.text
text = re.findall(r'https://i.walle.com/api\?data=(.+)?\)', origin)
@ -159,76 +208,99 @@ async def handler(event):
text = origin
else:
return
groupname = "mybot"
try:
logger.info(f"原始数据 {text}")
# 微定制
if "WDZactivityId" in text:
activity_id = re.search(f'WDZactivityId="(.+?)"', text)[1]
groupname = f'[{event.chat.title}](https://t.me/c/{event.chat.id}/{event.message.id})'
except Exception:
pass
try:
origin_text = text
logger.info(f"原始数据 {origin_text}")
# 黑名单
for b_key in monitor_black_keywords:
result = re.search(b_key, origin_text)
if result is not None:
await client.send_message(bot_id, f'黑名单 {b_key} {text}')
return
text = await converter_handler(text)
activity_id, url = await get_activity_info(text)
if "mybot" not in groupname:
if activity_id is not None:
if cache.get(activity_id) is not None:
await client.send_message(bot_id, f'跑过 {text}')
await client.send_message(bot_id, f'{groupname}】跑过 `{activity_id}`')
return
cache.set(activity_id, activity_id)
text = f'export jd_wdz_custom="{activity_id}"'
else:
urls = re.search('((http|https)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])', text)
if urls is not None:
url = urls[0]
domain = re.findall('https?://([^/]+)', url)[0]
params = parse.parse_qs(parse.urlparse(url).query)
activity_id = ''
if 'cjhy' in domain or 'lzkj' in domain or 'lzdz1' in domain:
if 'pageDecorateView/previewPage' in url:
activity_id = params["tplId"][0]
elif 'wxPointShopView' in url:
activity_id = params["giftId"][0]
elif 'activityId' in url:
activity_id = params["activityId"][0]
if len(activity_id) == 0:
if cache.get(text) is not None:
await client.send_message(bot_id, f'跑过 {text}')
return
cache.set(text, text)
elif cache.get(activity_id) is not None:
await client.send_message(bot_id, f'跑过 {text}')
return
cache.set(activity_id, activity_id)
cache.set(activity_id, activity_id, rest_of_day())
else:
if cache.get(text) is not None:
await client.send_message(bot_id, f'跑过 {text}')
await client.send_message(bot_id, f'{groupname}】跑过 {text}')
return
cache.set(text, text)
cache.set(text, text, rest_of_day())
logger.info(f"最终变量 {text}")
kv = text.replace("export ", "")
key = kv.split("=")[0]
value = re.findall(r'"([^"]*)"', kv)[0]
action = monitor_scripts.get(key)
logger.info(f'ACTION {action}')
if action is None: # 没有自动车
await client.send_message(bot_id, f'没有自动车 #{text}')
await client.send_message(bot_id, f'{groupname}】没有自动车 {text}')
return
file = action.get("file", "")
# 没有匹配的动作 或没开启
if not action.get("enable"):
await client.send_message(bot_id, f'{groupname}】没启用任务 {key}')
return
command = action.get("task", "")
if command == '':
await client.send_message(bot_id, f'{groupname}】没有配置任务 {key}')
return
name = action.get("name")
enable = action.get("enable")
logger.info(f'name {name} enable {enable}')
if not enable:
await client.send_message(bot_id, f'未开启任务 #{name}')
if action.get("queue"):
await queues[action.get("queue_name")].put({"text": text, "groupname": groupname, "action": action})
await client.send_message(bot_id, f'{groupname}】入队执行 #{name}')
return
queue = action.get("queue")
logger.info(f'queue {queue} name {name}')
if queue:
await queues[action.get("queue_name")].put({"text": text, "action": action})
await client.send_message(bot_id, f'入队执行 #{name}')
return
logger.info(f'设置环境变量export {action}')
await export(text)
await client.send_message(bot_id, f'开始执行 #{name}')
await cmd(f'{command} {monitor_scripts_path}/{file}')
await client.send_message(bot_id, f'{groupname}】开始执行 #{name}')
await cmd(command)
except Exception as e:
logger.error(e)
await client.send_message(bot_id, f'{str(e)}')
async def converter_handler(text):
text = text.replace("`", "")
for c_w_key in monitor_converters_whitelist_keywords:
result = re.search(c_w_key, text)
if result is not None:
logger.info(f"无需转换 {text}")
return text
logger.info(f"转换前数据 {text}")
try:
tmp_text = text
# 转换
for c_key in monitor_converters:
result = re.search(c_key, text)
if result is None:
logger.info(f"规则不匹配 {c_key},下一个")
continue
rule = monitor_converters.get(c_key)
target = rule.get("env")
argv_len = len(re.findall("%s", target))
values = re.findall(r'"([^"]*)"', text)
if argv_len == 1:
target = target % (values[0])
elif argv_len == 2:
target = target % (values[0], values[1])
elif argv_len == 3:
target = target % (values[0], values[1], values[2])
else:
print("不支持更多参数")
text = target
break
if tmp_text == text:
await client.send_message(bot_id, f'无法转换 {text}')
except Exception as e:
logger.info(str(e))
logger.info(f"转换后数据 {text}")
return text
queues = {}
@ -238,40 +310,35 @@ async def task(task_name, task_key):
while True:
try:
param = await curr_queue.get()
logger.info(f"出队执行开始 {param}")
text = param.get("text")
kv = text.replace("export ", "")
key = kv.split("=")[0]
value = re.findall(r'"([^"]*)"', kv)[0]
logger.info(f'出队执行变量与值 {key},{value}')
action = param.get("action")
logger.info(f'ACTION {action}')
file = action.get("file", "")
logger.info(f'JTASK命令 {file},{parse.quote_plus(value)}')
logger.info(f'出队执行-->设置环境变量export {action}')
await export(text)
await cmd(f'{command} {monitor_scripts_path}/{file}')
logger.info(f"出队执行 {param}")
exec_action = param.get("action")
# 默认立马执行
await client.send_message(bot_id, f'{param.get("groupname")}】出队执行 #{exec_action.get("name")}')
await export(param.get("text"))
await cmd(exec_action.get("task", ""))
if curr_queue.qsize() > 1:
await client.send_message(bot_id, f'{action["name"]},队列长度{curr_queue.qsize()},将等待{action["wait"]}秒...')
await asyncio.sleep(action['wait'])
exec_action = param.get("action")
await client.send_message(bot_id, f'{exec_action["name"]},队列长度{curr_queue.qsize()},将等待{exec_action["wait"]}秒...')
await asyncio.sleep(exec_action['wait'])
except Exception as e:
logger.error(e)
async def cmd(text):
async def cmd(exec_cmd):
try:
logger.info(f"执行命令{text}")
name = re.findall(r'[^/:*?"<>|]+$', text)[0]
logger.info(f'执行命令 {exec_cmd}')
name = re.findall(r'(?:.*/)*([^. ]+)\.(?:js|py|sh)', exec_cmd)[0]
tmp_log = f'{log_path}/{name}.{datetime.datetime.now().strftime("%H%M%S%f")}.log'
logger.info(f'日志文件 {tmp_log}')
proc = await asyncio.create_subprocess_shell(
f"{text} >> {tmp_log} 2>&1",
f"{exec_cmd} >> {tmp_log} 2>&1",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
await proc.communicate()
if log_send:
await client.send_file(bot_id, tmp_log)
# os.remove(tmp_log)
await client.send_file(log_send_id, tmp_log)
os.remove(tmp_log)
except Exception as e:
logger.error(e)
await client.send_message(bot_id, f'something wrong,I\'m sorry\n{str(e)}')
@ -284,11 +351,12 @@ if __name__ == "__main__":
action = monitor_scripts[key]
name = action.get('name')
queue = action.get("queue")
if queue:
queues[action.get("queue_name")] = asyncio.Queue()
client.loop.create_task(task(name, key))
else:
logger.info(f"无需队列--> {name} {key}")
queue_name = action.get("queue_name")
if queues.get(queue_name) is not None:
logger.info(f"队列监听--> {name} {queue_name} 已启动,等待任务")
continue
queues[queue_name] = asyncio.Queue()
client.loop.create_task(task(name, queue_name))
client.run_until_disconnected()
except Exception as e:
logger.error(e)