mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-14 13:47:24 +08:00
✨ 添加对lyfunction的支持
This commit is contained in:
parent
c2b3018908
commit
074882f092
@ -216,7 +216,12 @@ async def _(result: Arparma, bot: T_Bot, event: T_MessageEvent, matcher: Matcher
|
|||||||
arg = arg.replace("\\=", "EQUAL_SIGN")
|
arg = arg.replace("\\=", "EQUAL_SIGN")
|
||||||
if "=" in arg:
|
if "=" in arg:
|
||||||
key, value = arg.split("=", 1)
|
key, value = arg.split("=", 1)
|
||||||
_kwargs[key] = value.replace("EQUAL_SIGN", "=")
|
value = unescape(value.replace("EQUAL_SIGN", "="))
|
||||||
|
try:
|
||||||
|
value = eval(value)
|
||||||
|
except:
|
||||||
|
value = value
|
||||||
|
_kwargs[key] = value
|
||||||
else:
|
else:
|
||||||
_args.append(arg.replace("EQUAL_SIGN", "="))
|
_args.append(arg.replace("EQUAL_SIGN", "="))
|
||||||
|
|
||||||
@ -226,6 +231,7 @@ async def _(result: Arparma, bot: T_Bot, event: T_MessageEvent, matcher: Matcher
|
|||||||
|
|
||||||
await ly_func(*tuple(_args), **_kwargs)
|
await ly_func(*tuple(_args), **_kwargs)
|
||||||
|
|
||||||
|
|
||||||
@on_alconna(
|
@on_alconna(
|
||||||
command=Alconna(
|
command=Alconna(
|
||||||
"/api",
|
"/api",
|
||||||
@ -269,6 +275,7 @@ async def _(result: Arparma, bot: T_Bot, event: T_MessageEvent, matcher: Matcher
|
|||||||
print(f"API: {api_name}\n\nArgs: \n{args_show}\n\nResult: {result}")
|
print(f"API: {api_name}\n\nArgs: \n{args_show}\n\nResult: {result}")
|
||||||
await matcher.finish(f"API: {api_name}\n\nArgs: \n{args_show}\n\nResult: {result}")
|
await matcher.finish(f"API: {api_name}\n\nArgs: \n{args_show}\n\nResult: {result}")
|
||||||
|
|
||||||
|
|
||||||
# system hook
|
# system hook
|
||||||
@Bot.on_calling_api # 图片模式检测
|
@Bot.on_calling_api # 图片模式检测
|
||||||
async def test_for_md_image(bot: T_Bot, api: str, data: dict):
|
async def test_for_md_image(bot: T_Bot, api: str, data: dict):
|
||||||
@ -300,6 +307,7 @@ async def test_for_md_image(bot: T_Bot, api: str, data: dict):
|
|||||||
return
|
return
|
||||||
raise MockApiException(result=result)
|
raise MockApiException(result=result)
|
||||||
|
|
||||||
|
|
||||||
@driver.on_startup
|
@driver.on_startup
|
||||||
async def on_startup():
|
async def on_startup():
|
||||||
temp_data = common_db.where_one(TempConfig(), default=TempConfig())
|
temp_data = common_db.where_one(TempConfig(), default=TempConfig())
|
||||||
@ -309,10 +317,12 @@ async def on_startup():
|
|||||||
temp_data.data["delta_time"] = delta_time
|
temp_data.data["delta_time"] = delta_time
|
||||||
common_db.save(temp_data) # 更新数据
|
common_db.save(temp_data) # 更新数据
|
||||||
|
|
||||||
|
|
||||||
@driver.on_shutdown
|
@driver.on_shutdown
|
||||||
async def on_shutdown():
|
async def on_shutdown():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@driver.on_bot_connect
|
@driver.on_bot_connect
|
||||||
async def _(bot: T_Bot):
|
async def _(bot: T_Bot):
|
||||||
temp_data = common_db.where_one(TempConfig(), default=TempConfig())
|
temp_data = common_db.where_one(TempConfig(), default=TempConfig())
|
||||||
@ -342,6 +352,7 @@ async def _(bot: T_Bot):
|
|||||||
message="Liteyuki reloaded in %.2f s" % delta_time
|
message="Liteyuki reloaded in %.2f s" % delta_time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 每天4点更新
|
# 每天4点更新
|
||||||
@scheduler.scheduled_job("cron", hour=4)
|
@scheduler.scheduled_job("cron", hour=4)
|
||||||
async def every_day_update():
|
async def every_day_update():
|
||||||
@ -355,6 +366,7 @@ async def every_day_update():
|
|||||||
else:
|
else:
|
||||||
nonebot.logger.info(logs)
|
nonebot.logger.info(logs)
|
||||||
|
|
||||||
|
|
||||||
# 需要用户id的api
|
# 需要用户id的api
|
||||||
need_user_id = (
|
need_user_id = (
|
||||||
"send_private_msg",
|
"send_private_msg",
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
var qq={0} msg={1} a=A
|
|
||||||
api send_private_msg user_id=qq message=msg
|
api send_private_msg user_id=qq message=msg
|
||||||
sleep 3
|
sleep 3
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
var user_id={0}
|
|
||||||
api friend_poke user_id=user_id
|
api friend_poke user_id=user_id
|
||||||
api friend_poke user_id=user_id
|
api friend_poke user_id=user_id
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
|
@ -31,14 +31,16 @@ class LiteyukiFunction:
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.functions: list[str] = list()
|
self.functions: list[str] = list()
|
||||||
self.bot: Bot = None
|
self.bot: Bot = None
|
||||||
self.var_data = dict()
|
self.kwargs_data = dict()
|
||||||
self.macro_data = dict()
|
self.args_data = list()
|
||||||
self.matcher: Matcher = None
|
self.matcher: Matcher = None
|
||||||
self.end = False
|
self.end = False
|
||||||
|
|
||||||
self.sub_tasks: list[asyncio.Task] = list()
|
self.sub_tasks: list[asyncio.Task] = list()
|
||||||
|
|
||||||
async def __call__(self, *args, **kwargs):
|
async def __call__(self, *args, **kwargs):
|
||||||
|
self.kwargs_data.update(kwargs)
|
||||||
|
self.args_data = list(set(self.args_data + list(args)))
|
||||||
for i, cmd in enumerate(self.functions):
|
for i, cmd in enumerate(self.functions):
|
||||||
r = await self.execute_line(cmd, i, *args, **kwargs)
|
r = await self.execute_line(cmd, i, *args, **kwargs)
|
||||||
if r == 0:
|
if r == 0:
|
||||||
@ -62,7 +64,6 @@ class LiteyukiFunction:
|
|||||||
line: 行数
|
line: 行数
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
cmd = cmd.format(*args, **kwargs)
|
|
||||||
no_head = cmd.split(" ", 1)[1] if len(cmd.split(" ")) > 1 else ""
|
no_head = cmd.split(" ", 1)[1] if len(cmd.split(" ")) > 1 else ""
|
||||||
try:
|
try:
|
||||||
head, args, kwargs = self.get_args(cmd)
|
head, args, kwargs = self.get_args(cmd)
|
||||||
@ -74,7 +75,7 @@ class LiteyukiFunction:
|
|||||||
|
|
||||||
if head == "var":
|
if head == "var":
|
||||||
# 变量定义
|
# 变量定义
|
||||||
self.var_data.update(kwargs)
|
self.kwargs_data.update(kwargs)
|
||||||
|
|
||||||
elif head == "cmd":
|
elif head == "cmd":
|
||||||
# 在当前计算机上执行命令
|
# 在当前计算机上执行命令
|
||||||
@ -97,7 +98,6 @@ class LiteyukiFunction:
|
|||||||
|
|
||||||
elif head == "nohup":
|
elif head == "nohup":
|
||||||
# 挂起运行
|
# 挂起运行
|
||||||
print("挂起运行")
|
|
||||||
task = asyncio.create_task(self.execute_line(no_head))
|
task = asyncio.create_task(self.execute_line(no_head))
|
||||||
self.sub_tasks.append(task)
|
self.sub_tasks.append(task)
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ class LiteyukiFunction:
|
|||||||
try:
|
try:
|
||||||
value = eval(value)
|
value = eval(value)
|
||||||
except:
|
except:
|
||||||
value = self.var_data.get(value, value)
|
value = self.kwargs_data.get(value, value)
|
||||||
kwargs[key] = value
|
kwargs[key] = value
|
||||||
else:
|
else:
|
||||||
if i == 0:
|
if i == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user