feat: added database module
This commit is contained in:
parent
1e285b4c78
commit
6252090b4e
6 changed files with 42 additions and 4 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -178,3 +178,6 @@ poetry.toml
|
|||
pyrightconfig.json
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/python,dotenv
|
||||
|
||||
# MinyaDB Module
|
||||
minyadb
|
||||
|
|
2
minya.py
2
minya.py
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -191,7 +191,6 @@ items = [
|
|||
'엔터 키',
|
||||
'항아리',
|
||||
'수은',
|
||||
'DHMO',
|
||||
'물',
|
||||
'토지',
|
||||
'대륙',
|
||||
|
|
|
@ -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
31
modules/Minya_DB.py
Normal 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.")
|
Loading…
Reference in a new issue