aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests/plugins/test.py
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-05-02 23:30:19 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-05-02 23:30:19 +0800
commitdfa97c9d24b8124ca38ec5eb605cde932cd6ea78 (patch)
tree470a8bfd1960964b8c9724c19de876cf52cf60c3 /tests/plugins/test.py
parent45c49007ee01143ad26899751b856658321cd3ae (diff)
downloadHydroRoll-dfa97c9d24b8124ca38ec5eb605cde932cd6ea78.tar.gz
HydroRoll-dfa97c9d24b8124ca38ec5eb605cde932cd6ea78.zip
Diffstat (limited to 'tests/plugins/test.py')
-rw-r--r--tests/plugins/test.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/plugins/test.py b/tests/plugins/test.py
new file mode 100644
index 0000000..6f3bc3b
--- /dev/null
+++ b/tests/plugins/test.py
@@ -0,0 +1,35 @@
+from iamai import Plugin
+from iamai.exceptions import GetEventTimeout
+
+
+class Weather(Plugin):
+ async def handle(self) -> None:
+ args = self.event.get_plain_text().split(" ")
+ if len(args) >= 2:
+ await self.event.reply(await self.get_weather(args[1]))
+ else:
+ await self.event.reply("请输入想要查询天气的城市:")
+ try:
+ city_event = await self.event.adapter.get(
+ lambda x: x.type == "message", timeout=10
+ )
+ except GetEventTimeout:
+ return
+ else:
+ await self.event.reply(
+ await self.get_weather(city_event.get_plain_text())
+ )
+
+ async def rule(self) -> bool:
+ if self.event.adapter.name != "cqhttp":
+ return False
+ if self.event.type != "message":
+ return False
+ return self.event.message.startswith("天气")
+
+ @staticmethod
+ async def get_weather(city):
+ if city not in ["北京", "上海"]:
+ return "你想查询的城市暂不支持!"
+ return f"{city}的天气是..."
+