fix(onebot): preserve profile regions in user and member responses (#2107)
This commit is contained in:
1 parent
3f66b36901
commit
810052c605
4 files changed
+37
-2
No files matched your search
@@ -0,0 +1,24 @@
|
||||
/** Self-reported profile region only; never infer a location from other fields. */
|
||||
export interface ProfileRegion {
|
||||
country?: string;
|
||||
province?: string;
|
||||
city?: string;
|
||||
}
|
||||
|
||||
function text (value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : '';
|
||||
}
|
||||
|
||||
/** Keep one source together: mixing old/new components can invent a region. */
|
||||
export function selectProfileRegion (fresh?: ProfileRegion, fallback?: ProfileRegion): Required<ProfileRegion> {
|
||||
for (const source of [fresh, fallback]) {
|
||||
const region = { country: text(source?.country), province: text(source?.province), city: text(source?.city) };
|
||||
if (Object.values(region).some(Boolean)) return region;
|
||||
}
|
||||
return { country: '', province: '', city: '' };
|
||||
}
|
||||
|
||||
export function profileRegionArea (source?: ProfileRegion): string {
|
||||
const region = selectProfileRegion(source);
|
||||
return [...new Set(Object.values(region).filter(Boolean))].join(' ');
|
||||
}
|
||||
Reference in new issue
Block a user