mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 03:15:06 +08:00
feat(plugin): 新的__init__标准
This commit is contained in:
@@ -74,7 +74,7 @@ def initialize_plugins():
|
||||
if not plugin['enabled']:
|
||||
continue
|
||||
try:
|
||||
plugin['instance'] = plugin["class"]()
|
||||
plugin['instance'] = plugin["class"](plugin_host=context.get_plugin_host())
|
||||
except:
|
||||
logging.error("插件{}初始化时发生错误: {}".format(plugin['name'], sys.exc_info()))
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pkg.plugin.models import *
|
||||
from pkg.plugin.host import EventContext
|
||||
from pkg.plugin.host import EventContext, PluginHost
|
||||
|
||||
"""
|
||||
基本命令的中文形式支持
|
||||
@@ -26,7 +26,7 @@ __mapping__ = {
|
||||
@register(name="CmdCN", description="命令中文支持", version="0.1", author="RockChinQ")
|
||||
class CmdCnPlugin(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, plugin_host: PluginHost):
|
||||
pass
|
||||
|
||||
# 私聊发送指令
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pkg.plugin.models import *
|
||||
from pkg.plugin.host import EventContext
|
||||
from pkg.plugin.host import EventContext, PluginHost
|
||||
|
||||
"""
|
||||
在收到私聊或群聊消息"hello"时,回复"hello, <发送者id>!"或"hello, everyone!"
|
||||
@@ -10,7 +10,9 @@ from pkg.plugin.host import EventContext
|
||||
@register(name="Hello", description="hello world", version="0.1", author="RockChinQ")
|
||||
class HelloPlugin(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
# 插件加载时触发
|
||||
# plugin_host (pkg.plugin.host.PluginHost) 提供了与主程序交互的一些方法,详细请查看其源码
|
||||
def __init__(self, plugin_host: PluginHost):
|
||||
pass
|
||||
|
||||
# 当收到个人消息时触发
|
||||
@@ -43,5 +45,6 @@ class HelloPlugin(Plugin):
|
||||
# 阻止该事件默认行为(向接口获取回复)
|
||||
event.prevent_default()
|
||||
|
||||
# 插件卸载时触发
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
@@ -19,7 +19,7 @@ __random_reply__ = ['好好好', "啊对对对", "好好好好", "你说得对",
|
||||
@register(name="啊对对对", description="你都这样了,我就顺从你吧", version="0.1", author="RockChinQ")
|
||||
class AdddPlugin(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, plugin_host: PluginHost):
|
||||
pass
|
||||
|
||||
# 绑定私聊消息事件和群消息事件
|
||||
|
||||
Reference in New Issue
Block a user