Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/core/builtins/__init__.py

42 lines
1.3 KiB
Python
Raw Normal View History

2023-04-17 08:55:55 +00:00
from typing import Union, List
2023-04-16 07:44:17 +00:00
from core.types.message import FetchTarget, FetchedSession
2023-04-17 08:55:55 +00:00
from database import BotDBUtil
2023-02-04 14:42:21 +00:00
from .message import *
2023-02-05 14:33:33 +00:00
from .message.chain import *
from .message.internal import *
from .tasks import *
from .temp import *
from .utils import *
2023-02-04 14:42:21 +00:00
class Bot:
MessageSession = MessageSession
FetchTarget = FetchTarget
2023-04-16 07:44:17 +00:00
2023-04-16 07:46:17 +00:00
@staticmethod
2023-05-05 15:33:19 +00:00
async def sendMessage(target: Union[FetchedSession, MessageSession, str], msg: Union[MessageChain, list],
2023-04-16 07:44:17 +00:00
disable_secret_check=False,
allow_split_image=True):
if isinstance(target, str):
2023-04-17 08:55:55 +00:00
target = Bot.FetchTarget.fetch_target(target)
if not target:
raise ValueError("Target not found")
2023-04-16 07:44:17 +00:00
if isinstance(msg, list):
msg = MessageChain(msg)
await target.sendDirectMessage(msg, disable_secret_check, allow_split_image)
2023-04-17 08:55:55 +00:00
@staticmethod
async def fetch_target(target: str):
return Bot.FetchTarget.fetch_target(target)
@staticmethod
async def get_enabled_this_module(module: str) -> List[FetchedSession]:
lst = BotDBUtil.TargetInfo.get_enabled_this(module)
fetched = []
for x in lst:
x = Bot.FetchTarget.fetch_target(x)
if isinstance(x, FetchedSession):
fetched.append(x)
return fetched