mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-18 03:33:24 +00:00
优化快捷消息
This commit is contained in:
parent
6cf7833ef7
commit
c699feef54
@ -84,7 +84,7 @@ class WebSocketDialog extends AbstractModel
|
|||||||
$this->top_at = $this->top_at ?? $dialogUserFun('top_at');
|
$this->top_at = $this->top_at ?? $dialogUserFun('top_at');
|
||||||
$this->user_at = $this->user_at ?? $dialogUserFun('updated_at');
|
$this->user_at = $this->user_at ?? $dialogUserFun('updated_at');
|
||||||
$this->user_ms = WebSocketDialogUser::userMs($this->user_at);
|
$this->user_ms = WebSocketDialogUser::userMs($this->user_at);
|
||||||
$this->quick_msg = [];
|
$this->quick_msgs = [];
|
||||||
//
|
//
|
||||||
if (isset($this->search_msg_id)) {
|
if (isset($this->search_msg_id)) {
|
||||||
// 最后消息 (搜索预览消息)
|
// 最后消息 (搜索预览消息)
|
||||||
@ -118,6 +118,14 @@ class WebSocketDialog extends AbstractModel
|
|||||||
if ($basic) {
|
if ($basic) {
|
||||||
$this->name = $basic->nickname;
|
$this->name = $basic->nickname;
|
||||||
$this->bot = $basic->bot;
|
$this->bot = $basic->bot;
|
||||||
|
if ($basic->email === 'check-in@bot.system') {
|
||||||
|
$this->quick_msgs = [
|
||||||
|
[
|
||||||
|
'key' => 'checkin',
|
||||||
|
'label' => Base::Lang('我要签到')
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->name = 'non-existent';
|
$this->name = 'non-existent';
|
||||||
$this->dialog_delete = 1;
|
$this->dialog_delete = 1;
|
||||||
|
|||||||
@ -695,6 +695,17 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
}
|
}
|
||||||
$text = str_replace($matchs[0][$key], "[:{$matchChar[1]}:{$keyId}:{$matchValye[1]}:]", $text);
|
$text = str_replace($matchs[0][$key], "[:{$matchChar[1]}:{$keyId}:{$matchValye[1]}:]", $text);
|
||||||
}
|
}
|
||||||
|
// 处理快捷消息
|
||||||
|
preg_match_all("/<span[^>]*?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("/<a[^>]*?href=([\"'])(.*?)\\1[^>]*?>(.*?)<\/a>/is", $text, $matchs);
|
preg_match_all("/<a[^>]*?href=([\"'])(.*?)\\1[^>]*?>(.*?)<\/a>/is", $text, $matchs);
|
||||||
foreach ($matchs[0] as $key => $str) {
|
foreach ($matchs[0] as $key => $str) {
|
||||||
@ -734,6 +745,7 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
$text = preg_replace("/\[:@:(.*?):(.*?):\]/i", "<span class=\"mention user\" data-id=\"$1\">@$2</span>", $text);
|
$text = preg_replace("/\[:@:(.*?):(.*?):\]/i", "<span class=\"mention user\" data-id=\"$1\">@$2</span>", $text);
|
||||||
$text = preg_replace("/\[:#:(.*?):(.*?):\]/i", "<span class=\"mention task\" data-id=\"$1\">#$2</span>", $text);
|
$text = preg_replace("/\[:#:(.*?):(.*?):\]/i", "<span class=\"mention task\" data-id=\"$1\">#$2</span>", $text);
|
||||||
$text = preg_replace("/\[:~:(.*?):(.*?):\]/i", "<a class=\"mention file\" href=\"{{RemoteURL}}single/file/$1\" target=\"_blank\">~$2</a>", $text);
|
$text = preg_replace("/\[:~:(.*?):(.*?):\]/i", "<a class=\"mention file\" href=\"{{RemoteURL}}single/file/$1\" target=\"_blank\">~$2</a>", $text);
|
||||||
|
$text = preg_replace("/\[:QUICK:(.*?):(.*?):\]/i", "<span data-quick-key=\"$1\">$2</span>", $text);
|
||||||
$text = preg_replace_callback("/\[:LINK:(.*?):(.*?):\]/i", function (array $match) {
|
$text = preg_replace_callback("/\[:LINK:(.*?):(.*?):\]/i", function (array $match) {
|
||||||
return "<a href=\"" . base64_decode($match[1]) . "\" target=\"_blank\">" . base64_decode($match[2]) . "</a>";
|
return "<a href=\"" . base64_decode($match[1]) . "\" target=\"_blank\">" . base64_decode($match[2]) . "</a>";
|
||||||
}, $text);
|
}, $text);
|
||||||
|
|||||||
@ -68,9 +68,20 @@ class BotReceiveMsgTask extends AbstractTask
|
|||||||
if ($msg->type !== 'text') {
|
if ($msg->type !== 'text') {
|
||||||
return;
|
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("/<span[^>]*?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 (str_starts_with($pureText, '/')) {
|
||||||
// 管理机器人
|
|
||||||
if ($botUser->email === 'bot-manager@bot.system') {
|
if ($botUser->email === 'bot-manager@bot.system') {
|
||||||
$isManager = true;
|
$isManager = true;
|
||||||
} elseif (UserBot::whereBotId($botUser->userid)->whereUserid($msg->userid)->exists()) {
|
} 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("/^\x20+/", "", $text);
|
||||||
$text = preg_replace("/\n\x20+/", "\n", $text);
|
$text = preg_replace("/\n\x20+/", "\n", $text);
|
||||||
WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'text', ['text' => $text], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务
|
WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'text', ['text' => $text], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务
|
||||||
} elseif ($pureText) {
|
return;
|
||||||
// 推送Webhook
|
}
|
||||||
|
// 推送Webhook
|
||||||
|
if ($pureText) {
|
||||||
$userBot = UserBot::whereBotId($botUser->userid)->first();
|
$userBot = UserBot::whereBotId($botUser->userid)->first();
|
||||||
if ($userBot && preg_match("/^https*:\/\//", $userBot->webhook_url)) {
|
if ($userBot && preg_match("/^https*:\/\//", $userBot->webhook_url)) {
|
||||||
Ihttp::ihttp_post($userBot->webhook_url, [
|
Ihttp::ihttp_post($userBot->webhook_url, [
|
||||||
|
|||||||
@ -174,8 +174,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div v-else-if="quickShow" class="chat-bottom-menu">
|
<div v-else-if="quickShow" class="chat-bottom-menu">
|
||||||
<ul class="scrollbar-hidden">
|
<ul class="scrollbar-hidden">
|
||||||
<li v-for="text in quickMsg" @click.stop="sendMsg(text)">
|
<li v-for="item in quickMsgs" @click.stop="sendQuick(item)">
|
||||||
<div class="bottom-menu-desc no-dark-content">{{text}}</div>
|
<div class="bottom-menu-desc no-dark-content">{{item.label}}</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -730,12 +730,12 @@ export default {
|
|||||||
return array
|
return array
|
||||||
},
|
},
|
||||||
|
|
||||||
quickMsg() {
|
quickMsgs() {
|
||||||
return this.dialogData.quick_msg || []
|
return this.dialogData.quick_msgs || []
|
||||||
},
|
},
|
||||||
|
|
||||||
quickShow() {
|
quickShow() {
|
||||||
return this.quickMsg.length > 0 && this.windowScrollY === 0 && this.replyId === 0
|
return this.quickMsgs.length > 0 && this.windowScrollY === 0 && this.replyId === 0
|
||||||
},
|
},
|
||||||
|
|
||||||
todoList() {
|
todoList() {
|
||||||
@ -1144,6 +1144,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送快捷消息
|
||||||
|
* @param item
|
||||||
|
*/
|
||||||
|
sendQuick(item) {
|
||||||
|
this.sendMsg(`<p><span data-quick-key="${item.key}">${item.label}</span></p>`)
|
||||||
|
},
|
||||||
|
|
||||||
getMsgs(data) {
|
getMsgs(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(_ => this.msgLoadIng++, 2000)
|
setTimeout(_ => this.msgLoadIng++, 2000)
|
||||||
|
|||||||
@ -556,7 +556,7 @@
|
|||||||
.messenger-nav-item {
|
.messenger-nav-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
min-width: 90px;
|
min-width: 80px;
|
||||||
&.active {
|
&.active {
|
||||||
.nav-title {
|
.nav-title {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@ -642,4 +642,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.messenger-nav-menu {
|
||||||
|
.messenger-nav-item {
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user