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
|
2023-10-03 04:01:27 +02:00
|
|
|
|
|
|
|
|
2023-10-02 07:36:36 +02:00
|
|
|
class MinyaDB(ModuleInterface):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.name = "MinyaDB"
|
|
|
|
self.regex_pattern = None
|
|
|
|
|
|
|
|
if not os.path.isdir("./minyadb"):
|
|
|
|
os.mkdir("./minyadb")
|
2023-10-03 04:01:27 +02:00
|
|
|
|
2023-10-02 07:36:36 +02:00
|
|
|
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.")
|
2023-10-03 04:01:27 +02:00
|
|
|
|
2023-10-02 07:36:36 +02:00
|
|
|
async def execute_module(self, ctx: Note):
|
|
|
|
pass
|
2023-10-03 04:01:27 +02:00
|
|
|
|
2023-10-02 07:36:36 +02:00
|
|
|
def _get_module_db(self, module_name: str, key: str):
|
|
|
|
db = PupDB(f"./minyadb/{module_name}.db")
|
2023-10-05 15:49:14 +02:00
|
|
|
return db.get(key)
|
2023-10-02 07:36:36 +02:00
|
|
|
|
|
|
|
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.")
|