meshtastic-matrix-relay/plugins/base_plugin.py

37 wiersze
1.2 KiB
Python
Czysty Zwykły widok Historia

2023-04-25 21:29:17 +00:00
from abc import ABC, abstractmethod
2023-04-27 23:58:29 +00:00
from log_utils import get_logger
from config import relay_config
2023-04-28 07:04:09 +00:00
from db_utils import store_plugin_data, get_plugin_data, get_plugin_data_for_node
2023-04-25 21:29:17 +00:00
class BasePlugin(ABC):
2023-04-27 23:58:29 +00:00
plugin_name = None
2023-04-28 07:04:09 +00:00
max_data_rows_per_node = 10
2023-04-27 23:58:29 +00:00
def __init__(self) -> None:
super().__init__()
self.logger = get_logger(f"Plugin:{self.plugin_name}")
self.config = {"active": False}
if "plugins" in relay_config and self.plugin_name in relay_config["plugins"]:
self.config = relay_config["plugins"][self.plugin_name]
2023-04-28 07:04:09 +00:00
def store_node_data(self, meshtastic_id, data):
data = data[-self.max_data_rows_per_node :]
store_plugin_data(self.plugin_name, meshtastic_id, data)
def get_node_data(self, meshtastic_id):
return get_plugin_data_for_node(self.plugin_name, meshtastic_id)
def get_data(self):
return get_plugin_data(self.plugin_name)
2023-04-25 21:29:17 +00:00
@abstractmethod
async def handle_meshtastic_message(
packet, formatted_message, longname, meshnet_name
):
print("Base plugin: handling Meshtastic message")
@abstractmethod
async def handle_room_message(room, event, full_message):
print("Base plugin: handling room message")