Skip to content

Commit

Permalink
Napcat 2.0 支持
Browse files Browse the repository at this point in the history
✨ napcat 2.0 支持,支持多分离式分组获取方式;支持分组排序信息
🐛 修正 jsonpath 解析器无法拉取列表的问题
💄 脚本列表样式修改
💩 去除了独立回复消息字段支持的旧代码
📄 direnv、asdf 配置文件补充,移除 nvm 配置文件
  • Loading branch information
Stapxs committed Aug 21, 2024
1 parent 75d7979 commit c64592d
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 83 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export PYTHON_PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin/python
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 18.18.2
8 changes: 4 additions & 4 deletions src/assets/css/append/append_new.css
Original file line number Diff line number Diff line change
Expand Up @@ -652,20 +652,20 @@
}
.script-view .list > header > span {
margin: 10px -5px 0 -5px;
font-size: 0.8rem;
font-size: 0.75rem;
}
.script-view .list-body {
margin: 0 -5px;
}
.script-view .list-body h2 {
font-size: 0.9rem;
font-size: 0.8rem;
}
.script-view .list-body span {
font-size: 0.8rem;
font-size: 0.75rem;
}
.script-view .list-body span svg {
margin: 0;
font-size: 0.75rem;
font-size: 0.7rem;
}
.script-view .editor-main {
box-shadow: -5px 0px 4px -5px var(--color-shader);
Expand Down
15 changes: 12 additions & 3 deletions src/assets/pathMap/NapCat.Onebot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ login_info:
# 群、好友列表
friend_list:
name: get_friends_with_category
source: $.data[*]
source: $.data[*].buddyList[*]
list:
class_id: /categoryId
class_name: /categroyName
class_id: null
class_name: null
user_id: /user_id
nickname: /nickname
remark: /remark
Expand All @@ -31,6 +31,15 @@ group_list:
group_name: /group_name
member_count: /member_count
admin_flag: null
# 好友分组
friend_category:
name: get_friends_with_category
source: $.data[*]
list:
class_id: /categoryId
class_name: /categoryName
sort_id: /categorySortId
users: $.buddyList[*].user_id
# 消息列表
message_list:
name: get_group_msg_history
Expand Down
4 changes: 2 additions & 2 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ app.on('ready', async () => {
if (isDevelopment && !process.env.IS_TEST) {
try {
await installExtension('nhdogjmejiglipccpnnnanhbledajbpd')
} catch (e: any) {
console.error('Vue Devtools failed to install:', e.toString())
} catch (e: unknown) {
console.error('Vue Devtools failed to install:', (e as Error).toString())
}
}
createWindow()
Expand Down
35 changes: 1 addition & 34 deletions src/components/MsgBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
{{ isMe ? runtimeData.loginInfo.nickname : runtimeData.chatInfo.show.name }}
</a>
<div>
<!-- 回复指示框(独立版本) -->
<div v-if="data.source && data.source.seq" :class="isMe ? (type == 'merge' ? 'msg-replay' : 'msg-replay me') : 'msg-replay'"
@click="scrollToMsg(data.source.seq)">
<font-awesome-icon :icon="['fas', 'reply']" />
<a> {{ getRepInfo((data.source ? data.source.message : ''), data) }} </a>
</div>
<!-- 消息体 -->
<template v-if="!hasCard()">
<div v-for="(item, index) in data.message" :class="View.isMsgInline(item.type) ? 'msg-inline' : ''" :key="data.message_id + '-m-' + index">
Expand All @@ -44,7 +38,7 @@
<img v-else-if="item.type == 'mface' && item.url" @load="scrollButtom" @error="imgLoadFail" :class="imgStyle(data.message.length, index, item.asface) + ' msg-mface'" :src="item.url">
<span v-else-if="item.type == 'mface' && item.text" class="msg-unknown">{{ item.text }}</span>
<span v-else-if="item.type == 'bface'" style="font-style: italic;opacity: 0.7;">[ {{ $t('chat_fun_menu_pic') }}:{{ item.text }} ]</span>
<div v-else-if="item.type == 'at'" v-show="isAtShow(data.source, item.qq)" :class="getAtClass(item.qq)">
<div v-else-if="item.type == 'at'" :class="getAtClass(item.qq)">
<a @mouseenter="showUserInfo" :data-id="item.qq" :data-group="data.group_id">{{ getAtName(item) }}</a>
</div>
<div v-else-if="item.type == 'file'" :class="'msg-file' + (isMe ? ' me' : '')">
Expand Down Expand Up @@ -174,18 +168,6 @@ export default defineComponent({
return getMsgRawTxt(message)
},

/**
* 判断是否需要隐藏重复的 At
* @param source 回复信息
* @param at at 信息
*/
isAtShow (source: any, at: any) {
if (source) {
return !(at === source.user_id)
}
return true
},

/**
* 根据消息状态获取 At 消息实际的 CSS class
* @param who
Expand Down Expand Up @@ -423,21 +405,6 @@ export default defineComponent({
}
},

/**
* 获取回复内容(拼接名字和消息内容)
* @param msg 消息对象
* @param data 回复信息
*/
getRepInfo (msg: any, data: any) {
const list = this.runtimeData.chatInfo.info.group_members.filter((item) => {
return Number(item.user_id) === Number(data.source.user_id)
})
if (list.length === 1) {
return (list[0].card !== '' ? list[0].card : list[0].nickname) + ': ' + msg
}
return msg
},

/**
* 尝试在消息列表中寻找这条被回复的消息,获取消息内容
* @param message_id
Expand Down
2 changes: 1 addition & 1 deletion src/function/electron/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function regIpcListener() {
})
// 获取补充的调试信息
ipcMain.handle('opt:getSystemInfo', () => {
const systemInfo = {} as { [key: string]: any }
const systemInfo = {} as { [key: string]: [string, string] }
systemInfo.electron = ['Electron Version', process.versions.electron]
return systemInfo
})
Expand Down
63 changes: 56 additions & 7 deletions src/function/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { GroupMemberInfoElem, UserFriendElem, UserGroupElem, MsgItemElem, RunTim
import { NotificationElem } from './elements/system'
import { IPinyinOptions } from 'pinyin/lib/declare'

const logger = new Logger()
const popInfo = new PopInfo()
// eslint-disable-next-line
let msgPath = require('@/assets/pathMap/Lagrange.OneBot.yaml')
Expand All @@ -52,6 +51,7 @@ export function parse(str: string) {
case 'getMoreLoginInfo' : runtimeData.loginInfo.info = msg.data.data.result.buddy.info_list[0]; break
case 'getGroupList' : saveUser(msg, 'group'); break
case 'getFriendList' : saveUser(msg, 'friend'); break
case 'getFriendCategory' : saveClassInfoAlone(msg); break
case 'getUserInfoInGroup' : runtimeData.chatInfo.info.me_info = msg; break
case 'getGroupMemberList' : saveGroupMember(msg.data); break
case 'getChatHistoryFist' : saveMsg(msg, 'top'); break
Expand Down Expand Up @@ -245,9 +245,23 @@ function saveUser(msg: { [key: string]: any }, type: string) {
switch(type) {
case 'friend':
list = getMsgData('friend_list', msg, msgPath.friend_list)
if(list)
// 根据 user_id 去重
list = list.filter((item, index, arr) => {
return arr.findIndex((item2) => {
return item2.user_id == item.user_id
}) == index
})
break
case 'group':
list = getMsgData('group_list', msg, msgPath.group_list)
if(list)
// 根据 group_id 去重
list = list.filter((item, index, arr) => {
return arr.findIndex((item2) => {
return item2.group_id == item.group_id
}) == index
})
break
}
}
Expand Down Expand Up @@ -324,6 +338,10 @@ function saveUser(msg: { [key: string]: any }, type: string) {
if(runtimeData.jsonMap.recent_contact)
Connector.send(runtimeData.jsonMap.recent_contact.name, {}, 'GetRecentContact')
}
// 如果是分离式的好友列表,继续获取分类信息
if(type == 'friend' && runtimeData.jsonMap.friend_category) {
Connector.send(runtimeData.jsonMap.friend_category.name, {}, 'getFriendCategory')
}
}

function updateTopMsg(msg: any, echoList: string[]) {
Expand All @@ -349,7 +367,29 @@ function updateTopMsg(msg: any, echoList: string[]) {
}
}

function saveClassInfo(list: { class_id: number, class_name: string }[]) {
function saveClassInfoAlone(msg: any) {
const list = getMsgData('friend_category', msg, msgPath.friend_category) as {
class_id: number,
class_name: string,
sort_id: number,
users: number[]
}[]
if (list != undefined) {
saveClassInfo(list)
}
// 刷新用户列表的分类信息
list.forEach((item) => {
item.users.forEach((id) => {
runtimeData.userList.forEach((user) => {
if (user.user_id == id && user.class_id == undefined) {
user.class_id = item.class_id
user.class_name = item.class_name
}
})
})
})
}
function saveClassInfo(list: { class_id: number, class_name: string, sort_id?: number }[]) {
// 按拼音重新排序
// const names = [] as string[]
// list.forEach((item) => {
Expand All @@ -365,12 +405,21 @@ function saveClassInfo(list: { class_id: number, class_name: string }[]) {
// })
// })

// 按 class_id 排序
const back = list.sort((a, b) => {
return a.class_id - b.class_id
})
if(list[0].sort_id != undefined) {
// 如果有 sort_id,按 sort_id 排序,从小到大
list.sort((a, b) => {
if(a.sort_id && b.sort_id)
return a.sort_id - b.sort_id
else return 0
})
} else {
// 按 class_id 排序
list.sort((a, b) => {
return a.class_id - b.class_id
})
}

runtimeData.tags.classes = back
runtimeData.tags.classes = list
}

function saveGroupMember(data: GroupMemberInfoElem[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/function/utils/msgUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function getMsgData(name: string, msg: { [key: string]: any }, map: strin
nameKey = name
regexKey = key
}
itemObj[key] = jp.query(item, replaceJPValue(nameKey))[0]
itemObj[key] = jp.query(item, replaceJPValue(nameKey))
if(regexKey != null) {
const regex = new RegExp(regexKey)
const match = itemObj[key].match(regex)
Expand Down
Loading

0 comments on commit c64592d

Please sign in to comment.