Initial commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user