Files
aoc/skills/helper.py
T
2026-02-15 13:26:30 +01:00

41 lines
1.3 KiB
Python

import logging
import time
import asyncio
from nio import RoomMessageText
logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', level=logging.INFO)
class BotHelper:
"""a helper class for frequently need actions"""
__AUTHOR__ = 'anima'
__VERSION__ = '0.0.2'
def __init__(self, client):
self.client = client
self.starttime = int(time.time() * 1000)
def validate_message(self, event: RoomMessageText):
"""validate incomming messages befor bot start his work"""
if self.client.user == event.sender:
logging.debug(f"no reaction on messgaes from bot it self")
return False
if self.starttime > event.server_timestamp:
logging.debug(f"no reaction on messgaes befor bot start")
return False
return True
async def send_message(self, room: str, message: str):
"""send a basic text message to a room
Args:
room (str): room id without domain part (like !roomid)
message (str): simpl text message
"""
logging.debug(f'send message: {message}')
await self.client.room_send(
room,
message_type="m.room.message",
content={
"msgtype": "m.text",
"body": message
}
)