aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests/plugins/Webhook/__init__.py
blob: 23f4c3a7b13959e46ac3bc01d6b12f67f480d389 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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