app/dev/api/utils.html

95 lines
69 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="zh-Hans" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>liteyuki.utils | 轻雪机器人</title>
<meta name="description" content="一个综合性的机器人应用及管理框架">
<meta name="generator" content="VitePress v1.3.4">
<link rel="preload stylesheet" href="/assets/style.BKWwdMfO.css" as="style">
<script type="module" src="/assets/app.BSaCUHN6.js"></script>
<link rel="preload" href="/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/assets/chunks/theme.7ricsd7T.js">
<link rel="modulepreload" href="/assets/chunks/framework.C4_mTacX.js">
<link rel="modulepreload" href="/assets/dev_api_utils.md.CvLxJfa5.lean.js">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://fonts.font.im/css?family=Cousine:400,400i,700,700i|Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i">
<script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-be658c97 data-v-4be82239><!--[--><!--]--><!--[--><span tabindex="-1" data-v-4a10e730></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-4a10e730> Skip to content </a><!--]--><!----><header class="VPNav" data-v-4be82239 data-v-10d5e81f><div class="VPNavBar has-sidebar top" data-v-10d5e81f data-v-03df6358><div class="wrapper" data-v-03df6358><div class="container" data-v-03df6358><div class="title" data-v-03df6358><div class="VPNavBarTitle has-sidebar" data-v-03df6358 data-v-01425599><a class="title" href="/" data-v-01425599><!--[--><!--]--><!--[--><!--[--><!--[--><img class="VPImage dark logo" src="/liteyuki-dark.svg" alt="LiteyukiBot Logo" data-v-8fba738a><!--]--><!--[--><img class="VPImage light logo" src="/liteyuki.svg" alt="LiteyukiBot Logo" data-v-8fba738a><!--]--><!--]--><!--]--><span data-v-01425599>轻雪机器人</span><!--[--><!--]--></a></div></div><div class="content" data-v-03df6358><div class="content-body" data-v-03df6358><!--[--><!--]--><div class="VPNavBarSearch search" data-v-03df6358><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="打开搜索框"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">搜索文档</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-03df6358 data-v-a0b069c0><span id="main-nav-aria-label" class="visually-hidden" data-v-a0b069c0> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/deploy/install.html" tabindex="0" data-v-a0b069c0 data-v-c1f5da45><!--[--><span data-v-c1f5da45>部署</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/usage/basic.html" tabindex="0" data-v-a0b069c0 data-v-c1f5da45><!--[--><span data-v-c1f5da45>使用</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/store/resource.html" tabindex="0" data-v-a0b069c0 data-v-c1f5da45><!--[--><span data-v-c1f5da45>扩展</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/dev/guide.html" tabindex="0" data-v-a0b069c0 data-v-c1f5da45><!--[--><span data-v-c1f5da45>开发</span><!--]--></a><!--]--><!--]--></nav><div class="VPFlyout VPNavBarTranslations translations" data-v-03df6358 data-v-a0e85ae2 data-v-4e740509><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="语言" data-v-4e740509><span class="text" data-v-4e740509><span class="vpi-languages option-icon" data-v-4e740509></span><!----><span class="vpi-chevron-down text-icon" data-v-4e740509></span></span></button><div class="menu" data-v-4e740509><div class="VPMenu" data-v-4e740509 data-v-4397d6aa><!----><!--[--><!--[--><div class="items" data-v-a0e85ae2><p class="title" data-v-a0e85ae2>简体中文</p><!--[--><div class="VPMenuLink" data-v-a0e85ae2 data-v-90280799><a class="VPLink link" href="/en/dev/api/utils.html" data-v-90280799><!--[-->English<!--]--></a></div><!--]--></div><!--]--><!--]--></div></div></div><div class="VPNavBarAppearance appearance" data-v-03df6358 data-v-0e100a46><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="深色模式" aria-checked="false" data-v-0e100a46 data-v-10656515 data-v-8727337c><span class="check" data-v-8727337c><span class="icon" data-v-8727337c><!--[--><span class="vpi-sun sun" data-v-10656515></span><span class="vpi-moon moon" data-v-10656515></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-03df6358 data-v-ca530fac data-v-b1e9369e><!--[--><a class="VPSocialLink no-icon" href="https://github.com/LiteyukiStudio/LiteyukiBot" aria-label="github" target="_blank" rel="noopener" data-v-b1e9369e data-v-9abc2d2a><span class="vpi-social-github" /></a><a class="VPSocialLink no-icon" href="https
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 判断是否为协程可调用对象</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> call: 可调用对象</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Returns:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bool: 是否为协程可调用对象</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inspect.isroutine(call):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inspect.iscoroutinefunction(call)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inspect.isclass(call):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> False</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> func_ </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> getattr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(call, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;__call__&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">None</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inspect.iscoroutinefunction(func_)</span></span></code></pre></div></details><h3 id="func-run-coroutine-coro-coroutine" tabindex="-1"><em><strong>func</strong></em> <code>run_coroutine(*coro: Coroutine)</code> <a class="header-anchor" href="#func-run-coroutine-coro-coroutine" aria-label="Permalink to &quot;***func*** `run_coroutine(*coro: Coroutine)`&quot;"></a></h3><p><strong>说明</strong>: 运行协程</p><p><strong>参数</strong>:</p><blockquote><ul><li>coro:</li></ul></blockquote><details><summary><b>源代码</b><a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/utils.py#L33" target="_blank">在GitHub上查看</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> run_coroutine</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">coro: Coroutine):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 运行协程</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> coro:</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Returns:</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> try</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> loop </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> asyncio.get_running_loop()</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> loop.is_running():</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> coro:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> asyncio.ensure_future(c)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> coro:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> loop.run_until_complete(c)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> except</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> RuntimeError</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> loop </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> asyncio.new_event_loop()</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> asyncio.set_event_loop(loop)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> loop.run_until_complete(asyncio.gather(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">coro))</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> loop.close()</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> except</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> Exception</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> as</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> e:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> logger.error(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;Exception occurred: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div></details><h3 id="func-run-coroutine-in-thread-coro-coroutine" tabindex="-1"><em><strong>func</strong></em> <code>run_coroutine_in_thread(*coro: Coroutine)</code> <a class="header-anchor" href="#func-run-coroutine-in-thread-coro-coroutine" aria-label="Permalink to &quot;***func*** `run_coroutine_in_thread(*coro: Coroutine)`&quot;"></a></h3><p><strong>说明</strong>: 在新线程中运行协程</p><p><strong>参数</strong>:</p><blockquote><ul><li>coro:</li></ul></blockquote><details><summary><b>源代码</b><a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/utils.py#L66" target="_blank">在GitHub上查看</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> run_coroutine_in_thread</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">coro: Coroutine):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 在新线程中运行协程</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> coro:</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Returns:</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> threading.Thread(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">target</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">run_coroutine, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">args</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">coro, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">daemon</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">).start()</span></span></code></pre></div></details><h3 id="func-path-to-module-name-path-path-str" tabindex="-1"><em><strong>func</strong></em> <code>path_to_module_name(path: Path) -&gt; str</code> <a class="header-anchor" href="#func-path-to-module-name-path-path-str" aria-label="Permalink to &quot;***func*** `path_to_module_name(path: Path) -&gt; str`&quot;"></a></h3><p><strong>说明</strong>: 转换路径为模块名</p><p><strong>参数</strong>:</p><blockquote><ul><li>path: 路径a/b/c/d -&gt; a.b.c.d</li></ul></blockquote><p><strong>返回</strong>: str: 模块名</p><details><summary><b>源代码</b><a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/utils.py#L78" target="_blank">在GitHub上查看</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> path_to_module_name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(path: Path) -&gt; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 转换路径为模块名</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> path: 路径a/b/c/d -&gt; a.b.c.d</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Returns:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> str: 模块名</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rel_path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> path.resolve().relative_to(Path.cwd().resolve())</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rel_path.stem </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;__init__&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;.&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.join(rel_path.parts[:</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">])</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;.&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.join(rel_path.parts[:</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (rel_path.stem,))</span></span></code></pre></div></details><h3 id="func-async-wrapper-func-callable-any-callable-coroutine" tabindex="-1"><em><strong>func</strong></em> <code>async_wrapper(func: Callable[..., Any]) -&gt; Callable[..., Coroutine]</code> <a class="header-anchor" href="#func-async-wrapper-func-callable-any-callable-coroutine" aria-label="Permalink to &quot;***func*** `async_wrapper(func: Callable[..., Any]) -&gt; Callable[..., Coroutine]`&quot;"></a></h3><p><strong>说明</strong>: 异步包装器</p><p><strong>参数</strong>:</p><blockquote><ul><li>func: Sync Callable</li></ul></blockquote><p><strong>返回</strong>: Coroutine: Asynchronous Callable</p><details><summary><b>源代码</b><a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/utils.py#L93" target="_blank">在GitHub上查看</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> async_wrapper</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(func: Callable[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">...</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, Any]) -&gt; Callable[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">...</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, Coroutine]:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 异步包装器</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> func: Sync Callable</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Returns:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Coroutine: Asynchronous Callable</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> async</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> wrapper</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">args, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">**</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kwargs):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> func(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">args, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">**</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kwargs)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> wrapper.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">__signature__</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inspect.signature(func)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> wrapper</span></span></code></pre></div></details></div></div></main><footer class="VPDocFooter" data-v-1b1e6eb6 data-v-bb44dcf3><!--[--><!--]--><div class="edit-info" data-v-bb44dcf3><div class="edit-link" data-v-bb44dcf3><a class="VPLink link vp-external-link-icon no-icon edit-link-button" href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/utils.py" target="_blank" rel="noreferrer" data-v-bb44dcf3><!--[--><span class="vpi-square-pen edit-link-icon" data-v-bb44dcf3></span> 在 GitHub 上编辑此页<!--]--></a></div><!----></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-bb44dcf3><span class="visually-hidden" id="doc-footer-aria-label" data-v-bb44dcf3>Pager</span><div class="pager" data-v-bb44dcf3><a class="VPLink link pager-link prev" href="/dev/api/plugins/plugin_loader/" data-v-bb44dcf3><!--[--><span class="desc" data-v-bb44dcf3>上一页</span><span class="title" data-v-bb44dcf3>liteyuki.plugins.plugin_loader</span><!--]--></a></div><div class="pager" data-v-bb44dcf3><a class="VPLink link pager-link next" href="/dev/api/" data-v-bb44dcf3><!--[--><span class="desc" data-v-bb44dcf3>下一页</span><span class="title" data-v-bb44dcf3>liteyuki API</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-4be82239 data-v-d5f9ff66><div class="container" data-v-d5f9ff66><p class="message" data-v-d5f9ff66>文档由 <a href="https://vitepress.dev/">VitePress</a> 构建 | API引用由 <a href="https://github.com/LiteyukiStudio/litedoc">litedoc</a> 生成</p><p class="copyright" data-v-d5f9ff66>Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"deploy_config.md\":\"BBoJ_SVs\",\"deploy_fandq.md\":\"D3AaSKzf\",\"deploy_install.md\":\"DMcLeaSP\",\"dev_api_bot_index.md\":\"CO6VsP4-\",\"dev_api_bot_lifespan.md\":\"Brz5v0DB\",\"dev_api_comm_channel.md\":\"DqKQ48r8\",\"dev_api_comm_event.md\":\"CKj2UKdm\",\"dev_api_comm_index.md\":\"uufyI1S9\",\"dev_api_comm_rpc.md\":\"DZB2wFct\",\"dev_api_comm_socks_channel.md\":\"D_LOQMVo\",\"dev_api_comm_storage.md\":\"ByeStviG\",\"dev_api_config.md\":\"B6-1F5M4\",\"dev_api_core_index.md\":\"SSSl_XRw\",\"dev_api_core_manager.md\":\"CUxE2_uH\",\"dev_api_dev_index.md\":\"Ckrx8rJ6\",\"dev_api_dev_observer.md\":\"CK2VQ1dm\",\"dev_api_dev_plugin.md\":\"CQmBgdvS\",\"dev_api_exception.md\":\"CHNyxSqL\",\"dev_api_index.md\":\"D5E434zv\",\"dev_api_log.md\":\"BTzz4w7t\",\"dev_api_message_event.md\":\"ClMwOOd3\",\"dev_api_message_index.md\":\"CCG9t-zb\",\"dev_api_message_matcher.md\":\"C-ROK-bX\",\"dev_api_message_on.md\":\"BL6JkrM3\",\"dev_api_message_rule.md\":\"Cl4Pbacm\",\"dev_api_message_session.md\":\"CC5IECPx\",\"dev_api_mkdoc.md\":\"D83YPFf0\",\"dev_api_plugin_index.md\":\"s_ae6nFU\",\"dev_api_plugin_load.md\":\"Dr9bABNT\",\"dev_api_plugin_manager.md\":\"rRp7jB1O\",\"dev_api_plugin_model.md\":\"BDcYOOls\",\"dev_api_plugins_index.md\":\"CSspw-A7\",\"dev_api_plugins_liteecho.md\":\"B8fCIJFA\",\"dev_api_plugins_plugin_loader_index.md\":\"BUTV_7BY\",\"dev_api_utils.md\":\"CvLxJfa5\",\"dev_comm.md\":\"cMJIV6AK\",\"dev_guide.md\":\"CQPpARnL\",\"dev_lyfunc.md\":\"D4LU5X67\",\"dev_plugin.md\":\"phZolwS6\",\"dev_resource.md\":\"CiEukBtC\",\"en_deploy_config.md\":\"DdMT5vqs\",\"en_deploy_fandq.md\":\"BKc7kj27\",\"en_deploy_install.md\":\"C00Sx2cS\",\"en_dev_api_bot_index.md\":\"BKlim-xP\",\"en_dev_api_bot_lifespan.md\":\"XWy-18_r\",\"en_dev_api_comm_channel.md\":\"BdNiQzBm\",\"en_dev_api_comm_event.md\":\"C-rHpKa9\",\"en_dev_api_comm_index.md\":\"Dg6nSUT4\",\"en_dev_api_comm_rpc.md\":\"Dot66ZOf\",\"en_dev_api_comm_socks_channel.md\":\"B-Ph112g\",\"en_dev_api_comm_storage.md\":\"Cmhtt_I0\",\"en_dev_api_config.md\":\"BeBusNL-\",\"en_dev_api_core_index.md\":\"CJrGoxVS\",\"en_dev_api_core_manager.md\":\"C-smFgZK\",\"en_dev_api_dev_index.md\":\"IWiJmN2l\",\"en_dev_api_dev_observer.md\":\"D-WCNidu\",\"en_dev_api_dev_plugin.md\":\"DKRyz1o4\",\"en_dev_api_exception.md\":\"DfRyv62x\",\"en_dev_api_index.md\":\"Clr1QQbT\",\"en_dev_api_log.md\":\"CDk5dyBa\",\"en_dev_api_message_event.md\":\"DEcIQdiK\",\"en_dev_api_message_index.md\":\"Cy6O48O3\",\"en_dev_api_message_matcher.md\":\"D8JXS8zE\",\"en_dev_api_message_on.md\":\"cvWZYehF\",\"en_dev_api_message_rule.md\":\"Gu_H8fye\",\"en_dev_api_message_session.md\":\"qPDLFiy0\",\"en_dev_api_mkdoc.md\":\"DWIWl3U9\",\"en_dev_api_plugin_index.md\":\"B1_Dcoud\",\"en_dev_api_plugin_load.md\":\"D4Kj7cH5\",\"en_dev_api_plugin_manager.md\":\"DwpN_WJP\",\"en_dev_api_plugin_model.md\":\"DJi_Hqis\",\"en_dev_api_plugins_index.md\":\"BP3-0fiD\",\"en_dev_api_plugins_liteecho.md\":\"qdho9nqc\",\"en_dev_api_plugins_plugin_loader_index.md\":\"CYeKyOFO\",\"en_dev_api_utils.md\":\"Cn9x0Itt\",\"en_dev_comm.md\":\"DWySVBZ2\",\"en_dev_guide.md\":\"CHoOI0HI\",\"en_dev_lyfunc.md\":\"BhYjNK3N\",\"en_dev_plugin.md\":\"CKzO3RVR\",\"en_dev_resource.md\":\"Q8AwzAyN\",\"en_index.md\":\"DS37TlOH\",\"en_store_plugin.md\":\"C0UyBVv2\",\"en_store_resource.md\":\"Ci-LBCav\",\"en_usage_agreement.md\":\"vFfahjeR\",\"en_usage_basic.md\":\"DVpsBy5w\",\"en_usage_extra.md\":\"DU-WQhbO\",\"index.md\":\"Dl11pd1E\",\"store_plugin.md\":\"BhQadjel\",\"store_resource.md\":\"CgUrr2wJ\",\"usage_agreement.md\":\"BYijSUyJ\",\"usage_basic.md\":\"CS9J19pD\",\"usage_extra.md\":\"CPLcG44C\"}");function deserializeFunctions(r){return Array.isArray(r)?r.map(deserializeFunctions):typeof r=="object"&&r!==null?Object.keys(r).reduce((t,n)=>(t[n]=deserializeFunctions(r[n]),t),{}):typeof r=="string"&&r.startsWith("_vp-fn_")?new Function(`return ${r.slice(7)}`)():r};window.__VP_SITE_DATA__=deserializeFunctions(JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"VitePress\",\"description\":\"A VitePress site\",\"base\
</body>
</html>