mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-10-19 08:07:44 -05:00
Add home, settings, history, schedules and battle history types
This commit is contained in:
85
src/cli/splatnet3/battles.ts
Normal file
85
src/cli/splatnet3/battles.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import createDebug from 'debug';
|
||||
import Table from '../util/table.js';
|
||||
import type { Arguments as ParentArguments } from '../splatnet3.js';
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
|
||||
import { initStorage } from '../../util/storage.js';
|
||||
import { getBulletToken } from '../../common/auth/splatnet3.js';
|
||||
import { Judgement } from '../../api/splatnet3-types.js';
|
||||
|
||||
const debug = createDebug('cli:splatnet3:battles');
|
||||
|
||||
export const command = 'battles';
|
||||
export const desc = 'List the last 50 regular/ranked/private/festival battles';
|
||||
|
||||
export function builder(yargs: Argv<ParentArguments>) {
|
||||
return yargs.option('user', {
|
||||
describe: 'Nintendo Account ID',
|
||||
type: 'string',
|
||||
}).option('token', {
|
||||
describe: 'Nintendo Account session token',
|
||||
type: 'string',
|
||||
}).option('json', {
|
||||
describe: 'Output raw JSON',
|
||||
type: 'boolean',
|
||||
}).option('json-pretty-print', {
|
||||
describe: 'Output pretty-printed JSON',
|
||||
type: 'boolean',
|
||||
});
|
||||
}
|
||||
|
||||
type Arguments = YargsArguments<ReturnType<typeof builder>>;
|
||||
|
||||
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
const storage = await initStorage(argv.dataPath);
|
||||
|
||||
const usernsid = argv.user ?? await storage.getItem('SelectedUser');
|
||||
const token: string = argv.token ||
|
||||
await storage.getItem('NintendoAccountToken.' + usernsid);
|
||||
const {splatnet} = await getBulletToken(storage, token, argv.zncProxyUrl, argv.autoUpdateSession);
|
||||
|
||||
const results = await splatnet.getLatestBattleHistories();
|
||||
|
||||
if (argv.jsonPrettyPrint) {
|
||||
console.log(JSON.stringify(results.data, null, 4));
|
||||
return;
|
||||
}
|
||||
if (argv.json) {
|
||||
console.log(JSON.stringify(results.data));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Summary', results.data.latestBattleHistories.summary);
|
||||
|
||||
const table = new Table({
|
||||
head: [
|
||||
'ID',
|
||||
'Mode',
|
||||
'Rule',
|
||||
'Stage',
|
||||
'Result',
|
||||
],
|
||||
});
|
||||
|
||||
for (const group of results.data.latestBattleHistories.historyGroups.nodes) {
|
||||
for (const result of group.historyDetails.nodes) {
|
||||
const match = Buffer.from(result.id, 'base64').toString().match(/^VsHistoryDetail-(u-[0-9a-z]{20}):RECENT:((\d+T\d+)_([0-9a-f-]+))$/);
|
||||
const id_str = match ? match[2] : result.id;
|
||||
|
||||
table.push([
|
||||
id_str,
|
||||
(result.vsMode.mode === 'REGULAR' ? '\u001b[32m' :
|
||||
// result.vsMode.mode === 'ranked' ? '\u001b[33m' :
|
||||
// result.vsMode.mode === 'league' ? '\u001b[31m' :
|
||||
// result.vsMode.mode === 'private' ? '\u001b[35m' :
|
||||
'') +
|
||||
result.vsMode.mode + '\u001b[0m',
|
||||
result.vsRule.name,
|
||||
result.vsStage.name,
|
||||
(result.judgement === Judgement.WIN ? '\u001b[32m' : '\u001b[31m') +
|
||||
result.judgement + '\u001b[0m',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(table.toString());
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * as user from './user.js';
|
||||
export * as token from './token.js';
|
||||
export * as schedule from './schedule.js';
|
||||
export * as battles from './battles.js';
|
||||
|
||||
@@ -39,11 +39,11 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
const schedules = await splatnet.getSchedules();
|
||||
|
||||
if (argv.jsonPrettyPrint) {
|
||||
console.log(JSON.stringify(schedules, null, 4));
|
||||
console.log(JSON.stringify(schedules.data, null, 4));
|
||||
return;
|
||||
}
|
||||
if (argv.json) {
|
||||
console.log(JSON.stringify(schedules));
|
||||
console.log(JSON.stringify(schedules.data));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
await storage.getItem('NintendoAccountToken.' + usernsid);
|
||||
const {splatnet, data} = await getBulletToken(storage, token, argv.zncProxyUrl, argv.autoUpdateSession);
|
||||
|
||||
const history: any = await splatnet.getHistoryRecords();
|
||||
const history = await splatnet.getHistoryRecords();
|
||||
|
||||
console.log('Player %s#%s (title %s, first played %s)',
|
||||
history.data.currentPlayer.name,
|
||||
|
||||
Reference in New Issue
Block a user