@39choko/lanyard 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 39Choko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @39choko/lanyard
2
+
3
+ <div align="center">
4
+ <p>
5
+ <a href="https://www.npmjs.com/package/@39choko/lanyard"><img src="https://img.shields.io/npm/v/@39choko/lanyard.svg?maxAge=3600" alt="npm version" /></a>
6
+ <a href="https://www.npmjs.com/package/@39choko/lanyard"><img src="https://img.shields.io/npm/dt/@39choko/lanyard.svg?maxAge=3600" alt="npm downloads" /></a>
7
+ <a href="https://github.com/39Choko/lanyard/commits/main/"><img alt="Last commit." src="https://img.shields.io/github/last-commit/39Choko/lanyard?logo=github&logoColor=ffffff">
8
+ </p>
9
+ </div>
10
+
11
+ ## About
12
+
13
+ @39choko/lanyard is a [npm](https://www.npmjs.com/) package that allows you to interacting with [Lanyard](https://github.com/Phineas/lanyard).
14
+
15
+ ## Installation
16
+
17
+ ```sh
18
+ npm install @39choko/lanyard
19
+ yarn add @39choko/lanyard
20
+ pnpm add @39choko/lanyard
21
+ bun add @39choko/lanyard
22
+ deno install npm:@39choko/lanyard
23
+ ```
24
+
25
+ ## Example usage
26
+
27
+ ```ts
28
+ import { Client } from '@39choko/lanyard';
29
+
30
+ const client = new Client();
31
+ ```
32
+
33
+ ### Example
34
+
35
+ Getting User Info
36
+
37
+ ```ts
38
+ const user = await client.user.getUser("826467976484094023");
39
+ if (!user.success) return throw Error("Failed to fetch user.")
40
+
41
+ console.log(user.data);
42
+ ```
43
+
44
+ Getting User display name
45
+
46
+ ```ts
47
+ const avatarURL = await client.user.getAvatarURL("826467976484094023");
48
+ if (!avatarURL) return throw Error("Failed to fetch the avatar url.")
49
+
50
+ console.log(avatarURL); // "https://cdn.discordapp.com/avatars/826467976484094023/e4479e082bb156a6f004fb3b34d678ac.png"
51
+ ```
52
+
53
+ Getting User platform status
54
+
55
+ ```ts
56
+ const platformStatus = await client.user.getPlatformStatus("826467976484094023");
57
+ if (!platformStatus) return throw Error("Failed to fetch the platform status.")
58
+
59
+ console.log(platformStatus); // ["desktop", "mobile"]
60
+ ```
61
+
62
+ ## Links
63
+
64
+ - [npm](https://www.npmjs.com/package/@39choko/lanyard)
65
+ - [Lanyard](https://github.com/Phineas/lanyard)
66
+
67
+ ## More
68
+
69
+ If you want to contribute to this repo please make a pull request or dm me on discord (39choko / 826467976484094023)
@@ -0,0 +1,10 @@
1
+ import { Client } from "../client/Client";
2
+ import { APIResponse, UserData } from "../types";
3
+ export declare class Users {
4
+ private client;
5
+ constructor(client: Client);
6
+ getUser(userId: string): Promise<APIResponse<UserData>>;
7
+ getDisplayName(userId: string): Promise<string | null>;
8
+ getAvatarURL(userId: string): Promise<string | null>;
9
+ getPlatformStatus(userId: string): Promise<string[] | null>;
10
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
+ var Users_exports = {};
17
+ __export(Users_exports, {
18
+ Users: () => Users
19
+ });
20
+ module.exports = __toCommonJS(Users_exports);
21
+ class Users {
22
+ constructor(client) {
23
+ this.client = client;
24
+ }
25
+ async getUser(userId) {
26
+ const request = await this.client.request(`users/${userId}`);
27
+ return request.success === !1, request;
28
+ }
29
+ async getDisplayName(userId) {
30
+ const userRequest = await this.getUser(userId);
31
+ return userRequest.success === !1 ? null : userRequest.data.discord_user.display_name;
32
+ }
33
+ async getAvatarURL(userId) {
34
+ const userRequest = await this.getUser(userId);
35
+ if (userRequest.success === !1)
36
+ return null;
37
+ const avatarHash = userRequest.data.discord_user.avatar;
38
+ return `https://cdn.discordapp.com/avatars/${userId}/${avatarHash}.png`;
39
+ }
40
+ async getPlatformStatus(userId) {
41
+ const userRequest = await this.getUser(userId), platform = [];
42
+ if (userRequest.success === !1)
43
+ return null;
44
+ const data = userRequest.data;
45
+ return data.active_on_discord_desktop && platform.push("desktop"), data.active_on_discord_mobile && platform.push("mobile"), data.active_on_discord_web && platform.push("web"), data.active_on_discord_embedded && platform.push("embedded"), platform;
46
+ }
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ Users
51
+ });
@@ -0,0 +1,30 @@
1
+ class Users {
2
+ constructor(client) {
3
+ this.client = client;
4
+ }
5
+ async getUser(userId) {
6
+ const request = await this.client.request(`users/${userId}`);
7
+ return request.success === !1, request;
8
+ }
9
+ async getDisplayName(userId) {
10
+ const userRequest = await this.getUser(userId);
11
+ return userRequest.success === !1 ? null : userRequest.data.discord_user.display_name;
12
+ }
13
+ async getAvatarURL(userId) {
14
+ const userRequest = await this.getUser(userId);
15
+ if (userRequest.success === !1)
16
+ return null;
17
+ const avatarHash = userRequest.data.discord_user.avatar;
18
+ return `https://cdn.discordapp.com/avatars/${userId}/${avatarHash}.png`;
19
+ }
20
+ async getPlatformStatus(userId) {
21
+ const userRequest = await this.getUser(userId), platform = [];
22
+ if (userRequest.success === !1)
23
+ return null;
24
+ const data = userRequest.data;
25
+ return data.active_on_discord_desktop && platform.push("desktop"), data.active_on_discord_mobile && platform.push("mobile"), data.active_on_discord_web && platform.push("web"), data.active_on_discord_embedded && platform.push("embedded"), platform;
26
+ }
27
+ }
28
+ export {
29
+ Users
30
+ };
@@ -0,0 +1,10 @@
1
+ import { Users } from "../api/Users";
2
+ import { APIResponse, ClientOptions } from "../types";
3
+ export declare class Client {
4
+ private readonly baseURL;
5
+ private readonly userAgent;
6
+ readonly users: Users;
7
+ constructor(options?: ClientOptions);
8
+ request<T>(endpoint?: string): Promise<APIResponse<T>>;
9
+ getUserAgent(): string | undefined;
10
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
+ var Client_exports = {};
17
+ __export(Client_exports, {
18
+ Client: () => Client
19
+ });
20
+ module.exports = __toCommonJS(Client_exports);
21
+ var import_Users = require('../api/Users.js');
22
+ class Client {
23
+ constructor(options) {
24
+ this.baseURL = "https://api.lanyard.rest/v1";
25
+ options?.userAgent && (this.userAgent = options.userAgent), this.users = new import_Users.Users(this);
26
+ }
27
+ async request(endpoint) {
28
+ const headers = {};
29
+ this.userAgent && (headers["User-Agent"] = this.userAgent);
30
+ const finalEndpoint = endpoint ?? "", result = await fetch(`${this.baseURL}/${finalEndpoint}`, {
31
+ headers
32
+ });
33
+ return result.ok ? await result.json() : await result.json();
34
+ }
35
+ getUserAgent() {
36
+ return this.userAgent;
37
+ }
38
+ }
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ Client
42
+ });
@@ -0,0 +1,21 @@
1
+ import { Users } from "../api/Users.mjs";
2
+ class Client {
3
+ constructor(options) {
4
+ this.baseURL = "https://api.lanyard.rest/v1";
5
+ options?.userAgent && (this.userAgent = options.userAgent), this.users = new Users(this);
6
+ }
7
+ async request(endpoint) {
8
+ const headers = {};
9
+ this.userAgent && (headers["User-Agent"] = this.userAgent);
10
+ const finalEndpoint = endpoint ?? "", result = await fetch(`${this.baseURL}/${finalEndpoint}`, {
11
+ headers
12
+ });
13
+ return result.ok ? await result.json() : await result.json();
14
+ }
15
+ getUserAgent() {
16
+ return this.userAgent;
17
+ }
18
+ }
19
+ export {
20
+ Client
21
+ };
@@ -0,0 +1 @@
1
+ export * from "./client/Client";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from == "object" || typeof from == "function")
8
+ for (let key of __getOwnPropNames(from))
9
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ return to;
11
+ }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
12
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
13
+ var index_exports = {};
14
+ module.exports = __toCommonJS(index_exports);
15
+ __reExport(index_exports, require('./client/Client.js'), module.exports);
16
+ // Annotate the CommonJS export names for ESM import in node:
17
+ 0 && (module.exports = {
18
+ ...require('./client/Client.js')
19
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export * from "./client/Client.mjs";
@@ -0,0 +1,115 @@
1
+ export interface ClientOptions {
2
+ userAgent?: string;
3
+ }
4
+ export interface ErrorResponse {
5
+ error: {
6
+ code: string;
7
+ message: string;
8
+ };
9
+ success: false;
10
+ }
11
+ export interface SuccessResponse<T> {
12
+ data: T;
13
+ success: true;
14
+ }
15
+ export type APIResponse<T> = SuccessResponse<T> | ErrorResponse;
16
+ export interface RootData {
17
+ info: string;
18
+ monitored_user_count: number;
19
+ discord_invite: string;
20
+ }
21
+ export interface UserData {
22
+ kv: {
23
+ [key: string]: string;
24
+ };
25
+ discord_user: {
26
+ avatar: string | null;
27
+ avatar_decoration: AvatarDecoration | null;
28
+ bot: boolean;
29
+ collectibles: Collectibles | null;
30
+ discriminator: string;
31
+ display_name: string;
32
+ display_name_styles: DisplayNameStyles | null;
33
+ global_name: string;
34
+ id: string;
35
+ primary_guild: PrimaryGuild | null;
36
+ public_flags: number;
37
+ username: string;
38
+ };
39
+ activities: Activity[] | [];
40
+ discord_status: "online" | "idle" | "dnd" | "offline";
41
+ active_on_discord_web: boolean;
42
+ active_on_discord_mobile: boolean;
43
+ active_on_discord_desktop: boolean;
44
+ active_on_discord_embedded: boolean;
45
+ listening_to_spotify: boolean;
46
+ spotify: SpotifyData | null;
47
+ }
48
+ export interface AvatarDecoration {
49
+ asset: string;
50
+ expire_at: number | null;
51
+ sku_id: string;
52
+ }
53
+ export interface Collectibles {
54
+ nameplate: {
55
+ asset: string;
56
+ expire_at: number | null;
57
+ label: string;
58
+ palette: string;
59
+ sku_id: string;
60
+ };
61
+ }
62
+ export interface DisplayNameStyles {
63
+ color: number[];
64
+ effect_id: number;
65
+ font_id: number;
66
+ }
67
+ export interface PrimaryGuild {
68
+ badge: string;
69
+ identity_enabled: boolean;
70
+ identity_guild_id: string;
71
+ tag: string;
72
+ }
73
+ export interface Activity {
74
+ application_id?: string;
75
+ asserts?: Partial<Record<"large_image" | "large_text" | "large_url" | "small_image" | "small_text" | "small_url", string>>;
76
+ buttons?: string[] | GatewayActivityButton[];
77
+ created_at: number;
78
+ details?: null | string;
79
+ details_url?: null | string;
80
+ flags?: number;
81
+ id: string;
82
+ instance?: boolean;
83
+ name: string;
84
+ party?: {
85
+ id?: string;
86
+ size?: [current_size: number, max_size: number];
87
+ };
88
+ platform?: string;
89
+ secrets?: Partial<Record<"join" | "match" | "spectate", string>>;
90
+ session_id?: string;
91
+ state?: null | string;
92
+ status_display_type?: null | number;
93
+ sync_id?: string;
94
+ timestamps?: {
95
+ end?: number;
96
+ start?: number;
97
+ };
98
+ type: number;
99
+ url: null | string;
100
+ }
101
+ export interface GatewayActivityButton {
102
+ id: string;
103
+ url: string;
104
+ }
105
+ export interface SpotifyData {
106
+ track_id: string;
107
+ timestamps: {
108
+ start: number;
109
+ end: number;
110
+ };
111
+ song: string;
112
+ artist: string;
113
+ album: string;
114
+ album_art_url: string;
115
+ }
package/dist/types.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from == "object" || typeof from == "function")
8
+ for (let key of __getOwnPropNames(from))
9
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ return to;
11
+ };
12
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
13
+ var types_exports = {};
14
+ module.exports = __toCommonJS(types_exports);
package/dist/types.mjs ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@39choko/lanyard",
3
+ "description": "A simple Lanyard client.",
4
+ "version": "1.0.0",
5
+ "homepage": "https://github.com/39Choko/lanyard",
6
+ "bugs": "https://github.com/39Choko/lanyard/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/39Choko/lanyard.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "provenance": true
14
+ },
15
+ "license": "MIT",
16
+ "author": {
17
+ "name": "39Choko",
18
+ "url": "https://github.com/39Choko"
19
+ },
20
+ "main": "./dist/index.js",
21
+ "module": "./dist/index.mjs",
22
+ "types": "./dist/index.d.ts",
23
+ "scripts": {
24
+ "prettier": "bunx prettier --write .",
25
+ "test": "bun test",
26
+ "build": "bun build.ts",
27
+ "release": "bun run prettier && bun run build && bun run test && bun publish"
28
+ },
29
+ "exports": {
30
+ "./package.json": "./package.json",
31
+ ".": {
32
+ "import": "./dist/index.mjs",
33
+ "require": "./dist/index.js",
34
+ "types": "./dist/index.d.ts"
35
+ },
36
+ "./client": {
37
+ "import": "./dist/client/index.mjs",
38
+ "require": "./dist/client/index.js",
39
+ "types": "./dist/client/index.d.ts"
40
+ },
41
+ "./api": {
42
+ "import": "./dist/api/index.mjs",
43
+ "require": "./dist/api/index.js",
44
+ "types": "./dist/api/index.d.ts"
45
+ },
46
+ "./types": {
47
+ "types": "./dist/types.d.ts",
48
+ "import": "./dist/types.mjs",
49
+ "require": "./dist/types.js"
50
+ }
51
+ },
52
+ "keywords": [
53
+ "discord",
54
+ "lanyard",
55
+ "presence"
56
+ ],
57
+ "devDependencies": {
58
+ "@39choko/prettier-config": "^1.0.2",
59
+ "@types/bun": "latest",
60
+ "esbuild-fix-imports-plugin": "^1.0.23",
61
+ "prettier": "^3.7.4",
62
+ "tsup": "^8.5.1"
63
+ },
64
+ "peerDependencies": {
65
+ "@types/bun": "latest",
66
+ "typescript": "^5"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "@types/bun": {
70
+ "optional": true
71
+ },
72
+ "typescript": {
73
+ "optional": true
74
+ }
75
+ }
76
+ }