Skip to content

Commit

Permalink
refactor: 解耦合 icqq
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Jul 10, 2024
1 parent d90ba10 commit 07e6194
Show file tree
Hide file tree
Showing 33 changed files with 879 additions and 793 deletions.
1 change: 1 addition & 0 deletions main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"log4js": "^6.9.1",
"markdown-escape": "^2.0.0",
"nodejs-base64": "^2.0.0",
"posthog-node": "^4.0.1",
"prisma": "5.16.2",
"probe-image-size": "^7.2.3",
"prompts": "^2.4.2",
Expand Down
27 changes: 17 additions & 10 deletions main/src/api/richHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { FastifyPluginCallback } from 'fastify';
import { Pair } from '../models/Pair';
import ejs from 'ejs';
import fs from 'fs';
import { Group } from '@icqqjs/icqq';
import { Group as OicqGroup, Member as OicqMember } from '@icqqjs/icqq';
import { format } from 'date-and-time';
import { Group, GroupMemberInfo } from '../client/QQClient';

const template = ejs.compile(fs.readFileSync('./assets/richHeader.ejs', 'utf-8'));

Expand All @@ -17,25 +18,31 @@ export default ((fastify, opts, done) => {
return 'Group not found';
}
const group = pair.qq as Group;
const members = await group.getMemberMap();
const member = members.get(Number(request.params.userId));
const member = group.pickMember(Number(request.params.userId), true);
if (!member) {
reply.code(404);
return 'Member not found';
}
const profile = await pair.qq.client.getProfile(member.user_id);
const profile = group instanceof OicqGroup ? await group.client.getProfile(member.uid) : ({} as any); // TODO
let memberInfo: GroupMemberInfo;
if (member instanceof OicqMember) {
memberInfo = member.info;
}
if (!memberInfo) {
memberInfo = {} as any;
}

reply.type('text/html');
return template({
userId: request.params.userId,
title: member.title,
name: member.card || member.nickname,
role: member.role,
joinTime: format(new Date(member.join_time * 1000), 'YYYY-MM-DD HH:mm'),
lastSentTime: format(new Date(member.last_sent_time * 1000), 'YYYY-MM-DD HH:mm'),
title: memberInfo.title,
name: memberInfo.card || memberInfo.nickname,
role: memberInfo.role,
joinTime: format(new Date(memberInfo.join_time * 1000), 'YYYY-MM-DD HH:mm'),
lastSentTime: format(new Date(memberInfo.last_sent_time * 1000), 'YYYY-MM-DD HH:mm'),
regTime: format(new Date(profile.regTimestamp * 1000), 'YYYY-MM-DD HH:mm'),
location: [profile.country, profile.province, profile.city].join(' ').trim(),
nickname: member.nickname,
nickname: memberInfo.nickname,
email: profile.email,
qid: profile.QID,
signature: profile.signature,
Expand Down
Loading

0 comments on commit 07e6194

Please sign in to comment.