mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-07 18:07:05 +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->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;
|
||||
|
||||
@ -695,6 +695,17 @@ class WebSocketDialogMsg extends AbstractModel
|
||||
}
|
||||
$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);
|
||||
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 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("/\[:QUICK:(.*?):(.*?):\]/i", "<span data-quick-key=\"$1\">$2</span>", $text);
|
||||
$text = preg_replace_callback("/\[:LINK:(.*?):(.*?):\]/i", function (array $match) {
|
||||
return "<a href=\"" . base64_decode($match[1]) . "\" target=\"_blank\">" . base64_decode($match[2]) . "</a>";
|
||||
}, $text);
|
||||
|
||||
@ -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("/<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 ($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, [
|
||||
|
||||
@ -174,8 +174,8 @@
|
||||
</div>
|
||||
<div v-else-if="quickShow" class="chat-bottom-menu">
|
||||
<ul class="scrollbar-hidden">
|
||||
<li v-for="text in quickMsg" @click.stop="sendMsg(text)">
|
||||
<div class="bottom-menu-desc no-dark-content">{{text}}</div>
|
||||
<li v-for="item in quickMsgs" @click.stop="sendQuick(item)">
|
||||
<div class="bottom-menu-desc no-dark-content">{{item.label}}</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -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(`<p><span data-quick-key="${item.key}">${item.label}</span></p>`)
|
||||
},
|
||||
|
||||
getMsgs(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(_ => this.msgLoadIng++, 2000)
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user