diff --git a/app/Models/UserBot.php b/app/Models/UserBot.php
index e79f47112..520b7bdfe 100644
--- a/app/Models/UserBot.php
+++ b/app/Models/UserBot.php
@@ -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" => "使用说明:打开你想要发匿名消息的个人对话,点击输入框右边的 ⊕ 号,选择 匿名消息 即可输入你想要发送的匿名消息内容。",
+ "privacy" => "匿名消息将通过 匿名消息(机器人) 发送给对方,不会记录你的身份信息。",
+ default => '',
+ };
+ }
}
diff --git a/app/Module/Extranet.php b/app/Module/Extranet.php
index aca6b26eb..4b738c184 100644
--- a/app/Module/Extranet.php
+++ b/app/Module/Extranet.php
@@ -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;
diff --git a/app/Tasks/BotReceiveMsgTask.php b/app/Tasks/BotReceiveMsgTask.php
index ba8b1872b..32e9aa061 100644
--- a/app/Tasks/BotReceiveMsgTask.php
+++ b/app/Tasks/BotReceiveMsgTask.php
@@ -69,19 +69,27 @@ class BotReceiveMsgTask extends AbstractTask
return;
}
$original = $msg->msg['text'];
- $pureText = trim(strip_tags($original));
+ if (preg_match("/]*?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("/]*?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,
diff --git a/language/original-web.txt b/language/original-web.txt
index f964c89fa..39de3229b 100644
--- a/language/original-web.txt
+++ b/language/original-web.txt
@@ -1041,7 +1041,7 @@ Pro版
匿名消息
匿名消息仅允许发送给个人
发送匿名消息
-匿名消息将通过匿名机器人发送给对方,绝对不会暴露你的身份
+匿名消息将通过匿名消息(机器人)发送给对方,不会记录你的任何身份信息
匿名发送
请输入消息内容
隐藏共享文件
diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue
index e28f90ad5..96b733374 100644
--- a/resources/assets/js/pages/manage/components/DialogWrapper.vue
+++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue
@@ -1571,7 +1571,7 @@ export default {
}
$A.modalInput({
title: `发送匿名消息`,
- placeholder: `匿名消息将通过匿名机器人发送给对方,绝对不会暴露你的身份`,
+ placeholder: `匿名消息将通过匿名消息(机器人)发送给对方,不会记录你的任何身份信息`,
inputProps: {
type: 'textarea',
rows: 3,
diff --git a/resources/views/push/bot.blade.php b/resources/views/push/bot.blade.php
index 854a89692..347d16705 100755
--- a/resources/views/push/bot.blade.php
+++ b/resources/views/push/bot.blade.php
@@ -12,7 +12,7 @@
/setname {机器人ID} {机器人名称} - 修改机器人名称
/deletebot {机器人ID} - 删除机器人
/clearday {机器人ID} {天数} - 设置自动清理消息时间(默认30天)
- /webhook {机器人ID} [url] - 设置消息Webhook(详细说明看 /api)
+ /webhook {机器人ID} [url] - 设置消息Webhook(详情请看 Api接口文档)
机器人设置
/token {机器人ID} - 生成Token令牌