KuroCore/kurocore/main/event.py

41 lines
1.2 KiB
Python
Raw Normal View History

2024-03-24 04:05:54 +03:00
from kurocore.vk.utils import generate_random_id
2024-01-02 00:25:23 +03:00
class ChatEvent:
__slots__ = ('session', 'api', 'raw', 'type', 'member_id', 'text', 'photo')
2024-03-24 04:05:54 +03:00
def __init__(self, api, raw: dict):
2024-01-02 00:25:23 +03:00
self.api = api
self.raw: dict = raw
self.type: str = self.raw.get('type', '')
self.member_id: int = self.raw.get('member_id', 0)
self.text: str = self.raw.get('text', '')
self.photo: dict = self.raw.get('photo', {})
class Event:
__slots__ = ('session', 'api', 'raw', 'type')
2024-03-24 04:05:54 +03:00
def __init__(self, api, raw: dict):
2024-01-02 00:25:23 +03:00
self.api = api
self.raw: dict = raw['object']
self.type: str = raw['type']
async def send_message(self, target_id, text, attachments: (str, list, tuple, set, frozenset) = '', **kwargs):
data = kwargs.copy()
data.update({
'peer_id': target_id,
'random_id': generate_random_id()
})
if text:
data.update({'message': text})
if attachments:
2024-03-24 04:05:54 +03:00
if type(attachments) is str:
2024-01-02 00:25:23 +03:00
data.update({'attachment': attachments})
else:
data.update({'attachment': ','.join(attachments)})
await self.api.messages.send(**data)