minya_hotomoe/modules/Minya_DB.py
2023-10-05 22:49:14 +09:00

33 lines
939 B
Python

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")
return 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.")