import{_ as s,r as t,o,c as i,b as n,d as e,a as l,e as c}from"./app-CaCnUB7w.js";const p={},r=c(`

轻雪函数

轻雪函数 Liteyuki Function 是轻雪的一个功能,它允许你在轻雪中运行一些自定义的由数据驱动的命令,类似于Minecraft的mcfunction.

函数文件

函数文件放在资源包的functions目录下,文件名以.mcfunction .lyfunction .lyf结尾,例如test.mcfunction,文件内容为一系列的命令,每行一个命令,支持单行注释#(编辑时的语法高亮可采取shell格式),例如:

# 在发信器输出"hello world"
cmd echo hello world

# 如果你想同时输出多行内容可以尝试换行符(Python格式)
cmd echo hello world\\nLiteyuki bot

也支持句末注释,例如:

cmd echo hello world # 输出"hello world"

命令文档

var <var1=value1> [var2=value2] ...  # 定义变量
cmd <command>  # 在设备上执行命令
api <api_name> [var=value...]  # 调用Bot API
function <func_name> # 调用函数,可递归
sleep <time>  # 异步等待,单位s
nohup <command>  # 使用新的task执行命令,即不等待
end # 结束函数关键字,包括子task
await # 等待所有异步任务结束,若函数中启动了其他task,需要在最后调用,否则task对象会被销毁

示例

# 疯狂戳好友
# 使用 /function poke user_id=123456 执行
# 每隔0.2s戳两次,无限戳,会触发最大递归深度限制
# 若要戳20s后停止,则需要删除await,添加sleep 20和end
api friend_poke user_id=user_id
api friend_poke user_id=user_id
sleep 0.2
nohup function poke
await

API

理论上所有基于onebotv11的api都可调用,不同Adapter api也有差别.

`,13),d={href:"https://283375.github.io/onebot_v11_vitepress/api/index.html",target:"_blank",rel:"noopener noreferrer"},u=n("h3",{id:"结束关键字",tabindex:"-1"},[n("a",{class:"header-anchor",href:"#结束关键字"},[n("span",null,[n("strong",null,"结束关键字")])])],-1),m=n("p",null,'由于LiteyukiBot基于异步运行, 所以在编写lyfunction时也要注意异步的调用,避免出现"单线程走到底"的情况是效率提升的关键.',-1),h=n("p",null,[n("code",null,"await"),e(" 异步任务结束关键字,用于结束当前已完成function的执行")],-1),v=n("div",{class:"hint-container warning"},[n("p",{class:"hint-container-title"},"注意"),n("p",null,"但若出现非单function的情况,有一个task任务没有完成而await被执行了,那么当前所有函数包的task都会被截停销毁")],-1);function k(g,f){const a=t("ExternalLinkIcon");return o(),i("div",null,[r,n("p",null,[n("a",d,[e("Onebot v11 API文档"),l(a)])]),u,m,h,v])}const y=s(p,[["render",k],["__file","lyfunc.html.vue"]]),_=JSON.parse('{"path":"/usage/lyfunc.html","title":"轻雪函数","lang":"zh-CN","frontmatter":{"title":"轻雪函数","icon":"code","order":4,"category":"使用指南","tag":["配置"],"description":"轻雪函数 轻雪函数 Liteyuki Function 是轻雪的一个功能,它允许你在轻雪中运行一些自定义的由数据驱动的命令,类似于Minecraft的mcfunction. 函数文件 函数文件放在资源包的functions目录下,文件名以.mcfunction .lyfunction .lyf结尾,例如test.mcfunction,文件内容为一系列的...","head":[["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/usage/lyfunc.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"轻雪函数"}],["meta",{"property":"og:description","content":"轻雪函数 轻雪函数 Liteyuki Function 是轻雪的一个功能,它允许你在轻雪中运行一些自定义的由数据驱动的命令,类似于Minecraft的mcfunction. 函数文件 函数文件放在资源包的functions目录下,文件名以.mcfunction .lyfunction .lyf结尾,例如test.mcfunction,文件内容为一系列的..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-06-16T15:33:58.000Z"}],["meta",{"property":"article:author","content":"远野千束"}],["meta",{"property":"article:tag","content":"配置"}],["meta",{"property":"article:modified_time","content":"2024-06-16T15:33:58.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"轻雪函数\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-06-16T15:33:58.000Z\\",\\"author\\":[{\\"@type\\":\\"Person\\",\\"name\\":\\"远野千束\\",\\"url\\":\\"https://snowykami.me\\"}]}"]]},"headers":[{"level":2,"title":"轻雪函数","slug":"轻雪函数","link":"#轻雪函数","children":[{"level":3,"title":"函数文件","slug":"函数文件","link":"#函数文件","children":[]},{"level":3,"title":"命令文档","slug":"命令文档","link":"#命令文档","children":[]},{"level":3,"title":"API","slug":"api","link":"#api","children":[]},{"level":3,"title":"结束关键字","slug":"结束关键字","link":"#结束关键字","children":[]}]}],"git":{"createdTime":1717168540000,"updatedTime":1718552038000,"contributors":[{"name":"Nanaloveyuki","email":"136328617+MiaoMioLint@users.noreply.github.com","commits":1},{"name":"Nanaloveyuki","email":"miaomiao_159@outlook.com","commits":1},{"name":"snowy","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":1.76,"words":528},"filePathRelative":"usage/lyfunc.md","localizedDate":"2024年5月31日","autoDesc":true}');export{y as comp,_ as data};