From c3b9a4b82bb15cdc4c3f4da5f40579bcbb7f16d8 Mon Sep 17 00:00:00 2001 From: Il Harper Date: Fri, 23 Aug 2024 13:25:33 +0800 Subject: [PATCH] feat(shell): uix: implement `getUix2()` --- packages/shell/src/services/uix.ts | 42 ++++++++++++++++++++++++++++++ packages/shell/src/types.ts | 3 +++ 2 files changed, 45 insertions(+) diff --git a/packages/shell/src/services/uix.ts b/packages/shell/src/services/uix.ts index 5cf4c47..b9e1728 100644 --- a/packages/shell/src/services/uix.ts +++ b/packages/shell/src/services/uix.ts @@ -1,4 +1,5 @@ import { EventEmitter } from 'node:events' +import { api } from './api' const uinRegex = /\d+/ @@ -9,11 +10,14 @@ const isUin = (uin: unknown) => const isUid = (uid: unknown) => typeof uid === 'string' && uid.length === 24 && uid.startsWith('u_') +const isGroup = isUin + export class Uix extends EventEmitter { map: Record = {} isUin = isUin isUid = isUid + isGroup = isGroup add = (uid: string, uin: string) => { if (!isUid(uid) || !isUin(uin)) return @@ -23,6 +27,9 @@ export class Uix extends EventEmitter { this.emit(uid, uin) } + /** + * @deprecated + */ getUin = (uid: string) => { if (!isUid(uid)) return undefined const uin = this.map[uid] @@ -30,12 +37,47 @@ export class Uix extends EventEmitter { return uin } + getUin2 = async (uid: string, group: string | number | undefined) => { + if (!isUid(uid)) return undefined + let uin: string | undefined + if (group) { + if (!isGroup(group)) return undefined + // const groupString = `${group}` + try { + uin = await api['chronocat.internal.uix.uin.get'](uid) + // uin = await api['chronocat.internal.uix.uin.get.group'](uid, groupString) + } catch (e) { + // TODO + } + } else { + try { + uin = await api['chronocat.internal.uix.uin.get'](uid) + } catch (e) { + // TODO + } + } + if (uin) this.add(uid, uin) + return this.getUin(uid) + } + + /** + * @deprecated + */ getUid = (uin: string) => { if (!isUin(uin)) return undefined const uid = this.map[uin] if (!isUid(uid)) return undefined return uid } + + getUid2 = async (uin: string, _group: string | number | undefined) => { + if (!isUin(uin)) return undefined + // if (group) { + // if (!isGroup(group)) return undefined + // const groupString = `${group}` + // } + return this.getUid(uin) + } } export const uix = new Uix() diff --git a/packages/shell/src/types.ts b/packages/shell/src/types.ts index a1ad1b9..117279e 100644 --- a/packages/shell/src/types.ts +++ b/packages/shell/src/types.ts @@ -192,6 +192,9 @@ export interface CCInternalMethods { 'chronocat.internal.qface.get': [[string], QFace | undefined] 'chronocat.internal.qface.list': [[], QFace[] | undefined] + + 'chronocat.internal.uix.uin.get': [[string], string | undefined] + 'chronocat.internal.uix.uin.get.group': [[string, string], string | undefined] } export type Methods = SatoriMethods & CCInternalMethods