From 85ec2f7dc55a672b07272a50f11eb86460f38671 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Wed, 9 Aug 2023 14:36:37 +0800 Subject: feat:all MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plugins/Webhook/__init__.py | 32 ++++++++++++++++++++++++++++++++ tests/plugins/Webhook/config.py | 0 2 files changed, 32 insertions(+) create mode 100644 tests/plugins/Webhook/__init__.py create mode 100644 tests/plugins/Webhook/config.py (limited to 'tests/plugins/Webhook') 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 -- cgit v1.2.3-70-g09d2