add reaction validate and instance check
This commit is contained in:
+22
-4
@@ -1,25 +1,43 @@
|
||||
import logging
|
||||
import time
|
||||
import asyncio
|
||||
from nio import RoomMessageText
|
||||
from nio import RoomMessageText, ReactionEvent
|
||||
|
||||
logging.basicConfig(format='[%(asctime)s] %(process)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s', level=logging.INFO)
|
||||
|
||||
class BotHelper:
|
||||
"""a helper class for frequently need actions"""
|
||||
__AUTHOR__ = 'anima'
|
||||
__VERSION__ = '0.0.2'
|
||||
__VERSION__ = '0.3.1'
|
||||
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 not isinstance(event, RoomMessageText):
|
||||
logging.debug(f"message hast wrong type")
|
||||
return False
|
||||
if self.client.user == event.sender:
|
||||
logging.debug(f"no reaction on messgaes from bot it self")
|
||||
logging.debug(f"no reaction on messages from bot it self")
|
||||
return False
|
||||
if self.starttime > event.server_timestamp:
|
||||
logging.debug(f"no reaction on messgaes befor bot start")
|
||||
logging.debug(f"no reaction on messages befor bot start")
|
||||
return False
|
||||
return True
|
||||
|
||||
def validate_reaction(self, event: ReactionEvent):
|
||||
"""validate incomming reactions befor bot start his work"""
|
||||
if isinstance(event, ReactionEvent):
|
||||
logging.debug(f"reaction hast wrong type")
|
||||
return False
|
||||
if self.client.user == event.sender:
|
||||
logging.debug(f"no reaction on reactions from bot it self")
|
||||
return False
|
||||
if self.starttime > event.server_timestamp:
|
||||
print(f"{self.starttime=}")
|
||||
print(f"{event.server_timestamp=}")
|
||||
logging.debug(f"no reaction on reactions befor bot start")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user