diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index 59ccb00eb..b8850fa0b 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -84,7 +84,7 @@ class WebSocketDialog extends AbstractModel $this->top_at = $this->top_at ?? $dialogUserFun('top_at'); $this->user_at = $this->user_at ?? $dialogUserFun('updated_at'); $this->user_ms = WebSocketDialogUser::userMs($this->user_at); - $this->quick_msg = []; + $this->quick_msgs = []; // if (isset($this->search_msg_id)) { // 最后消息 (搜索预览消息) @@ -118,6 +118,14 @@ class WebSocketDialog extends AbstractModel if ($basic) { $this->name = $basic->nickname; $this->bot = $basic->bot; + if ($basic->email === 'check-in@bot.system') { + $this->quick_msgs = [ + [ + 'key' => 'checkin', + 'label' => Base::Lang('我要签到') + ] + ]; + } } else { $this->name = 'non-existent'; $this->dialog_delete = 1; diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index 8f3f502dc..7c7a21d83 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -695,6 +695,17 @@ class WebSocketDialogMsg extends AbstractModel } $text = str_replace($matchs[0][$key], "[:{$matchChar[1]}:{$keyId}:{$matchValye[1]}:]", $text); } + // 处理快捷消息 + preg_match_all("/]*?data-quick-key=([\"'])(.*?)\\1[^>]*?>(.*?)<\/span>/is", $text, $matchs); + foreach ($matchs[0] as $key => $str) { + $quickKey = $matchs[2][$key]; + $quickLabel = $matchs[3][$key]; + if ($quickKey && $quickLabel) { + $quickKey = str_replace(":", "", $quickKey); + $quickLabel = str_replace(":", "", $quickLabel); + $text = str_replace($str, "[:QUICK:{$quickKey}:{$quickLabel}:]", $text); + } + } // 处理链接标签 preg_match_all("/]*?href=([\"'])(.*?)\\1[^>]*?>(.*?)<\/a>/is", $text, $matchs); foreach ($matchs[0] as $key => $str) { @@ -734,6 +745,7 @@ class WebSocketDialogMsg extends AbstractModel $text = preg_replace("/\[:@:(.*?):(.*?):\]/i", "@$2", $text); $text = preg_replace("/\[:#:(.*?):(.*?):\]/i", "#$2", $text); $text = preg_replace("/\[:~:(.*?):(.*?):\]/i", "~$2", $text); + $text = preg_replace("/\[:QUICK:(.*?):(.*?):\]/i", "$2", $text); $text = preg_replace_callback("/\[:LINK:(.*?):(.*?):\]/i", function (array $match) { return "" . base64_decode($match[2]) . ""; }, $text); diff --git a/app/Tasks/BotReceiveMsgTask.php b/app/Tasks/BotReceiveMsgTask.php index 018cbc0e9..095b769a2 100644 --- a/app/Tasks/BotReceiveMsgTask.php +++ b/app/Tasks/BotReceiveMsgTask.php @@ -68,9 +68,20 @@ class BotReceiveMsgTask extends AbstractTask if ($msg->type !== 'text') { return; } - $pureText = trim(strip_tags($msg->msg['text'])); + $original = $msg->msg['text']; + $pureText = trim(strip_tags($original)); + // 签到机器人 + if ($botUser->email === 'check-in@bot.system') { + if (preg_match("/]*?data-quick-key=([\"'])(.*?)\\1[^>]*?>(.*?)<\/span>/is", $original, $match)) { + if ($match[2] === 'checkin') { + $text = "暂未开放手动签到。"; + WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'text', ['text' => $text], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务 + return; + } + } + } + // 管理机器人 if (str_starts_with($pureText, '/')) { - // 管理机器人 if ($botUser->email === 'bot-manager@bot.system') { $isManager = true; } elseif (UserBot::whereBotId($botUser->userid)->whereUserid($msg->userid)->exists()) { @@ -317,8 +328,10 @@ class BotReceiveMsgTask extends AbstractTask $text = preg_replace("/^\x20+/", "", $text); $text = preg_replace("/\n\x20+/", "\n", $text); WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'text', ['text' => $text], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务 - } elseif ($pureText) { - // 推送Webhook + return; + } + // 推送Webhook + if ($pureText) { $userBot = UserBot::whereBotId($botUser->userid)->first(); if ($userBot && preg_match("/^https*:\/\//", $userBot->webhook_url)) { Ihttp::ihttp_post($userBot->webhook_url, [ diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 84ff9d44f..4dd194fef 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -174,8 +174,8 @@
    -
  • -
    {{text}}
    +
  • +
    {{item.label}}
@@ -730,12 +730,12 @@ export default { return array }, - quickMsg() { - return this.dialogData.quick_msg || [] + quickMsgs() { + return this.dialogData.quick_msgs || [] }, quickShow() { - return this.quickMsg.length > 0 && this.windowScrollY === 0 && this.replyId === 0 + return this.quickMsgs.length > 0 && this.windowScrollY === 0 && this.replyId === 0 }, todoList() { @@ -1144,6 +1144,14 @@ export default { } }, + /** + * 发送快捷消息 + * @param item + */ + sendQuick(item) { + this.sendMsg(`

${item.label}

`) + }, + getMsgs(data) { return new Promise((resolve, reject) => { setTimeout(_ => this.msgLoadIng++, 2000) diff --git a/resources/assets/sass/pages/page-messenger.scss b/resources/assets/sass/pages/page-messenger.scss index 80aa644f1..301572931 100644 --- a/resources/assets/sass/pages/page-messenger.scss +++ b/resources/assets/sass/pages/page-messenger.scss @@ -556,7 +556,7 @@ .messenger-nav-item { display: flex; align-items: center; - min-width: 90px; + min-width: 80px; &.active { .nav-title { font-weight: bold; @@ -642,4 +642,9 @@ } } } + .messenger-nav-menu { + .messenger-nav-item { + min-width: 100px; + } + } }