mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-22 07:07:53 +00:00
feat(shell): uix: implement getUix2()
This commit is contained in:
parent
ab26d18813
commit
c3b9a4b82b
@ -1,4 +1,5 @@
|
|||||||
import { EventEmitter } from 'node:events'
|
import { EventEmitter } from 'node:events'
|
||||||
|
import { api } from './api'
|
||||||
|
|
||||||
const uinRegex = /\d+/
|
const uinRegex = /\d+/
|
||||||
|
|
||||||
@ -9,11 +10,14 @@ const isUin = (uin: unknown) =>
|
|||||||
const isUid = (uid: unknown) =>
|
const isUid = (uid: unknown) =>
|
||||||
typeof uid === 'string' && uid.length === 24 && uid.startsWith('u_')
|
typeof uid === 'string' && uid.length === 24 && uid.startsWith('u_')
|
||||||
|
|
||||||
|
const isGroup = isUin
|
||||||
|
|
||||||
export class Uix extends EventEmitter {
|
export class Uix extends EventEmitter {
|
||||||
map: Record<string, string> = {}
|
map: Record<string, string> = {}
|
||||||
|
|
||||||
isUin = isUin
|
isUin = isUin
|
||||||
isUid = isUid
|
isUid = isUid
|
||||||
|
isGroup = isGroup
|
||||||
|
|
||||||
add = (uid: string, uin: string) => {
|
add = (uid: string, uin: string) => {
|
||||||
if (!isUid(uid) || !isUin(uin)) return
|
if (!isUid(uid) || !isUin(uin)) return
|
||||||
@ -23,6 +27,9 @@ export class Uix extends EventEmitter {
|
|||||||
this.emit(uid, uin)
|
this.emit(uid, uin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
getUin = (uid: string) => {
|
getUin = (uid: string) => {
|
||||||
if (!isUid(uid)) return undefined
|
if (!isUid(uid)) return undefined
|
||||||
const uin = this.map[uid]
|
const uin = this.map[uid]
|
||||||
@ -30,12 +37,47 @@ export class Uix extends EventEmitter {
|
|||||||
return uin
|
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) => {
|
getUid = (uin: string) => {
|
||||||
if (!isUin(uin)) return undefined
|
if (!isUin(uin)) return undefined
|
||||||
const uid = this.map[uin]
|
const uid = this.map[uin]
|
||||||
if (!isUid(uid)) return undefined
|
if (!isUid(uid)) return undefined
|
||||||
return uid
|
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()
|
export const uix = new Uix()
|
||||||
|
@ -192,6 +192,9 @@ export interface CCInternalMethods {
|
|||||||
|
|
||||||
'chronocat.internal.qface.get': [[string], QFace | undefined]
|
'chronocat.internal.qface.get': [[string], QFace | undefined]
|
||||||
'chronocat.internal.qface.list': [[], 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
|
export type Methods = SatoriMethods & CCInternalMethods
|
||||||
|
Loading…
Reference in New Issue
Block a user