minya_hotomoe/modules/Minya_DB.py

32 lines
950 B
Python
Raw Normal View History

2023-10-02 07:36:36 +02:00
from module_interface import ModuleInterface
from pupdb.core import PupDB
import os
from mipac.models import Note
class MinyaDB(ModuleInterface):
def __init__(self):
super().__init__()
self.name = "MinyaDB"
self.regex_pattern = None
if not os.path.isdir("./minyadb"):
os.mkdir("./minyadb")
self.funcs["get_module_db"] = self._get_module_db
self.funcs["set_module_db"] = self._set_module_db
print("[MinyaDB] Database system for modules, MinyaDB loaded.")
async def execute_module(self, ctx: Note):
pass
def _get_module_db(self, module_name: str, key: str):
db = PupDB(f"./minyadb/{module_name}.db")
db.get(key)
def _set_module_db(self, module_name: str, key: str, data):
db = PupDB(f"./minyadb/{module_name}.db")
db.set(key, data)
def module_ready(self):
print("[MinyaDB] Module Ready.")