feat: added database module

This commit is contained in:
Soumt Nam 2023-10-02 14:36:36 +09:00
parent 1e285b4c78
commit 6252090b4e
No known key found for this signature in database
GPG key ID: 5F46B099DCBCA8CE
6 changed files with 42 additions and 4 deletions

3
.gitignore vendored
View file

@ -178,3 +178,6 @@ poetry.toml
pyrightconfig.json
# End of https://www.toptal.com/developers/gitignore/api/python,dotenv
# MinyaDB Module
minyadb

View file

@ -59,6 +59,8 @@ class MiNya(Bot):
for module in self.__modules:
self.__manager.register_module(module)
for module in self.__modules:
module.module_ready()
print("")
async def on_mention(self, notice: NotificationNote):

View file

@ -9,7 +9,7 @@ class ModuleInterface:
def set_manager(self, manager):
self.manager = manager
self.module_ready()
#self.module_ready()
def get_execute_pattern(self, regex_pattern):
return self.__regex_pattern

View file

@ -191,7 +191,6 @@ items = [
'엔터 키',
'항아리',
'수은',
'DHMO',
'',
'토지',
'대륙',

View file

@ -24,11 +24,14 @@ class Friend(ModuleInterface):
pass
def _get_like(self, userid: str):
pass
return self._get_db(self.Name, userid)
async def _is_friend_async(self, userid: str):
target = await self.manager.bot.user.api.action.get(userid)
return target.is_followed and target.is_following
def module_ready(self):
self._get_db = self.manager.require("MinyaDB").get_func("get_module_db")
self._set_db = self.manager.require("MinyaDB").get_func("set_module_db")
print("[Friend] Module Ready.")

31
modules/Minya_DB.py Normal file
View file

@ -0,0 +1,31 @@
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.")