aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests/plugins
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-08-09 14:36:37 +0800
committer简律纯 <i@jyunko.cn>2023-08-09 14:36:37 +0800
commit85ec2f7dc55a672b07272a50f11eb86460f38671 (patch)
tree8517989c8cc6444df8ae7ae50802a3b81766b01f /tests/plugins
parent642a278b1e2cc11fee587b933413a30c057753c1 (diff)
downloadHydroRoll-85ec2f7dc55a672b07272a50f11eb86460f38671.tar.gz
HydroRoll-85ec2f7dc55a672b07272a50f11eb86460f38671.zip
feat:all
Diffstat (limited to 'tests/plugins')
-rw-r--r--tests/plugins/Webhook/__init__.py32
-rw-r--r--tests/plugins/Webhook/config.py0
-rw-r--r--tests/plugins/_bradge-kook-cqhttp.py25
-rw-r--r--tests/plugins/e.py16
-rw-r--r--tests/plugins/exc.py18
-rw-r--r--tests/plugins/test.py35
-rw-r--r--tests/plugins/test2.py15
7 files changed, 88 insertions, 53 deletions
diff --git a/tests/plugins/Webhook/__init__.py b/tests/plugins/Webhook/__init__.py
new file mode 100644
index 0000000..23f4c3a
--- /dev/null
+++ b/tests/plugins/Webhook/__init__.py
@@ -0,0 +1,32 @@
+from iamai import Plugin
+from iamai.log import logger as log
+import asyncio
+import aiohttp
+
+payload = None
+
+class Webhook(Plugin):
+ async def handle(self) -> None:
+ global payload
+ if payload:
+ log.info(payload[:5])
+ await self.bot.get_adapter("cqhttp").call_api(
+ "send_group_msg",
+ group_id=126211793,
+ message=payload
+ )
+
+ async def rule(self) -> bool:
+ global payload
+ async with aiohttp.ClientSession() as session:
+ try:
+ async with session.get('http://localhost:3000') as response:
+ try:
+ payload = await response.text()
+ log.info(payload)
+ return True
+ except Exception as e:
+ log.info(f'Failed to fetch payload: {e}')
+ return False
+ except Exception as e:
+ return False \ No newline at end of file
diff --git a/tests/plugins/Webhook/config.py b/tests/plugins/Webhook/config.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/plugins/Webhook/config.py
diff --git a/tests/plugins/_bradge-kook-cqhttp.py b/tests/plugins/_bradge-kook-cqhttp.py
new file mode 100644
index 0000000..4b2712d
--- /dev/null
+++ b/tests/plugins/_bradge-kook-cqhttp.py
@@ -0,0 +1,25 @@
+from iamai import Plugin
+
+
+class Bradge(Plugin):
+ async def handle(self) -> None:
+ if self.event.adapter.name == "kook":
+ await self.bot.get_adapter("cqhttp").call_api(
+ "send_group_msg",
+ group_id=971050440,
+ message=f"[{self.event.adapter.name} - {self.event.extra.author.username}]\n{self.event.message}"
+ )
+ elif self.event.adapter.name == "cqhttp":
+ if self.event.group_id == 971050440:
+ await self.bot.get_adapter("kook").call_api(
+ api="message/create",
+ target_id=1661426334688259,
+ content=f"[{self.event.adapter.name} - {self.event.sender.nickname}]\n{self.event.message}"
+ )
+
+ async def rule(self) -> bool:
+ if self.event.adapter.name not in ["cqhttp","kook"]:
+ return False
+ if self.event.type not in ["message","9",9]:
+ return False
+ return True \ No newline at end of file
diff --git a/tests/plugins/e.py b/tests/plugins/e.py
new file mode 100644
index 0000000..be28e30
--- /dev/null
+++ b/tests/plugins/e.py
@@ -0,0 +1,16 @@
+from iamai import Plugin
+
+class Exec(Plugin):
+ async def handle(self) -> None:
+ try:
+ await self.event.reply(eval(self.event.raw_message[5:]))
+ except Exception as e:
+ await self.event.reply(f"ERROR:\n\t{e}")
+
+ async def rule(self) -> bool:
+ if self.event.adapter.name != "cqhttp":
+ return False
+ try:
+ return self.event.message.get_plain_text().startswith(".show")
+ except:
+ return False \ No newline at end of file
diff --git a/tests/plugins/exc.py b/tests/plugins/exc.py
deleted file mode 100644
index 4d6b885..0000000
--- a/tests/plugins/exc.py
+++ /dev/null
@@ -1,18 +0,0 @@
-from iamai import Plugin
-import os
-class Exec(Plugin):
- async def handle(self) -> None:
- from hydroroll.config import ConfigManager, GlobalConfig
- tmpConf = ConfigManager(os.path.join(GlobalConfig._current_path, "config", "userConf.dat"))
- tmpConf.load()
- await self.event.reply(str(tmpConf.properties))
-
-
- 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("t")
-
-print(1) \ No newline at end of file
diff --git a/tests/plugins/test.py b/tests/plugins/test.py
deleted file mode 100644
index 6f3bc3b..0000000
--- a/tests/plugins/test.py
+++ /dev/null
@@ -1,35 +0,0 @@
-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}的天气是..."
-
diff --git a/tests/plugins/test2.py b/tests/plugins/test2.py
new file mode 100644
index 0000000..45b37a9
--- /dev/null
+++ b/tests/plugins/test2.py
@@ -0,0 +1,15 @@
+from flask import Flask, request
+
+class Webhooks:
+ app = Flask(__name__)
+ requests = request
+ payload = None
+
+ @app.route('/', method=['POST', 'GET'])
+ async def handle_webhook(self):
+ self.payload = await request.get_json()
+ # 在这里处理接收到的数据
+ return 'Webhook received'
+
+ # app.run(host='0.0.0.0',port=3000)
+