perf: 新增管理机器人菜单

This commit is contained in:
kuaifan 2023-03-09 17:53:00 +08:00
parent 9dd27e9796
commit f2652d1ee4
6 changed files with 80 additions and 35 deletions

View File

@ -43,8 +43,8 @@ class UserBot extends AbstractModel
*/
public static function quickMsgs($email)
{
if ($email === 'check-in@bot.system') {
return [
return match ($email) {
'check-in@bot.system' => [
[
'key' => 'checkin',
'label' => Base::Lang('我要签到')
@ -59,38 +59,69 @@ class UserBot extends AbstractModel
'label' => Base::Lang('60s读世界')
], [
'key' => 'joke',
'label' => Base::Lang('一个笑话')
'label' => Base::Lang('开心笑话')
], [
'key' => 'soup',
'label' => Base::Lang('一碗鸡汤')
'label' => Base::Lang('心灵鸡汤')
]
];
}
return [];
],
'anon-msg@bot.system' => [
[
'key' => 'help',
'label' => Base::Lang('使用说明')
], [
'key' => 'privacy',
'label' => Base::Lang('隐私说明')
],
],
'bot-manager@bot.system' => [
[
'key' => '/help',
'label' => Base::Lang('帮助指令')
], [
'key' => '/api',
'label' => Base::Lang('Api接口文档')
], [
'key' => '/list',
'label' => Base::Lang('我的机器人')
],
],
default => [],
};
}
/**
* 签到机器人
* @param $type
* @param $command
* @param $userid
* @return string
*/
public static function checkinBotQuickMsg($type, $userid)
public static function checkinBotQuickMsg($command, $userid)
{
if (Cache::get("UserBot::checkinBotQuickMsg:{$userid}") === "yes") {
return "操作频繁!";
}
Cache::put("UserBot::checkinBotQuickMsg:{$userid}", "yes", Carbon::now()->addSecond());
//
switch ($type) {
case "checkin":
$text = "暂未开放手动签到。";
break;
default:
$text = Extranet::checkinBotQuickMsg($type);
break;
}
$text = match ($command) {
"checkin" => "暂未开放手动签到。",
default => Extranet::checkinBotQuickMsg($command),
};
return $text ?: '维护中...';
}
/**
* 隐私机器人
* @param $command
* @return string
*/
public static function anonBotQuickMsg($command)
{
return match ($command) {
"help" => "使用说明:打开你想要发匿名消息的个人对话,点击输入框右边的 ⊕ 号,选择 <u>匿名消息</u> 即可输入你想要发送的匿名消息内容。",
"privacy" => "匿名消息将通过 <u>匿名消息(机器人)</u> 发送给对方,不会记录你的身份信息。",
default => '',
};
}
}

View File

@ -213,7 +213,7 @@ class Extranet
*/
public static function checkinBotQuickMsg($type): string
{
$text = '';
$text = "维护中...";
switch ($type) {
case "it":
$data = self::curl('https://api.vvhan.com/api/hotlist?type=itNews', 3600);
@ -263,15 +263,21 @@ class Extranet
break;
case "joke":
$text = "笑话被掏空";
$data = self::curl('https://api.vvhan.com/api/joke?type=json', 5);
if ($data = Base::json2array($data)) {
$text = $data['joke'] ?: '笑话被掏空';
if ($data = trim($data['joke'])) {
$text = "开心笑话:{$data}";
}
}
break;
case "soup":
$text = "鸡汤分完了";
$data = self::curl('https://api.ayfre.com/jt/?type=bot', 5);
$text = trim($data) ?: "鸡汤分完了";
if ($data = trim($data)) {
$text = "心灵鸡汤:{$data}";
}
break;
}
return $text;

View File

@ -69,19 +69,27 @@ class BotReceiveMsgTask extends AbstractTask
return;
}
$original = $msg->msg['text'];
$pureText = trim(strip_tags($original));
if (preg_match("/<span[^>]*?data-quick-key=([\"'])(.*?)\\1[^>]*?>(.*?)<\/span>/is", $original, $match)) {
$command = $match[2];
} else {
$command = trim(strip_tags($original));
}
// 签到机器人
if ($botUser->email === 'check-in@bot.system') {
if (preg_match("/<span[^>]*?data-quick-key=([\"'])(.*?)\\1[^>]*?>(.*?)<\/span>/is", $original, $match)) {
$text = UserBot::checkinBotQuickMsg($match[2], $msg->userid);
if ($text) {
WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'text', ['text' => $text], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务
}
return;
$text = UserBot::checkinBotQuickMsg($command, $msg->userid);
if ($text) {
WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'text', ['text' => $text], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务
}
}
// 隐私机器人
if ($botUser->email === 'anon-msg@bot.system') {
$text = UserBot::anonBotQuickMsg($command);
if ($text) {
WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'text', ['text' => $text], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务
}
}
// 管理机器人
if (str_starts_with($pureText, '/')) {
if (str_starts_with($command, '/')) {
if ($botUser->email === 'bot-manager@bot.system') {
$isManager = true;
} elseif (UserBot::whereBotId($botUser->userid)->whereUserid($msg->userid)->exists()) {
@ -92,7 +100,7 @@ class BotReceiveMsgTask extends AbstractTask
return;
}
//
$array = Base::newTrim(explode(" ", "{$pureText} "));
$array = Base::newTrim(explode(" ", "{$command} "));
$type = $array[0];
$data = [];
$notice = "";
@ -331,11 +339,11 @@ class BotReceiveMsgTask extends AbstractTask
return;
}
// 推送Webhook
if ($pureText) {
if ($command) {
$userBot = UserBot::whereBotId($botUser->userid)->first();
if ($userBot && preg_match("/^https*:\/\//", $userBot->webhook_url)) {
Ihttp::ihttp_post($userBot->webhook_url, [
'text' => $pureText,
'text' => $command,
'token' => User::token($botUser),
'dialog_id' => $msg->dialog_id,
'msg_id' => $msg->id,

View File

@ -1041,7 +1041,7 @@ Pro版
匿名消息
匿名消息仅允许发送给个人
发送匿名消息
匿名消息将通过匿名机器人发送给对方,绝对不会暴露你的身份
匿名消息将通过匿名消息(机器人)发送给对方,不会记录你的任何身份信息
匿名发送
请输入消息内容
隐藏共享文件

View File

@ -1571,7 +1571,7 @@ export default {
}
$A.modalInput({
title: `发送匿名消息`,
placeholder: `匿名消息将通过匿名机器人发送给对方,绝对不会暴露你的身份`,
placeholder: `匿名消息将通过匿名消息(机器人)发送给对方,不会记录你的任何身份信息`,
inputProps: {
type: 'textarea',
rows: 3,

View File

@ -12,7 +12,7 @@
<span style="color:#84c56a">/setname {机器人ID} {机器人名称}</span> - 修改机器人名称
<span style="color:#84c56a">/deletebot {机器人ID}</span> - 删除机器人
<span style="color:#84c56a">/clearday {机器人ID} {天数}</span> - 设置自动清理消息时间默认30天
<span style="color:#84c56a">/webhook {机器人ID} [url]</span> - 设置消息Webhook细说明看 <u>/api</u>
<span style="color:#84c56a">/webhook {机器人ID} [url]</span> - 设置消息Webhook情请看 <u>Api接口文档</u>
<b>机器人设置</b>
<span style="color:#84c56a">/token {机器人ID}</span> - 生成Token令牌