mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-10-24 02:25:25 -05:00
Add an option to use a specific Discord client
This commit is contained in:
@@ -58,6 +58,9 @@ export function builder(yargs: Argv<ParentArguments>) {
|
||||
describe: 'Stay connected to Discord while not playing',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}).option('discord-user', {
|
||||
describe: 'Discord user ID (choose which Discord client to use when multiple are available)',
|
||||
type: 'string',
|
||||
}).option('splatnet2-monitor', {
|
||||
describe: 'Download new SplatNet 2 data when you are playing Splatoon 2 online',
|
||||
type: 'boolean',
|
||||
@@ -142,6 +145,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
DiscordPresencePlayTime.DETAILED_PLAY_TIME_SINCE;
|
||||
|
||||
i.discord_preconnect = argv.discordPreconnect;
|
||||
if (argv.discordUser) i.discord_client_filter = (client, id) => client.user.id === argv.discordUser;
|
||||
|
||||
if (argv.splatnet2Monitor) {
|
||||
const storage = await initStorage(argv.dataPath);
|
||||
@@ -208,6 +212,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
|
||||
i.presence_user = argv.friendNsaid ?? data?.nsoAccount.user.nsaId;
|
||||
i.discord_preconnect = argv.discordPreconnect;
|
||||
if (argv.discordUser) i.discord_client_filter = (client, id) => client.user.id === argv.discordUser;
|
||||
|
||||
console.warn('Authenticated as Nintendo Account %s (NA %s, NSO %s)',
|
||||
data.user.screenName, data.user.nickname, data.nsoAccount.user.name);
|
||||
|
||||
43
src/cli/util/discord-rpc.ts
Normal file
43
src/cli/util/discord-rpc.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import createDebug from 'debug';
|
||||
import type { Arguments as ParentArguments } from '../../cli.js';
|
||||
import { DiscordRpcClient, getAllIpcSockets } from '../../discord/rpc.js';
|
||||
import { defaultTitle } from '../../discord/titles.js';
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util.js';
|
||||
|
||||
const debug = createDebug('cli:util:discord-rpc');
|
||||
debug.enabled = true;
|
||||
|
||||
export const command = 'discord-rpc';
|
||||
export const desc = 'Search for Discord IPC sockets';
|
||||
|
||||
export function builder(yargs: Argv<ParentArguments>) {
|
||||
return yargs;
|
||||
}
|
||||
|
||||
type Arguments = YargsArguments<ReturnType<typeof builder>>;
|
||||
|
||||
const CLIENT_ID = defaultTitle.client;
|
||||
|
||||
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
const sockets = await getAllIpcSockets();
|
||||
|
||||
debug('Found %d Discord IPC sockets', sockets.length, sockets.map(s => s[0]));
|
||||
|
||||
for (const [id, socket] of sockets) {
|
||||
const client = new DiscordRpcClient({ transport: 'ipc', ipc_socket: socket });
|
||||
|
||||
await client.connect(CLIENT_ID);
|
||||
debug('[%d] Connected', id);
|
||||
|
||||
if (client.application) {
|
||||
debug('[%d] Application', id, client.application);
|
||||
}
|
||||
if (client.user) {
|
||||
debug('[%d] User', id, client.user);
|
||||
debug('[%d] User avatar', id,
|
||||
'https://cdn.discordapp.com/avatars/' + client.user.id + '/' + client.user.avatar + '.png');
|
||||
}
|
||||
|
||||
await client.destroy();
|
||||
}
|
||||
}
|
||||
@@ -2,3 +2,4 @@ export * as captureid from './captureid.js';
|
||||
export * as validateDiscordTitles from './validate-discord-titles.js';
|
||||
export * as exportDiscordTitles from './export-discord-titles.js';
|
||||
export * as discordActivity from './discord-activity.js';
|
||||
export * as discordRpc from './discord-rpc.js';
|
||||
|
||||
Reference in New Issue
Block a user