mirror of
https://github.com/aljazceru/mcp-code.git
synced 2025-12-18 05:05:17 +01:00
refactor and add list_snippets
This commit is contained in:
44
lib/converters/users.ts
Normal file
44
lib/converters/users.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { ndk } from "../../ndk.js";
|
||||
import { knownUsers } from "../../users.js";
|
||||
import { queryUser } from "../../users.js";
|
||||
|
||||
/**
|
||||
* Converts an identifier (pubkey, npub, or name) to pubkeys
|
||||
* @param identifier The identifier to convert
|
||||
* @returns Array of pubkeys
|
||||
*/
|
||||
export function toPubkeys(identifier: string): string[] {
|
||||
// If it's an npub, convert directly
|
||||
if (identifier.startsWith("npub")) {
|
||||
return [ndk.getUser({ npub: identifier }).pubkey];
|
||||
}
|
||||
|
||||
// If it's a hex pubkey, return as is
|
||||
if (identifier.length === 64 && /^[0-9a-f]+$/i.test(identifier)) {
|
||||
return [identifier];
|
||||
}
|
||||
|
||||
// Otherwise, search by profile name or other attributes
|
||||
return queryUser(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format user profile data for display
|
||||
* @param pubkey User public key
|
||||
* @returns Formatted string representation
|
||||
*/
|
||||
export function formatUser(pubkey: string): string {
|
||||
const profile = knownUsers[pubkey]?.profile;
|
||||
const user = ndk.getUser({ pubkey });
|
||||
const keys: Record<string, string> = {
|
||||
Npub: user.npub,
|
||||
};
|
||||
|
||||
if (profile?.name) keys.Name = profile.name;
|
||||
if (profile?.about) keys.About = profile.about;
|
||||
if (profile?.picture) keys.Picture = profile.picture;
|
||||
|
||||
return Object.entries(keys)
|
||||
.map(([key, value]) => `${key}: ${value}`)
|
||||
.join("\n");
|
||||
}
|
||||
Reference in New Issue
Block a user