diff --git a/client.d.ts b/client.d.ts index a2501ab..474d7c9 100644 --- a/client.d.ts +++ b/client.d.ts @@ -77,6 +77,10 @@ export declare namespace cloud { size: bigint } } +export declare namespace friends { + export function getPersonaName(who: bigint): string + export function requestUserInformation(who: bigint): void +} export declare namespace input { export const enum InputType { Unknown = 'Unknown', diff --git a/src/api/friends.rs b/src/api/friends.rs new file mode 100644 index 0000000..f35f67d --- /dev/null +++ b/src/api/friends.rs @@ -0,0 +1,23 @@ +use napi_derive::napi; + +#[napi] +pub mod friends { + use napi::bindgen_prelude::BigInt; + use steamworks::SteamId; + + #[napi(ts_args_type="who: bigint")] + pub fn get_persona_name(who: BigInt) -> String { + let client = crate::client::get_client(); + let (_, id, _) = who.get_u64(); + let friend = client.friends().get_friend(SteamId::from_raw(id)); + friend.name() + } + + #[napi(ts_args_type="who: bigint")] + pub fn request_user_information(who: BigInt) -> () { + let client = crate::client::get_client(); + let (_, id, _) = who.get_u64(); + let steam_id = SteamId::from_raw(id); + client.friends().request_user_information(steam_id, true); + } +} diff --git a/src/api/mod.rs b/src/api/mod.rs index 22161ba..0a4e8d7 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -3,6 +3,7 @@ pub mod apps; pub mod auth; pub mod callback; pub mod cloud; +pub mod friends; pub mod input; pub mod localplayer; pub mod matchmaking; diff --git a/test/friends.js b/test/friends.js new file mode 100644 index 0000000..91e20a8 --- /dev/null +++ b/test/friends.js @@ -0,0 +1,7 @@ +const { init } = require('../index.js') + +const client = init(480) +const steamId = client.localplayer.getSteamId().steamId64 +console.log('My Steam Id: ' + steamId) +console.log(`My name: ${client.friends.getPersonaName(steamId)}`) +process.exit(0)