添加开发文档和 API 文档的初始结构;更新 .gitignore 以排除生成的文档目录

This commit is contained in:
2024-12-14 18:49:06 +08:00
parent 8c06f1336e
commit 8530e2e34a
66 changed files with 5224 additions and 7 deletions

View File

@ -0,0 +1,50 @@
---
title: index
collapsed: true
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_bangumi`
---
### ***async func*** `fetch_calendar()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_bangumi/__init__.py#L6' target='_blank'>在GitHub上查看</a></summary>
```python
async def fetch_calendar():
url = 'https://api.bgm.tv/calendar'
headers = {'User-Agent': 'LiteyukiStudio/nonebot-plugin-marshoai (https://github.com/LiteyukiStudio/nonebot-plugin-marshoai)'}
async with httpx.AsyncClient() as client:
response = await client.get(url, headers=headers)
return response.json()
```
</details>
---
### ***async func*** `get_bangumi_news()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_bangumi/__init__.py#L17' target='_blank'>在GitHub上查看</a></summary>
```python
async def get_bangumi_news():
result = await fetch_calendar()
info = ''
try:
for i in result:
weekday = i['weekday']['cn']
info += f'{weekday}:'
items = i['items']
for item in items:
name = item['name_cn']
info += f'《{name}》'
info += '\n'
return info
except Exception as e:
traceback.print_exc()
return ''
```
</details>

View File

@ -0,0 +1,52 @@
---
title: index
collapsed: true
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_basic`
---
### ***async func*** `get_weather(location: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_basic/__init__.py#L6' target='_blank'>在GitHub上查看</a></summary>
```python
async def get_weather(location: str):
return f'{location}的温度是114514℃。'
```
</details>
---
### ***async func*** `get_current_env()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_basic/__init__.py#L10' target='_blank'>在GitHub上查看</a></summary>
```python
async def get_current_env():
ver = os.popen('uname -a').read()
return str(ver)
```
</details>
---
### ***async func*** `get_current_time()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_basic/__init__.py#L15' target='_blank'>在GitHub上查看</a></summary>
```python
async def get_current_time():
current_time = DateTime.now().strftime('%Y.%m.%d %H:%M:%S')
current_weekday = DateTime.now().weekday()
weekdays = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
current_weekday_name = weekdays[current_weekday]
current_lunar_date = DateTime.now().to_lunar().date_hanzify()[5:]
time_prompt = f'现在的时间是{current_time}{current_weekday_name},农历{current_lunar_date}。'
return time_prompt
```
</details>

View File

@ -0,0 +1,110 @@
---
title: index
collapsed: true
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_megakits`
---
### ***async func*** `twisuki()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py#L5' target='_blank'>在GitHub上查看</a></summary>
```python
async def twisuki():
return str(await mk_info.twisuki())
```
</details>
---
### ***async func*** `megakits()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py#L10' target='_blank'>在GitHub上查看</a></summary>
```python
async def megakits():
return str(await mk_info.megakits())
```
</details>
---
### ***async func*** `random_turntable(upper: int, lower: int = 0)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py#L15' target='_blank'>在GitHub上查看</a></summary>
```python
async def random_turntable(upper: int, lower: int=0):
return str(await mk_common.random_turntable(upper, lower))
```
</details>
---
### ***async func*** `number_calc(a: str, b: str, op: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py#L20' target='_blank'>在GitHub上查看</a></summary>
```python
async def number_calc(a: str, b: str, op: str):
return str(await mk_common.number_calc(a, b, op))
```
</details>
---
### ***async func*** `morse_encrypt(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py#L25' target='_blank'>在GitHub上查看</a></summary>
```python
async def morse_encrypt(msg: str):
return str(await mk_morse_code.morse_encrypt(msg))
```
</details>
---
### ***async func*** `morse_decrypt(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py#L30' target='_blank'>在GitHub上查看</a></summary>
```python
async def morse_decrypt(msg: str):
return str(await mk_morse_code.morse_decrypt(msg))
```
</details>
---
### ***async func*** `nya_encode(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py#L35' target='_blank'>在GitHub上查看</a></summary>
```python
async def nya_encode(msg: str):
return str(await mk_nya_code.nya_encode(msg))
```
</details>
---
### ***async func*** `nya_decode(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/__init__.py#L40' target='_blank'>在GitHub上查看</a></summary>
```python
async def nya_decode(msg: str):
return str(await mk_nya_code.nya_decode(msg))
```
</details>

View File

@ -0,0 +1,65 @@
---
title: mk_common
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_megakits.mk_common`
---
### ***async func*** `random_turntable(upper: int, lower: int)`
**说明**: Random Turntable
**参数**:
> - upper (int): _description_
> - lower (int): _description_
**返回**: _type_: _description_
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_common.py#L4' target='_blank'>在GitHub上查看</a></summary>
```python
async def random_turntable(upper: int, lower: int):
return random.randint(lower, upper)
```
</details>
---
### ***async func*** `number_calc(a: str, b: str, op: str) -> str`
**说明**: Number Calc
**参数**:
> - a (str): _description_
> - b (str): _description_
> - op (str): _description_
**返回**: str: _description_
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_common.py#L17' target='_blank'>在GitHub上查看</a></summary>
```python
async def number_calc(a: str, b: str, op: str) -> str:
a, b = (float(a), float(b))
match op:
case '+':
return str(a + b)
case '-':
return str(a - b)
case '*':
return str(a * b)
case '/':
return str(a / b)
case '**':
return str(a ** b)
case '%':
return str(a % b)
case _:
return '未知运算符'
```
</details>

View File

@ -0,0 +1,31 @@
---
title: mk_info
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_megakits.mk_info`
---
### ***async func*** `twisuki()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_info.py#L2' target='_blank'>在GitHub上查看</a></summary>
```python
async def twisuki():
return 'Twiuski(苏阳)是megakits插件作者, Github : "https://github.com/Twisuki"'
```
</details>
---
### ***async func*** `megakits()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_info.py#L7' target='_blank'>在GitHub上查看</a></summary>
```python
async def megakits():
return 'MegaKits插件是一个功能混杂的MarshoAI插件, 由Twisuki(Github : "https://github.com/Twisuki")开发, 插件仓库 : "https://github.com/LiteyukiStudio/marsho-toolsets/tree/main/Twisuki/marshoai-megakits"'
```
</details>

View File

@ -0,0 +1,46 @@
---
title: mk_morse_code
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_megakits.mk_morse_code`
---
### ***async func*** `morse_encrypt(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_morse_code.py#L62' target='_blank'>在GitHub上查看</a></summary>
```python
async def morse_encrypt(msg: str):
result = ''
msg = msg.upper()
for char in msg:
if char in MorseEncode:
result += MorseEncode[char]
else:
result += '..--..'
result += ' '
return result
```
</details>
---
### ***async func*** `morse_decrypt(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_morse_code.py#L76' target='_blank'>在GitHub上查看</a></summary>
```python
async def morse_decrypt(msg: str):
result = ''
msg_arr = msg.split()
for char in msg_arr:
if char in MorseDecode:
result += MorseDecode[char]
else:
result += '?'
return result
```
</details>

View File

@ -0,0 +1,60 @@
---
title: mk_nya_code
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_megakits.mk_nya_code`
---
### ***async func*** `nya_encode(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_nya_code.py#L25' target='_blank'>在GitHub上查看</a></summary>
```python
async def nya_encode(msg: str):
msg_b64str = base64.b64encode(msg.encode()).decode().replace('=', '')
msg_nyastr = ''.join((NyaCodeEncode[base64_char] for base64_char in msg_b64str))
result = ''
for char in msg_nyastr:
if char == '呜' and random.random() < 0.5:
result += '!'
if random.random() < 0.25:
result += random.choice(NyaCodeSpecialCharset) + char
else:
result += char
return result
```
</details>
---
### ***async func*** `nya_decode(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_megakits/mk_nya_code.py#L41' target='_blank'>在GitHub上查看</a></summary>
```python
async def nya_decode(msg: str):
msg = msg.replace('唔', '').replace('!', '').replace('.', '')
msg_nyastr = []
i = 0
if len(msg) % 3 != 0:
return '这句话不是正确的猫语'
while i < len(msg):
nyachar = msg[i:i + 3]
try:
if all((char in NyaCodeCharset for char in nyachar)):
msg_nyastr.append(nyachar)
i += 3
except Exception:
return '这句话不是正确的猫语'
msg_b64str = ''.join((NyaCodeDecode[nya_char] for nya_char in msg_nyastr))
msg_b64str += '=' * (4 - len(msg_b64str) % 4)
try:
result = base64.b64decode(msg_b64str.encode()).decode()
except Exception:
return '翻译失败'
return result
```
</details>

View File

@ -0,0 +1,45 @@
---
title: index
collapsed: true
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_meogirl`
---
### ***async func*** `meogirl()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_meogirl/__init__.py#L5' target='_blank'>在GitHub上查看</a></summary>
```python
async def meogirl():
return mg_info.meogirl()
```
</details>
---
### ***async func*** `search(msg: str, num: int = 3)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_meogirl/__init__.py#L10' target='_blank'>在GitHub上查看</a></summary>
```python
async def search(msg: str, num: int=3):
return str(await mg_search.search(msg, num))
```
</details>
---
### ***async func*** `introduce(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_meogirl/__init__.py#L15' target='_blank'>在GitHub上查看</a></summary>
```python
async def introduce(msg: str):
return str(await mg_introduce.introduce(msg))
```
</details>

View File

@ -0,0 +1,18 @@
---
title: mg_info
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_meogirl.mg_info`
---
### ***func*** `meogirl()`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_info.py#L2' target='_blank'>在GitHub上查看</a></summary>
```python
def meogirl():
return 'Meogirl指的是"萌娘百科"(https://zh.moegirl.org.cn/ , 简称"萌百"), 是一个"万物皆可萌的百科全书!"; 同时, MarshoTools也配有"Meogirl"插件, 可调用萌百的api'
```
</details>

View File

@ -0,0 +1,76 @@
---
title: mg_introduce
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_meogirl.mg_introduce`
---
### ***async func*** `get_async_data(url)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_introduce.py#L13' target='_blank'>在GitHub上查看</a></summary>
```python
async def get_async_data(url):
async with httpx.AsyncClient(timeout=None) as client:
return await client.get(url, headers=headers)
```
</details>
---
### ***async func*** `introduce(msg: str)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_introduce.py#L18' target='_blank'>在GitHub上查看</a></summary>
```python
async def introduce(msg: str):
logger.info(f'介绍 : "{msg}" ...')
result = ''
url = 'https://mzh.moegirl.org.cn/' + urllib.parse.quote_plus(msg)
response = await get_async_data(url)
logger.success(f'连接"{url}"完成, 状态码 : {response.status_code}')
soup = BeautifulSoup(response.text, 'html.parser')
if response.status_code == 200:
'\n 萌娘百科页面结构\n div#mw-content-text\n └── div#404search # 空白页面出现\n └── div.mw-parser-output # 正常页面\n └── div, p, table ... # 大量的解释项\n '
result += msg + '\n'
img = soup.find('img', class_='infobox-image')
if img:
result += f'![ {msg} ]( {img['src']} ) \n'
div = soup.find('div', class_='mw-parser-output')
if div:
p_tags = div.find_all('p')
num = 0
for p_tag in p_tags:
p = str(p_tag)
p = re.sub('<script.*?</script>|<style.*?</style>', '', p, flags=re.DOTALL)
p = re.sub('<.*?>', '', p, flags=re.DOTALL)
p = re.sub('\\[.*?]', '', p, flags=re.DOTALL)
if p != '':
result += str(p)
num += 1
if num >= 20:
break
return result
elif response.status_code == 404:
logger.info(f'未找到"{msg}", 进行搜索')
from . import mg_search
context = await mg_search.search(msg, 1)
keyword = re.search('.*?\\n', context, flags=re.DOTALL).group()[:-1]
logger.success(f'搜索完成, 打开"{keyword}"')
return await introduce(keyword)
elif response.status_code == 301:
return f'未找到{msg}'
else:
logger.error(f'网络错误, 状态码 : {response.status_code}')
return f'网络错误, 状态码 : {response.status_code}'
```
</details>
### var `keyword`
- **说明**: type: ignore
- **默认值**: `re.search('.*?\\n', context, flags=re.DOTALL).group()[:-1]`

View File

@ -0,0 +1,73 @@
---
title: mg_search
---
# **模块** `nonebot_plugin_marshoai.tools.marshoai_meogirl.mg_search`
---
### ***async func*** `get_async_data(url)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_search.py#L12' target='_blank'>在GitHub上查看</a></summary>
```python
async def get_async_data(url):
async with httpx.AsyncClient(timeout=None) as client:
return await client.get(url, headers=headers)
```
</details>
---
### ***async func*** `search(msg: str, num: int)`
<details>
<summary> <b>源代码</b><a href='https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/tools/marshoai_meogirl/mg_search.py#L17' target='_blank'>在GitHub上查看</a></summary>
```python
async def search(msg: str, num: int):
logger.info(f'搜索 : "{msg}" ...')
result = ''
url = 'https://mzh.moegirl.org.cn/index.php?search=' + urllib.parse.quote_plus(msg)
response = await get_async_data(url)
logger.success(f'连接"{url}"完成, 状态码 : {response.status_code}')
if response.status_code == 200:
'\n 萌娘百科搜索页面结构\n div.searchresults\n └── p ...\n └── ul.mw-search-results # 若无, 证明无搜索结果\n └── li # 一个搜索结果\n └── div.mw-search-result-heading > a # 标题\n └── div.mw-searchresult # 内容\n └── div.mw-search-result-data\n └── li ...\n └── li ...\n '
soup = BeautifulSoup(response.text, 'html.parser')
ul_tag = soup.find('ul', class_='mw-search-results')
if ul_tag:
li_tags = ul_tag.find_all('li')
for li_tag in li_tags:
div_heading = li_tag.find('div', class_='mw-search-result-heading')
if div_heading:
a_tag = div_heading.find('a')
result += a_tag['title'] + '\n'
logger.info(f'搜索到 : "{a_tag['title']}"')
div_result = li_tag.find('div', class_='searchresult')
if div_result:
content = str(div_result).replace('<div class="searchresult">', '').replace('</div>', '')
content = content.replace('<span class="searchmatch">', '').replace('</span>', '')
result += content + '\n'
num -= 1
if num == 0:
break
return result
else:
logger.info('无结果')
return '无结果'
elif response.status_code == 302:
logger.info(f'"{msg}"已被重定向至"{response.headers.get('location')}"')
from . import mg_introduce
return await mg_introduce.introduce(msg)
else:
logger.error(f'网络错误, 状态码 : {response.status_code}')
return f'网络错误, 状态码 : {response.status_code}'
```
</details>
### var `soup`
- **说明**:
- **默认值**: `BeautifulSoup(response.text, 'html.parser')`