Rbot注解

发表:2年前 更新:1年前

RBotOnMessage

这是一个 方法注解 只能用在类的方法上。

使用时需要 use 此注解类

use App\RBot\Annotation\RBotOnMessage;

使用此注解时请结合 go-cqhttp event 文档:https://docs.go-cqhttp.org/event/

用法

class Demo
{
	#[RBotOnMessage(传入的字段)]
	public function demo(string $msg,\App\RBot\RBotMsg $data){

	}
}

目前支持传入 post_typemessage_typenotice_typerequest_type 字段

这些字段的具体说明需要看 go-cqhttp event 文档

uploadtopic20220208116443220705BvUlte5UO.png

下面来说此注解的作用:

当你在某个方法上使用了此注解后,系统会根据你注解内传入的字段参数进行判断,符合条件则执行此方法

举例:

<?php

namespace App\Plugins\Demo\src\Message;

use App\RBot\Annotation\RBotOnMessage;

class Demo
{
	#[RBotOnMessage(post_type:"message")]
	public function demo($msg,\App\RBot\RBotMsg $data){

	}
}

如上面代码所示,我在这个注解内设置了 post_type 字段的参数为 message

那么在 go-cqhttp 事件中,post_type 的值等于 message 时才会执行 demo 方法。

简单来说,也就是收到消息时会执行 demo 方法。

通俗一点也就是当 post_type 上报的参数为 message 时会执行 demo 方法

当然,post_type 的值也可能是其他内容,这个需要到控制台查看查看 RBot:Watcher 命令的输出,或者查看 go-cqhttp event 文档

uploadtopic2022020811644322660xjvE13PYdh.png

uploadtopic2022020811644322529IKQyEK5JEE.png

进阶例子:

<?php

namespace App\Plugins\Demo\src\Message;

use App\RBot\Annotation\RBotOnMessage;

class Demo
{
	#[RBotOnMessage(post_type:"message",message_type:"group")]
	public function demo($msg,\App\RBot\RBotMsg $data){

	}
}

如上面代码所示:

我在这个注解内设置了 post_type 字段的参数为 message

message_type 字段的参数为 group

其意思也就是收到消息,并且是群聊消息后才执行 demo 方法

通俗一点,也就是当上报的 message_type 字段值为 group 时执行 demo 方法里的代码

notice_typerequest_typemessage_type 字段的意思及用法一样,不一样的是不同场景,不同值

signature
保持理智
评论

无权限

请登录后评论

RunPod公众号

赞助商

联系我们

QQ群:798695907

邮箱:laravel@88.com