mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-08 06:46:02 +00:00
feat: 在PluginHost中提供消息发送方法
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
# 插件管理模块
|
||||
import asyncio
|
||||
import logging
|
||||
import importlib
|
||||
import pkgutil
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
import pkg.utils.context as context
|
||||
|
||||
from mirai import Mirai
|
||||
|
||||
__plugins__ = {}
|
||||
"""
|
||||
插件列表
|
||||
@@ -159,10 +163,18 @@ class PluginHost:
|
||||
"""获取运行时上下文"""
|
||||
return context
|
||||
|
||||
def get_bot(self):
|
||||
def get_bot(self) -> Mirai:
|
||||
"""获取机器人对象"""
|
||||
return context.get_qqbot_manager().bot
|
||||
|
||||
def send_person_message(self, person, message):
|
||||
"""发送私聊消息"""
|
||||
asyncio.run(self.get_bot().send_friend_message(person, message))
|
||||
|
||||
def send_group_message(self, group, message):
|
||||
"""发送群消息"""
|
||||
asyncio.run(self.get_bot().send_group_message(group, message))
|
||||
|
||||
def notify_admin(self, message):
|
||||
"""通知管理员"""
|
||||
context.get_qqbot_manager().notify_admin(message)
|
||||
@@ -184,7 +196,8 @@ class PluginHost:
|
||||
logging.debug("插件 {} 阻止了后序插件的执行".format(plugin['name']))
|
||||
break
|
||||
|
||||
except:
|
||||
logging.error("插件{}触发事件{}时发生错误: {}".format(plugin['name'], event_name, sys.exc_info()))
|
||||
except Exception as e:
|
||||
logging.error("插件{}触发事件{}时发生错误".format(plugin['name'], event_name))
|
||||
logging.error(traceback.format_exc())
|
||||
|
||||
return event_context
|
||||
|
||||
Reference in New Issue
Block a user