Add Discord applications for most Nintendo titles

This commit is contained in:
Samuel Elliott
2022-04-21 15:29:06 +01:00
parent 8decef8dda
commit 3f73570096
7 changed files with 1119 additions and 112 deletions

View File

@@ -16,7 +16,7 @@ Access the Nintendo Switch Online and Nintendo Switch Parental Controls app APIs
- Fetch presence from a custom URL
- All titles are supported using a default Nintendo Switch app. A limited number of titles have their own
Discord apps (meaning they appear under your name with the title's name instead of "Nintendo Switch")
or other custom Discord features. [See here for Discord title overrides](src/discord/titles.ts) or
or other custom Discord features. [See here for Discord title overrides](src/discord/titles) or
[create an issue if you'd like another title added](https://github.com/samuelthomas2774/nxapi/issues/new/choose).
![Screenshot showing Splatoon 2 as a Discord activity](resources/Screenshot%202022-03-31%20at%2017.56.47%203.png)

View File

@@ -1,4 +1,5 @@
import { Title } from './util.js';
import * as publishers from './titles/index.js';
export const defaultTitle: Title = {
id: '0000000000000000',
@@ -8,112 +9,12 @@ export const defaultTitle: Title = {
showActiveEvent: true,
};
const titles: Title[] = [
{
// Splatoon 2 [Europe]
id: '0100f8f0000a2000',
client: '950886725398429726',
largeImageKey: '0100f8f0000a2000',
showPlayingOnline: true,
showActiveEvent: true,
},
{
// Splatoon 2 [The Americas]
id: '01003bc0000a0000',
client: '950886725398429726',
largeImageKey: '0100f8f0000a2000',
showPlayingOnline: true,
showActiveEvent: true,
},
{
// Splatoon 2 [Japan]
id: '01003c700009c000',
client: '950886725398429726',
largeImageKey: '01003c700009c000',
showPlayingOnline: true,
showActiveEvent: true,
},
export const titles: Title[] = [];
{
// Super Smash Bros. Ultimate
id: '01006a800016e000',
client: '950894516104212490',
largeImageKey: '01006a800016e000',
showActiveEvent: true,
},
for (const [publisher, m] of Object.entries(publishers)) {
if (!('titles' in m)) continue;
{
// Mario Kart 8 Deluxe
id: '0100152000022000',
client: '950905573149409280',
largeImageKey: '0100152000022000',
showActiveEvent: true,
},
{
// Super Mario Odyssey
id: '0100000000010000',
client: '950905939899351050',
largeImageKey: '0100000000010000',
},
{
// Minecraft
id: '0100d71004694000',
client: '950906152391168020',
largeImageKey: '0100d71004694000',
},
{
// Minecraft: Nintendo Switch Edition
id: '01006bd001e06000',
client: '950906152391168020',
largeImageKey: '01006bd001e06000',
},
{
// Nintendo Entertainment System - Nintendo Switch Online
id: '0100d870045b6000',
client: '950907272438104064',
titleName: 'Nintendo Entertainment System',
largeImageKey: '0100d870045b6000',
},
{
// Super Nintendo Entertainment System - Nintendo Switch Online
id: '01008d300c50c000',
client: '950907272438104064',
titleName: 'Super Nintendo Entertainment System',
largeImageKey: '01008d300c50c000',
},
{
// Nintendo 64 - Nintendo Switch Online
id: '0100c9a00ece6000',
client: '950907272438104064',
titleName: 'Nintendo 64',
largeImageKey: '0100c9a00ece6000',
},
{
// SEGA Mega Drive - Nintendo Switch Online
id: '0100b3c014bda000',
client: '950907272438104064',
titleName: 'SEGA Mega Drive',
largeImageKey: '0100b3c014bda000',
},
{
// Animal Crossing: New Horizons
id: '01006f8002326000',
client: '950908097235415079',
largeImageKey: '01006f8002326000',
showPlayingOnline: true,
showActiveEvent: true,
},
{
// Animal Crossing: New Horizons Island Transfer Tool
id: '0100f38011cfe000',
client: '950908097235415079',
titleName: 'Island Transfer Tool',
largeImageKey: '0100f38011cfe000',
},
];
export default titles;
for (const title of m.titles) {
titles.push(title);
}
}

View File

@@ -0,0 +1,4 @@
Title overrides for Discord activities
---
This directory contains custom configuration for titles. The default configuration for all other titles is in [src/discord/titles.ts](../titles.ts). This is used by [src/discord/util.ts](../util.ts) (which also declares the type for title configuration objects) to convert znc presences to Discord activities.

View File

@@ -0,0 +1,2 @@
export * as nintendo from './nintendo.js';
export * as mojang from './mojang.js';

View File

@@ -0,0 +1,16 @@
import { Title } from '../util.js';
export const titles: Title[] = [
{
// Minecraft
id: '0100d71004694000',
client: '950906152391168020',
largeImageKey: '0100d71004694000',
},
{
// Minecraft: Nintendo Switch Edition
id: '01006bd001e06000',
client: '950906152391168020',
largeImageKey: '01006bd001e06000',
},
];

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
import DiscordRPC from 'discord-rpc';
import { ActiveEvent, CurrentUser, Game, PresenceState } from '../api/znc-types.js';
import titles, { defaultTitle } from './titles.js';
import { defaultTitle, titles } from './titles.js';
import { getTitleIdFromEcUrl, hrduration } from '../util.js';
import { ZncDiscordPresence } from '../cli/nso/presence.js';
@@ -103,18 +103,56 @@ export function getTitleConfiguration(game: Game, id: string) {
}
export interface Title {
/** Lowercase hexadecimal title ID */
/**
* Lowercase hexadecimal title ID.
*
* Valid title IDs are 16 characters long, and should start with `0100` and end with `0000`, `2000`, `4000`, `6000`, `8000`, `a000`, `c000`, `e000` (this is because applications have 4^16 title IDs for the application itself, plus addon content and update data).
*/
id: string;
/** Discord client ID */
/**
* Discord client ID
*/
client: string;
/**
* Title name to show in Discord. This is *not* the name that will appear under the user's name after "Playing ".
*
* If this is set to true the title's name from znc will be used.
* If this is set to false (default) no title name will be set. This should be used when a specific Discord client for the title is used.
* If this is set to a string it will be used as the title name.
*
* @default false
*/
titleName?: string | boolean;
/**
* By default the title's icon from znc will be used. (No icons need to be uploaded to Discord.)
*/
largeImageKey?: string;
/**
* By default this will not be set.
*/
smallImageKey?: string;
/**
* Whether to show the timestamp the user started playing the title in Discord. Discord shows this as the number of minutes and seconds since the timestamp; this will be inaccurate as it may take up to a minute (by default) to detect the user's presence, so this is disabled by default.
*
* @default false
*/
showTimestamp?: boolean;
/** Show "Playing online" if playing online and the game doesn't set activity details */
/**
* Show "Playing online" if playing online and the game doesn't set activity details.
*
* @default false
*/
showPlayingOnline?: string | boolean;
/**
* Whether to show details of the current event (Online Lounge/voice chat) in Discord.
*
* @default false
*/
showActiveEvent?: boolean;
/**
* A function to call to customise the Discord activity.
*/
callback?: (activity: DiscordRPC.Presence, game: Game, context?: DiscordPresenceContext) => void;
}