Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions examples/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ port = 8080
url = "/cqhttp/ws"
api_timeout = 100

[adapter.mirai]
adapter_type = "reverse-ws"
verify_key = "1234567890"
qq = 123456
api_timeout = 100
[adapter.telegram]
bot_token = "YOUR_BOT_TOKEN_HERE"
File renamed without changes.
18 changes: 18 additions & 0 deletions examples/plugins/count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Any, override

from alicebot import MessageEvent, Plugin


class Count(Plugin[MessageEvent[Any], int | None]):
@override
async def handle(self) -> None:
if self.state is None:
self.state = 0
self.state += 1
await self.event.reply(f"count: {self.state}")

@override
async def rule(self) -> bool:
if not isinstance(self.event, MessageEvent):
return False
return self.event.get_plain_text() == "count"
16 changes: 0 additions & 16 deletions examples/plugins/count_cqhttp.py

This file was deleted.

15 changes: 15 additions & 0 deletions examples/plugins/echo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Any, override

from alicebot import MessageEvent, Plugin


class Echo(Plugin[MessageEvent[Any]]):
@override
async def handle(self) -> None:
await self.event.reply(self.event.get_plain_text().replace("echo ", ""))

@override
async def rule(self) -> bool:
if not isinstance(self.event, MessageEvent):
return False
return self.event.get_plain_text().startswith("echo ")
13 changes: 0 additions & 13 deletions examples/plugins/echo_cqhttp.py

This file was deleted.

14 changes: 8 additions & 6 deletions examples/plugins/global_state_test1.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from alicebot import Plugin
from typing import Any, override

from alicebot import MessageEvent, Plugin

class GlobalStateTest1(Plugin):

class GlobalStateTest1(Plugin[MessageEvent[Any]]):
@override
async def handle(self) -> None:
if self.bot.global_state.get("count") is None:
self.bot.global_state["count"] = 0
self.bot.global_state["count"] += 1
await self.event.reply(f"add: {self.bot.global_state['count']}")

@override
async def rule(self) -> bool:
if self.event.adapter.name != "cqhttp":
return False
if self.event.type != "message":
if not isinstance(self.event, MessageEvent):
return False
return self.event.message.get_plain_text() == "add"
return self.event.get_plain_text() == "add"
14 changes: 8 additions & 6 deletions examples/plugins/global_state_test2.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from alicebot import Plugin
from typing import Any, override

from alicebot import MessageEvent, Plugin

class GlobalStateTest2(Plugin):

class GlobalStateTest2(Plugin[MessageEvent[Any]]):
@override
async def handle(self) -> None:
if self.bot.global_state.get("count") is None:
self.bot.global_state["count"] = 0
self.bot.global_state["count"] -= 1
await self.event.reply(f"sub: {self.bot.global_state['count']}")

@override
async def rule(self) -> bool:
if self.event.adapter.name != "cqhttp":
return False
if self.event.type != "message":
if not isinstance(self.event, MessageEvent):
return False
return self.event.message.get_plain_text() == "sub"
return self.event.get_plain_text() == "sub"
15 changes: 15 additions & 0 deletions examples/plugins/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Any, override

from alicebot import MessageEvent, Plugin


class Hallo(Plugin[MessageEvent[Any]]):
@override
async def handle(self) -> None:
await self.event.reply("Hello, Alice!")

@override
async def rule(self) -> bool:
if not isinstance(self.event, MessageEvent):
return False
return self.event.get_plain_text().lower() == "hello"
13 changes: 0 additions & 13 deletions examples/plugins/hello_cqhttp.py

This file was deleted.

11 changes: 0 additions & 11 deletions examples/plugins/hello_dingtalk.py

This file was deleted.

13 changes: 0 additions & 13 deletions examples/plugins/hello_mirai.py

This file was deleted.

16 changes: 16 additions & 0 deletions examples/plugins/reload_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import Any, override

from alicebot import MessageEvent, Plugin


class ReloadPlugin(Plugin[MessageEvent[Any]]):
@override
async def handle(self) -> None:
self.bot.reload_plugins()
await self.event.reply("\n".join(map(repr, self.bot.plugins)))

@override
async def rule(self) -> bool:
if not isinstance(self.event, MessageEvent):
return False
return self.event.get_plain_text() == "reload"
14 changes: 0 additions & 14 deletions examples/plugins/reload_plugin_cqhttp.py

This file was deleted.

14 changes: 8 additions & 6 deletions examples/plugins/restart_cqhttp.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from alicebot import Plugin
from typing import Any, override

from alicebot import MessageEvent, Plugin

class Restart(Plugin):

class Restart(Plugin[MessageEvent[Any]]):
@override
async def handle(self) -> None:
self.bot.restart()

@override
async def rule(self) -> bool:
if self.event.adapter.name != "cqhttp":
return False
if self.event.type != "message":
if not isinstance(self.event, MessageEvent):
return False
return self.event.message.get_plain_text() == "restart"
return self.event.get_plain_text() == "restart"
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from typing import override

from alicebot import Plugin
from alicebot.adapter.apscheduler.event import APSchedulerEvent


class Schedule(Plugin):
class Schedule(Plugin[APSchedulerEvent]):
__schedule__ = True
trigger = "interval"
trigger_args = {"seconds": 10} # noqa: RUF012

@override
async def handle(self) -> None:
print(self.event.type, self.event.adapter)

@override
async def rule(self) -> bool:
return (
self.event.type == "apscheduler" and type(self) is self.event.plugin_class
Expand Down
7 changes: 6 additions & 1 deletion examples/plugins/schedule_decorator.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from typing import override

from alicebot import Plugin
from alicebot.adapter.apscheduler import scheduler_decorator
from alicebot.adapter.apscheduler.event import APSchedulerEvent


@scheduler_decorator(
trigger="interval", trigger_args={"seconds": 10}, override_rule=True
)
class Schedule(Plugin):
class ScheduleDecorator(Plugin[APSchedulerEvent]):
@override
async def handle(self) -> None:
print("scheduler_decorator", self.event.type, self.event.adapter)

@override
async def rule(self) -> bool:
return False
19 changes: 10 additions & 9 deletions examples/plugins/weather_cqhttp.py → examples/plugins/weather.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from alicebot import Plugin
from typing import Any, override

from alicebot import MessageEvent, Plugin
from alicebot.exceptions import GetEventTimeout


class Weather(Plugin):
class Weather(Plugin[MessageEvent[Any]]):
@override
async def handle(self) -> None:
args = self.event.get_plain_text().split(" ")

Expand All @@ -17,17 +20,15 @@ async def handle(self) -> None:
else:
await self.event.reply(await self.get_weather(city_event.get_plain_text()))

@override
async def rule(self) -> bool:
if self.event.adapter.name != "cqhttp":
return False
if self.event.type != "message":
if not isinstance(self.event, MessageEvent):
return False
return self.event.message.startswith("天气") or self.event.message.startswith(
"weather"
)
message = self.event.get_plain_text()
return message.startswith(("天气", "weather"))

@staticmethod
async def get_weather(city):
async def get_weather(city: str) -> str:
if city not in ["北京", "上海"]:
return "你想查询的城市暂不支持!"
return f"{city}的天气是..."
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ mirai = ["alicebot-adapter-mirai"]
dingtalk = ["alicebot-adapter-dingtalk"]
telegram = ["alicebot-adapter-telegram"]
apscheduler = ["alicebot-adapter-apscheduler"]
hot_reload = ["watchfiles>=0.24"]
hot_reload = ["watchfiles>=1"]
all = [
"alicebot-adapter-cqhttp",
"alicebot-adapter-onebot",
"alicebot-adapter-mirai",
"alicebot-adapter-dingtalk",
"alicebot-adapter-telegram",
"alicebot-adapter-apscheduler",
"watchfiles>=0.24",
"watchfiles>=1",
]

[project.urls]
Expand All @@ -57,7 +57,7 @@ dev = [
]
lint = [
"ruff>=0.6",
"pylint>=3",
"pylint>=4",
"pylint-pydantic>=0.3",
"basedpyright>=1",
"mypy>=1",
Expand All @@ -67,10 +67,10 @@ docs = [
"tomlkit>=0.13",
]
test = [
"pytest>=8",
"pytest>=9",
"pytest-mock>=3",
"pytest-xdist>=3",
"pytest-cov>=5",
"pytest-cov>=7",
]

[tool.uv]
Expand Down Expand Up @@ -138,7 +138,6 @@ keep-runtime-typing = true
"tests/*.py" = ["D", "PLR2004"]

[tool.basedpyright]
ignore = ["examples/plugins"]
extraPaths = ["tests", "tests/test_utils"]
pythonVersion = "3.13"
pythonPlatform = "All"
Expand All @@ -163,7 +162,6 @@ strict = true
exclude = [
'^packages/.*/alicebot/__init__\.py$',
'^packages/.*/alicebot/adapter/__init__\.py$',
'^examples/.*\.py$',
]
warn_return_any = false

Expand Down
Loading
Loading