Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
23 changes: 23 additions & 0 deletions src/api/friends.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/friends.js
Original file line number Diff line number Diff line change
@@ -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)