From 1e85cafcde86f306b95dbce6026ddf3731d858e5 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Sat, 25 May 2024 18:48:49 +0800 Subject: [PATCH] Update main.py --- main.py | 60 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/main.py b/main.py index 1b3d6e4..a954000 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,17 @@ +import os +import shutil from nakuru.entities.components import * -from nakuru import ( - GroupMessage, - FriendMessage -) -from botpy.message import Message, DirectMessage -from cores.qqbot.global_object import ( - AstrMessageEvent, - CommandResult -) +flag_not_support = False +try: + from util.plugin_dev.api.v1.config import * + from util.plugin_dev.api.v1.bot import ( + AstrMessageEvent, + CommandResult, + ) +except ImportError: + flag_not_support = True + print("导入接口失败。请升级到 AstrBot 最新版本。") + ''' 注意改插件名噢!格式:XXXPlugin 或 Main @@ -18,29 +22,24 @@ class HelloWorldPlugin: 初始化函数, 可以选择直接pass """ def __init__(self) -> None: - print("hello, world!") + pass """ 机器人程序会调用此函数。 - 返回规范: bool: 插件是否响应该消息 (所有的消息均会调用每一个载入的插件, 如果不响应, 则应返回 False) - Tuple: Non e或者长度为 3 的元组。如果不响应, 返回 None; 如果响应, 第 1 个参数为指令是否调用成功, 第 2 个参数为返回的消息链列表, 第 3 个参数为指令名称 - 例子:一个名为"yuanshen"的插件;当接收到消息为“原神 可莉”, 如果不想要处理此消息,则返回False, None;如果想要处理,但是执行失败了,返回True, tuple([False, "请求失败。", "yuanshen"]) ;执行成功了,返回True, tuple([True, "结果文本", "yuanshen"]) """ def run(self, ame: AstrMessageEvent): - if ame.message_str == "helloworld": - # return True, tuple([True, "Hello World!!", "helloworld"]) + if ame.message_str.startswith("helloworld"): # 如果消息文本以"helloworld"开头 return CommandResult( - hit=True, - success=True, - message_chain=[Plain("Hello World!!")], - command_name="helloworld" - ) - else: - return CommandResult( - hit=False, - success=False, - message_chain=None, + hit=True, # 代表插件会响应此消息 + success=True, # 插件响应类型为成功响应 + message_chain=[Plain("Hello World!!")], # 消息链 + command_name="helloworld" # 指令名 ) + return CommandResult( + hit=False, # 插件不会响应此消息 + success=False, + message_chain=None + ) """ 插件元信息。 当用户输入 plugin v 插件名称 时,会调用此函数,返回帮助信息。 @@ -53,12 +52,13 @@ class HelloWorldPlugin: "repo": str, # 插件仓库地址 [ 可选 ] "homepage": str, # 插件主页 [ 可选 ] } - """ + """ def info(self): return { "name": "helloworld", - "desc": "测试插件", - "help": "测试插件, 回复 helloworld 即可触发", - "version": "v1.2", - "author": "Soulter" + "desc": "这是 AstrBot 的默认插件,支持关键词回复。", + "help": "输入 /keyword 查看关键词回复帮助。", + "version": "v1.3", + "author": "Soulter", + "repo": "https://github.com/Soulter/helloworld" }