mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-16 12:51:39 +00:00
feat(shell): add uix svc
This commit is contained in:
parent
93aa0b9bcb
commit
fd187e84b3
@ -10,6 +10,7 @@ import type { ChronocatLogCurrentConfig } from './services/config/configEntity'
|
||||
import { emitter } from './services/emitter'
|
||||
import { l } from './services/logger'
|
||||
import { getSelfProfile, setSelfProfile } from './services/selfProfile'
|
||||
import { uix } from './services/uix'
|
||||
import { validate } from './services/validate'
|
||||
import type { ChronocatContext, Engine } from './types'
|
||||
import { PLATFORM } from './utils/consts'
|
||||
@ -39,6 +40,7 @@ export const chronocat = async () => {
|
||||
getSelfProfile,
|
||||
l,
|
||||
platform: PLATFORM,
|
||||
uix,
|
||||
validate,
|
||||
whenReady: () => readyPromise,
|
||||
},
|
||||
|
37
packages/shell/src/services/uix.ts
Normal file
37
packages/shell/src/services/uix.ts
Normal file
@ -0,0 +1,37 @@
|
||||
const uinRegex = /\d+/
|
||||
|
||||
const isUin = (uin: unknown) => typeof uin === 'string' && uinRegex.test(uin)
|
||||
|
||||
const isUid = (uid: unknown) =>
|
||||
typeof uid === 'string' && uid.length === 24 && uid.startsWith('u_')
|
||||
|
||||
const map: Record<string, string> = {}
|
||||
|
||||
const add = (uid: string, uin: string) => {
|
||||
if (!uid || !uin) return
|
||||
map[uid] = uin
|
||||
map[uin] = uid
|
||||
}
|
||||
|
||||
const getUin = (uid: string) => {
|
||||
if (!isUid(uid)) return undefined
|
||||
const uin = map[uid]
|
||||
if (!isUin(uin)) return undefined
|
||||
return uin
|
||||
}
|
||||
|
||||
const getUid = (uin: string) => {
|
||||
if (!isUin(uin)) return undefined
|
||||
const uid = map[uin]
|
||||
if (!isUid(uid)) return undefined
|
||||
return uid
|
||||
}
|
||||
|
||||
export const uix = {
|
||||
map,
|
||||
add,
|
||||
isUin,
|
||||
isUid,
|
||||
getUin,
|
||||
getUid,
|
||||
}
|
@ -10,6 +10,7 @@ import type {
|
||||
} from './services/config/configEntity'
|
||||
import type { l } from './services/logger'
|
||||
import type { getSelfProfile } from './services/selfProfile'
|
||||
import type { uix } from './services/uix'
|
||||
import type { validate } from './services/validate'
|
||||
import type { PLATFORM } from './utils/consts'
|
||||
|
||||
@ -23,6 +24,7 @@ export interface ChronocatContext {
|
||||
getSelfProfile: typeof getSelfProfile
|
||||
l: typeof l
|
||||
platform: typeof PLATFORM
|
||||
uix: typeof uix
|
||||
validate: typeof validate
|
||||
whenReady: () => Promise<void>
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user