Skip to content

Commit

Permalink
⬆️ 0.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed May 21, 2023
1 parent 76cac32 commit 22e4ff7
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 65 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ git clone https://github.com/RF-Tar-Railt/RaianBot.git

**mirai部分**
1. 确保安装并配置好了`java`环境, 推荐`java17``openj9`
2. 解压缩`mcl.zip`, 或前往[`mirai-console-loader`](https://github.com/iTXTech/mirai-console-loader)下载mcl
, 并在[`mirai-api-http`](https://github.com/project-mirai/mirai-api-http/releases)处下载mirai-api-http.jar(当前bot使用版本为2.6.2), 然后放入`.mcl/plugins/`
3. 下载 [`mirai-login-solver-sakura`](https://github.com/KasukuSakura/mirai-login-solver-sakura),放入`.mcl/plugins/`
2. 前往[`mirai-console-loader`](https://github.com/iTXTech/mirai-console-loader)下载 mcl, 并使用 `mcl -u` 命令更新 `mirai`
, 并在[`mirai-api-http`](https://github.com/project-mirai/mirai-api-http/releases)处下载mirai-api-http.jar(当前bot使用版本为2.9.1), 然后放入`.mcl/plugins/`
3. 下载 [`mirai-console-dev-qrlogin`](https://github.com/MrXiaoM/mirai-console-dev-qrlogin),放入`.mcl/plugins/`

**bot部分**
1. 安装`python`环境,至少要求`python 3.8`及以上版本
Expand All @@ -132,8 +132,8 @@ pip install -r requirements.txt
1. 先运行一遍mcl, 以自动生成配置文件, 确认生成后关闭mcl
2. 前往`mcl/config/net.mamoe.mirai-api-http`下, 打开`setting.yml`文件
3. 修改其中的`verifyKey`, 适当修改`adapterSettings`下的`host``port`
4. 前往`mcl/config/Console`下, 打开`AutoLogin.yml`文件
5. 按提示修改其中的`account``password`
~~4. 前往`mcl/config/Console`下, 打开`AutoLogin.yml`文件~~
~~5. 按提示修改其中的`account``password`~~

**bot部分**
1. bot 的初始配置位于 `./config/`
Expand All @@ -146,7 +146,8 @@ pip install -r requirements.txt

**mirai部分**
1.`mcl`文件夹下双击运行`mcl.cmd`文件
2. 若提示弹窗验证, 请按以下方法操作: [链接](https://docs.mirai.mamoe.net/mirai-login-solver-selenium)
2. 在命令框内输入`qrlogin <bot账号>` (如 "qrlogin 114514"), 然后扫描弹出的二维码
~~2. 若提示弹窗验证, 请按以下方法操作: [链接](https://docs.mirai.mamoe.net/mirai-login-solver-selenium)~~
3. 命令框内出现正常对话信息则代表登录成功

**bot部分**
Expand Down
3 changes: 1 addition & 2 deletions app/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from graia.broadcast.interfaces.dispatcher import DispatcherInterface
from graia.saya import Saya
from graia.scheduler import GraiaScheduler
from graia.scheduler.service import SchedulerService
from graiax.fastapi import FastAPIBehaviour, FastAPIService
from graiax.playwright import PlaywrightService
from launart import ExportInterface, Service, Launart
Expand Down Expand Up @@ -198,7 +197,7 @@ def launch(debug_log: bool = True):
manager.add_service(AlconnaGraiaService(AlconnaAriadneAdapter, enable_cache=True, cache_dir=config.cache_dir))
manager.add_service(FastAPIService(fastapi))
manager.add_service(UvicornService(config.api.host, config.api.port))
manager.add_service(SchedulerService(it(GraiaScheduler)))
# manager.add_service(SchedulerService(it(GraiaScheduler)))
manager.add_service(bot_service := RaianBotService(config))
bcc.prelude_dispatchers.append(RaianBotDispatcher(bot_service))
Ariadne.config(launch_manager=manager, default_account=config.default_account)
Expand Down
11 changes: 10 additions & 1 deletion app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ def exclusive(func: T_Callable) -> T_Callable:

async def send_handler(t: str, output: str):
# length = (output.count("\n") + 5) * 16
if t != "help":
if t == "shortcut":
return MessageChain(output)
if t == "completion":
output = (
output.replace("\n\n", "\n")
.replace("&lt;", "<")
.replace("&gt;", ">")
.replace("&#123;", "{")
.replace("&#125;", "}")
)
return MessageChain(output)
if not output.startswith("#"):
output = f"# {output}"
Expand Down
46 changes: 23 additions & 23 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions plugins/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
from datetime import datetime
from io import BytesIO
from pathlib import Path
from typing import Optional
from typing import Optional, Union

import ujson
from app import RaianBotInterface, RaianBotService, Sender, Target, exclusive, record, accessable
from arclet.alconna import command_manager
from arclet.alconna.graia import endswith, startswith, success_record
from arclet.alconna.graia import endswith, startswith
from arclet.alconna.graia.service import AlconnaGraiaInterface
from arclet.alconna.graia.dispatcher import result_cache
from arclet.alconna.ariadne import AlconnaAriadneAdapter
from graia.ariadne.app import Ariadne
from graia.ariadne.event.message import FriendMessage, GroupMessage
from graia.ariadne.message.chain import MessageChain
Expand Down Expand Up @@ -151,13 +154,22 @@ async def random_ai(app: Ariadne, sender: Sender, target: Target, msg: str, **kw
@priority(20)
@exclusive
@accessable
async def smatch(app: Ariadne, target: Target, sender: Sender, message: MessageChain):
async def smatch(
app: Ariadne,
target: Target,
sender: Sender,
message: MessageChain,
alcif: AlconnaGraiaInterface,
event: Union[GroupMessage, FriendMessage],
):
"""依据语料进行匹配回复"""
cmds = [i.name for i in command_manager.get_commands()]
if msg := str(message.include(Plain)).strip(" +"):
if len(success_record):
success_record.clear()
raise PropagationCancelled
adapter: AlconnaAriadneAdapter = alcif.adapter
source = adapter.source_id(event)
for alc, cache in result_cache.items():
if source in cache and ((res := cache[source].result()) and res.result.matched):
raise PropagationCancelled
for n in cmds:
if re.search(f".*{n}.*", msg):
raise PropagationCancelled
Expand Down
3 changes: 2 additions & 1 deletion plugins/guess_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ async def waiter(waiter_sender: Sender, message: MessageChain):
current_bot.data.cache["$guess"].remove(id_)
return await app.send_message(
sender,
f"{'' if isinstance(sender, Friend) else f'{sender.name}的'}游戏已结束!\n答案为{ans.select}",
f"{'' if isinstance(sender, Friend) else f'{sender.name}的'}游戏已结束!" +
f"\n答案为{ans.select}" if ans else ""
)
try:
if simple.result:
Expand Down
6 changes: 3 additions & 3 deletions plugins/img_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ async def waiter1(app1: Ariadne, waiter1_sender: Sender, waiter1_target: Target,
image_url = img.result
else:
waite = await app.send_message(sender, MessageChain("请发送图片以继续,发送取消可终止搜图"))
image_url = await FunctionWaiter(waiter1, [GroupMessage, FriendMessage]).wait(20, "None")
if not image_url:
image_url = await FunctionWaiter(waiter1, [GroupMessage, FriendMessage]).wait(20, None)
if image_url is False:
return await app.send_message(sender, MessageChain("已取消"))
if image_url == "None":
if image_url is None:
return await app.send_message(sender, MessageChain("等待超时"), quote=waite.id)
await app.send_message(sender, MessageChain("正在搜索,请稍后"), quote=source.id)
running.set()
Expand Down
12 changes: 3 additions & 9 deletions plugins/nudge.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,12 @@ async def draw(
async def draw(app: Ariadne, event: NudgeEvent, bot: RaianBotInterface):
if event.supplicant in bot.base_config.bots or event.target != bot.config.account:
return
async with cd.trigger(event.group_id or event.friend_id, int) as res:
async with cd.trigger(event.subject.id, int) as res:
if not res[1]:
if event.group_id:
return await app.send_group_message(event.group_id, "戳太快了!")
else:
return await app.send_friend_message(event.friend_id, "戳太快了!")
return await app.send_message(event.subject, "戳太快了!")
async with app.service.client_session.get(
f"https://q1.qlogo.cn/g?b=qq&nk={event.supplicant}&s=640"
) as resp:
data = await resp.read()
image = pet.generate(data)
if event.group_id:
return await app.send_group_message(event.group_id, MessageChain(Image(data_bytes=image.getvalue())))
elif event.friend_id:
return await app.send_friend_message(event.friend_id, MessageChain(Image(data_bytes=image.getvalue())))
return await app.send_message(event.subject, MessageChain(Image(data_bytes=image.getvalue())))
6 changes: 3 additions & 3 deletions plugins/t2i.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)


@alcommand(m2i, comp_session={})
@alcommand(m2i)
@record("t2i")
@assign("mode", "chain", True)
@exclusive
Expand Down Expand Up @@ -54,7 +54,7 @@ async def chain(app: Ariadne, sender: Sender, message: MessageChain, width: Matc
)


@alcommand(m2i, comp_session={})
@alcommand(m2i)
@record("t2i")
@assign("mode", "html")
@exclusive
Expand All @@ -74,7 +74,7 @@ async def html(app: Ariadne, sender: Sender, message: MessageChain, width: Match
)


@alcommand(m2i, comp_session={})
@alcommand(m2i)
@record("t2i")
@assign("mode", "md")
@exclusive
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[project]
name = "raian-bot"
version = "0.21.2"
version = "0.21.3"
description = "simple qq bot bases on Araidne and Alconna"
authors = [
{name = "RF-Tar-Railt", email = "rf_tar_railt@qq.com"},
]
dependencies = [
"arclet-alconna<2.0.0, >=1.7.6",
"arclet-alconna-graia<1.0.0, >=0.13.2",
"arclet-alconna-ariadne<1.0.0, >=0.13.2",
"arclet-alconna-graia<1.0.0, >=0.13.3",
"arclet-alconna-ariadne<1.0.0, >=0.13.3",
"arclet-alconna-tools>=0.6.0",
"graia-ariadne<0.11.0, >=0.10.3",
"graia-ariadne<0.12.0, >=0.11.5",
"graia-amnesia>=0.6.0",
"graia-broadcast>=0.19.2",
"graia-saya>=0.0.16",
"graia-scheduler>=0.1.4",
"graia-scheduler==0.0.10",
"unwind~=0.4.0",
"Pillow>=9.0.1",
"aiohttp~=3.8.1",
Expand Down
Loading

0 comments on commit 22e4ff7

Please sign in to comment.