mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-04-21 14:37:59 -05:00
Add aliases for --splatnet2-monitor-* options and don't require setting a directory for downloading Parental Controls and SplatNet 2 data
This commit is contained in:
parent
085d8a6a54
commit
74c6f71a76
|
|
@ -37,36 +37,49 @@ export function builder(yargs: Argv<ParentArguments>) {
|
|||
describe: 'Update interval in seconds',
|
||||
type: 'number',
|
||||
default: 30,
|
||||
}).option('splatnet2-monitor', {
|
||||
describe: 'Download new SplatNet 2 data when you are playing Splatoon 2 online',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}).option('splatnet2-monitor-directory', {
|
||||
alias: ['sn2-path'],
|
||||
describe: 'Directory to write SplatNet 2 record data to',
|
||||
type: 'string',
|
||||
}).option('splatnet2-monitor-profile-image', {
|
||||
alias: ['sn2-profile-image'],
|
||||
describe: 'Include profile image',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}).option('splatnet2-monitor-favourite-stage', {
|
||||
alias: ['sn2-favourite-stage'],
|
||||
describe: 'Favourite stage to include on profile image',
|
||||
type: 'string',
|
||||
}).option('splatnet2-monitor-favourite-colour', {
|
||||
alias: ['sn2-favourite-colour'],
|
||||
describe: 'Favourite colour to include on profile image',
|
||||
type: 'string',
|
||||
}).option('splatnet2-monitor-battles', {
|
||||
alias: ['sn2-battles'],
|
||||
describe: 'Include regular/ranked/private/festival battle results',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
}).option('splatnet2-monitor-battle-summary-image', {
|
||||
alias: ['sn2-battle-summary-image'],
|
||||
describe: 'Include regular/ranked/private/festival battle summary image',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}).option('splatnet2-monitor-battle-images', {
|
||||
alias: ['sn2-battle-images'],
|
||||
describe: 'Include regular/ranked/private/festival battle result images',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}).option('splatnet2-monitor-coop', {
|
||||
alias: ['sn2-coop'],
|
||||
describe: 'Include coop (Salmon Run) results',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
}).option('splatnet2-monitor-update-interval', {
|
||||
alias: ['sn2-update-interval'],
|
||||
describe: 'Update interval in seconds',
|
||||
type: 'number',
|
||||
// 3 minutes - the monitor is only active while the authenticated user is playing Splatoon 2 online
|
||||
|
|
@ -77,7 +90,7 @@ export function builder(yargs: Argv<ParentArguments>) {
|
|||
type Arguments = YargsArguments<ReturnType<typeof builder>>;
|
||||
|
||||
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
if (!argv.userNotifications && !argv.friendNotifications && !argv.splatnet2MonitorDirectory) {
|
||||
if (!argv.userNotifications && !argv.friendNotifications && !argv.splatnet2Monitor) {
|
||||
throw new Error('Must enable either user notifications, friend notifications, or SplatNet 2 monitoring');
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +106,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
|||
console.warn('Authenticated as Nintendo Account %s (NA %s, NSO %s)',
|
||||
data.user.screenName, data.user.nickname, data.nsoAccount.user.name);
|
||||
|
||||
if (argv.splatnet2MonitorDirectory) {
|
||||
if (argv.splatnet2Monitor) {
|
||||
console.warn('SplatNet 2 monitoring enabled for %s (NA %s, NSO %s) - SplatNet 2 records will be ' +
|
||||
'downloaded when this user is playing Splatoon 2 online.',
|
||||
data.user.screenName, data.user.nickname, data.nsoAccount.user.name);
|
||||
|
|
@ -446,12 +459,14 @@ export function handleEnableSplatNet2Monitoring(
|
|||
argv: ArgumentsCamelCase<Arguments>, storage: persist.LocalStorage, token: string
|
||||
) {
|
||||
return async () => {
|
||||
const directory = argv.splatnet2MonitorDirectory ?? path.join(argv.dataPath, 'splatnet2');
|
||||
|
||||
const {splatnet, data} = await getIksmToken(storage, token, argv.zncProxyUrl);
|
||||
|
||||
const records = await splatnet.getRecords();
|
||||
const stages = await splatnet.getStages();
|
||||
|
||||
const i = new EmbeddedSplatNet2Monitor(storage, token, splatnet, stages, argv.splatnet2MonitorDirectory!, argv.zncProxyUrl);
|
||||
const i = new EmbeddedSplatNet2Monitor(storage, token, splatnet, stages, directory, argv.zncProxyUrl);
|
||||
|
||||
i.update_interval = argv.splatnet2MonitorUpdateInterval;
|
||||
|
||||
|
|
|
|||
|
|
@ -51,36 +51,49 @@ export function builder(yargs: Argv<ParentArguments>) {
|
|||
}).option('presence-url', {
|
||||
describe: 'URL to get user presence from, for use with `nxapi nso http-server`',
|
||||
type: 'string',
|
||||
}).option('splatnet2-monitor', {
|
||||
describe: 'Download new SplatNet 2 data when you are playing Splatoon 2 online',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}).option('splatnet2-monitor-directory', {
|
||||
alias: ['sn2-path'],
|
||||
describe: 'Directory to write SplatNet 2 record data to',
|
||||
type: 'string',
|
||||
}).option('splatnet2-monitor-profile-image', {
|
||||
alias: ['sn2-profile-image'],
|
||||
describe: 'Include profile image',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}).option('splatnet2-monitor-favourite-stage', {
|
||||
alias: ['sn2-favourite-stage'],
|
||||
describe: 'Favourite stage to include on profile image',
|
||||
type: 'string',
|
||||
}).option('splatnet2-monitor-favourite-colour', {
|
||||
alias: ['sn2-favourite-colour'],
|
||||
describe: 'Favourite colour to include on profile image',
|
||||
type: 'string',
|
||||
}).option('splatnet2-monitor-battles', {
|
||||
alias: ['sn2-battles'],
|
||||
describe: 'Include regular/ranked/private/festival battle results',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
}).option('splatnet2-monitor-battle-summary-image', {
|
||||
alias: ['sn2-battle-summary-image'],
|
||||
describe: 'Include regular/ranked/private/festival battle summary image',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}).option('splatnet2-monitor-battle-images', {
|
||||
alias: ['sn2-battle-images'],
|
||||
describe: 'Include regular/ranked/private/festival battle result images',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}).option('splatnet2-monitor-coop', {
|
||||
alias: ['sn2-coop'],
|
||||
describe: 'Include coop (Salmon Run) results',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
}).option('splatnet2-monitor-update-interval', {
|
||||
alias: ['sn2-update-interval'],
|
||||
describe: 'Update interval in seconds',
|
||||
type: 'number',
|
||||
// 3 minutes - the monitor is only active while the authenticated user is playing Splatoon 2 online
|
||||
|
|
@ -98,7 +111,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
|||
|
||||
const i = new ZncProxyDiscordPresence(argv, argv.presenceUrl);
|
||||
|
||||
if (argv.splatnet2MonitorDirectory) {
|
||||
if (argv.splatnet2Monitor) {
|
||||
const storage = await initStorage(argv.dataPath);
|
||||
|
||||
const usernsid = argv.user ?? await storage.getItem('SelectedUser');
|
||||
|
|
@ -142,7 +155,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
|||
console.warn('Authenticated as Nintendo Account %s (NA %s, NSO %s)',
|
||||
data.user.screenName, data.user.nickname, data.nsoAccount.user.name);
|
||||
|
||||
if (argv.splatnet2MonitorDirectory) {
|
||||
if (argv.splatnet2Monitor) {
|
||||
if (argv.friendNsaid) {
|
||||
console.warn('SplatNet 2 monitoring is enabled, but --friend-nsaid is set. SplatNet 2 records will only be downloaded when the authenticated user is playing Splatoon 2 online, regardless of the --friend-nsaid user.');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,13 @@ import MoonApi from '../../api/moon.js';
|
|||
|
||||
const debug = createDebug('cli:pctl:dump-summaries');
|
||||
|
||||
export const command = 'dump-summaries <directory>';
|
||||
export const command = 'dump-summaries [directory]';
|
||||
export const desc = 'Download all daily and monthly summaries';
|
||||
|
||||
export function builder(yargs: Argv<ParentArguments>) {
|
||||
return yargs.positional('directory', {
|
||||
describe: 'Directory to write summary data to',
|
||||
type: 'string',
|
||||
demandOption: true,
|
||||
}).option('user', {
|
||||
describe: 'Nintendo Account ID',
|
||||
type: 'string',
|
||||
|
|
@ -39,7 +38,9 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
|||
await storage.getItem('NintendoAccountToken-pctl.' + usernsid);
|
||||
const {moon, data} = await getPctlToken(storage, token);
|
||||
|
||||
await mkdirp(argv.directory);
|
||||
const directory = argv.directory ?? path.join(argv.dataPath, 'summaries');
|
||||
|
||||
await mkdirp(directory);
|
||||
|
||||
const devices = await moon.getDevices();
|
||||
|
||||
|
|
@ -54,8 +55,8 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
|||
|
||||
console.warn('Downloading summaries for device %s (%s)', device.label, device.deviceId);
|
||||
|
||||
await dumpMonthlySummariesForDevice(moon, argv.directory, device.deviceId);
|
||||
await dumpDailySummariesForDevice(moon, argv.directory, device.deviceId);
|
||||
await dumpMonthlySummariesForDevice(moon, directory, device.deviceId);
|
||||
await dumpDailySummariesForDevice(moon, directory, device.deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,14 +12,13 @@ import { Challenge, NicknameAndIcon, Records, Stages } from '../../api/splatnet2
|
|||
|
||||
const debug = createDebug('cli:splatnet2:dump-records');
|
||||
|
||||
export const command = 'dump-records <directory>';
|
||||
export const command = 'dump-records [directory]';
|
||||
export const desc = 'Download all other records';
|
||||
|
||||
export function builder(yargs: Argv<ParentArguments>) {
|
||||
return yargs.positional('directory', {
|
||||
describe: 'Directory to write record data to',
|
||||
type: 'string',
|
||||
demandOption: true,
|
||||
}).option('user', {
|
||||
describe: 'Nintendo Account ID',
|
||||
type: 'string',
|
||||
|
|
@ -69,7 +68,9 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
|||
await storage.getItem('NintendoAccountToken.' + usernsid);
|
||||
const {splatnet} = await getIksmToken(storage, token, argv.zncProxyUrl, argv.autoUpdateSession);
|
||||
|
||||
await mkdirp(argv.directory);
|
||||
const directory = argv.directory ?? path.join(argv.dataPath, 'splatnet2');
|
||||
|
||||
await mkdirp(directory);
|
||||
|
||||
const [records, stages, activefestivals, timeline] = await Promise.all([
|
||||
splatnet.getRecords(),
|
||||
|
|
@ -82,30 +83,30 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
|||
const updated = argv.newRecords ? new Date(records.records.update_time * 1000) : undefined;
|
||||
|
||||
if (argv.userRecords) {
|
||||
await dumpRecords(argv.directory, records.records.unique_id, records,
|
||||
await dumpRecords(directory, records.records.unique_id, records,
|
||||
nickname_and_icons.nickname_and_icons[0], updated);
|
||||
}
|
||||
|
||||
if (argv.profileImage) {
|
||||
await dumpProfileImage(splatnet, argv.directory, records.records.unique_id, stages,
|
||||
await dumpProfileImage(splatnet, directory, records.records.unique_id, stages,
|
||||
nickname_and_icons.nickname_and_icons[0],
|
||||
argv.favouriteStage, argv.favouriteColour, updated);
|
||||
}
|
||||
|
||||
if (argv.challenges) {
|
||||
await dumpChallenges(splatnet, argv.directory, records.records.unique_id,
|
||||
await dumpChallenges(splatnet, directory, records.records.unique_id,
|
||||
records.challenges.archived_challenges, 1);
|
||||
await dumpChallenges(splatnet, argv.directory, records.records.unique_id,
|
||||
await dumpChallenges(splatnet, directory, records.records.unique_id,
|
||||
records.challenges.archived_challenges_octa, 2);
|
||||
}
|
||||
|
||||
if (argv.heroRecords) {
|
||||
await dumpHeroRecords(splatnet, argv.directory, records.records.unique_id);
|
||||
await dumpHeroRecords(splatnet, directory, records.records.unique_id);
|
||||
}
|
||||
|
||||
if (argv.timeline) {
|
||||
const filename = 'splatnet2-timeline-' + records.records.unique_id + '-' + Date.now() + '.json';
|
||||
const file = path.join(argv.directory, filename);
|
||||
const file = path.join(directory, filename);
|
||||
|
||||
debug('Writing timeline %s', filename);
|
||||
await fs.writeFile(file, JSON.stringify(timeline, null, 4) + '\n', 'utf-8');
|
||||
|
|
|
|||
|
|
@ -11,14 +11,13 @@ import fetch from 'node-fetch';
|
|||
|
||||
const debug = createDebug('cli:splatnet2:dump-results');
|
||||
|
||||
export const command = 'dump-results <directory>';
|
||||
export const command = 'dump-results [directory]';
|
||||
export const desc = 'Download all battle and coop results';
|
||||
|
||||
export function builder(yargs: Argv<ParentArguments>) {
|
||||
return yargs.positional('directory', {
|
||||
describe: 'Directory to write record data to',
|
||||
type: 'string',
|
||||
demandOption: true,
|
||||
}).option('user', {
|
||||
describe: 'Nintendo Account ID',
|
||||
type: 'string',
|
||||
|
|
@ -58,18 +57,20 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
|||
await storage.getItem('NintendoAccountToken.' + usernsid);
|
||||
const {splatnet} = await getIksmToken(storage, token, argv.zncProxyUrl, argv.autoUpdateSession);
|
||||
|
||||
await mkdirp(argv.directory);
|
||||
const directory = argv.directory ?? path.join(argv.dataPath, 'splatnet2');
|
||||
|
||||
await mkdirp(directory);
|
||||
|
||||
const updated = argv.checkUpdated ? new Date((await splatnet.getRecords()).records.update_time * 1000) : undefined;
|
||||
|
||||
const records = await splatnet.getRecords();
|
||||
|
||||
if (argv.battles) {
|
||||
await dumpResults(splatnet, argv.directory, records.records.unique_id,
|
||||
await dumpResults(splatnet, directory, records.records.unique_id,
|
||||
argv.battleImages, argv.battleSummaryImage, updated);
|
||||
}
|
||||
if (argv.coop) {
|
||||
await dumpCoopResults(splatnet, argv.directory, records.records.unique_id, updated);
|
||||
await dumpCoopResults(splatnet, directory, records.records.unique_id, updated);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user