minya_hotomoe/modules/Friend.py

43 lines
1.4 KiB
Python
Raw Permalink Normal View History

2023-09-12 05:51:47 +02:00
from module_interface import ModuleInterface
from mipac.models import Note
2023-10-03 04:01:27 +02:00
2023-09-12 05:51:47 +02:00
class Friend(ModuleInterface):
def __init__(self):
super().__init__()
self.name = "Friend"
2023-09-15 04:43:17 +02:00
self.regex_pattern = ".*TestAreWeFriend"
2023-10-03 04:01:27 +02:00
2023-09-12 05:51:47 +02:00
self.funcs["dec_like"] = self._dec_like
self.funcs["inc_like"] = self._inc_like
self.funcs["get_like"] = self._get_like
2023-09-15 04:48:59 +02:00
self.funcs["is_friend_async"] = self._is_friend_async
2023-10-03 04:01:27 +02:00
2023-09-12 05:51:47 +02:00
print("[Friend] Friend DB system, Friend V1 loaded.")
async def execute_module(self, ctx: Note):
2023-10-03 04:01:27 +02:00
await ctx.api.action.reply(
"1" if await self._is_friend_async(ctx.author.id) else "0"
)
2023-09-15 04:43:17 +02:00
def _dec_like(self, userid: str):
2023-09-12 05:51:47 +02:00
pass
2023-09-15 04:43:17 +02:00
def _inc_like(self, userid: str):
2023-09-12 05:51:47 +02:00
pass
2023-09-15 04:43:17 +02:00
def _get_like(self, userid: str):
2023-10-03 04:01:27 +02:00
return self._get_db(self.name, userid)["like"]
2023-09-15 04:43:17 +02:00
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
2023-09-12 05:51:47 +02:00
def module_ready(self):
2023-10-03 04:01:27 +02:00
if self.manager != None:
self._get_db = self.manager.require("MinyaDB").get_func("get_module_db")
self._set_db = self.manager.require("MinyaDB").get_func("set_module_db")
else:
raise (Exception("Couldn't find manager"))
2023-09-12 05:51:47 +02:00
print("[Friend] Module Ready.")