diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/manaplus/manaplus.ts | 1 | ||||
-rw-r--r-- | src/main/richpresence.ts | 99 | ||||
-rw-r--r-- | src/main/status.ts | 10 |
3 files changed, 85 insertions, 25 deletions
diff --git a/src/main/manaplus/manaplus.ts b/src/main/manaplus/manaplus.ts index 5de7d01..7573c84 100644 --- a/src/main/manaplus/manaplus.ts +++ b/src/main/manaplus/manaplus.ts @@ -90,6 +90,7 @@ please check you network connection first.", e.message, "Launch preparation fail EventEmitter.emit('openTray'); await runManaProgram(params,ManaPlusInstance.startCommand,args.address); // On Close + Status.setGameStatus({server: "Launcher"}) Status.setGameRunning(false); Status.setPlaying(false); Status.removeActivity(); diff --git a/src/main/richpresence.ts b/src/main/richpresence.ts index 4ef8f42..93d9f9a 100644 --- a/src/main/richpresence.ts +++ b/src/main/richpresence.ts @@ -1,32 +1,65 @@ -// Only for testing as of right now -const DiscordRPC = require('discord-rpc'); +import {Status} from './status'; +// Only for testing as of right now -> Experimental +const ClientId = '551884486351126528'; +const DiscordRPC = require('discord-rich-presence')(ClientId); -const ClientId = '447258715586822154'; +const slogans = [ + 'free OpenSource 2D MMORPG', + 'Community made', + 'Join a Server or start your own' +] +const dataSet: +{[key:string]:{name:string, logo:string, description:string}} = { + 'server.tmw2.org':{ + name: 'Moubootaur Legends', + logo: 'tmw2', + description: 'Playing on Moubootaur Legends ⎛tmw2.org⎠' + }, + 'world.evolonline.org':{ + name: 'Evol Online', + logo: 'evol', + description: 'Playing on Evol Online ⎛evolonline.org⎠' + }, + 'server.themanaworld.org':{ + name: 'The Mana World', + logo: 'tmw', + description: 'Playing on The Mana World ⎛themanaworld.org⎠' + }, + 'noServer':{ + name: 'Manaplus', + logo: 'manaplus', + description: 'Playing on any of the M+ servers' + } + } -DiscordRPC.register(ClientId); +async function setActivity() { + const status = Status.getStatus() -const rpc = new DiscordRPC.Client({ transport: 'ipc' }); -const startTimestamp = new Date(); + const slogan = slogans[Math.floor(Math.random() * slogans.length)] -async function setActivity() { - if (!rpc) - return false; - - rpc.setActivity({ - details: `booped times`, - startTimestamp, - largeImageKey: 'connect', - largeImageText: 'Currently on map xy', - // smallImageKey: 'snek_small', - // smallImageText: 'i am my own pillows', - partySize:2, //TODO get online players - partyMax:999, - partyId:"ae488379-351d-4a4f-ad32-2b9b01c91657", - joinSecret:"MTI4NzM0OjFpMmhuZToxMjMxMjM=" + const data = dataSet[status.gameStatus.server] + + const details = status.gameStatus.server === 'Launcher' ? 'in Launcher Menu' : `🎮 ${data.name} 🎮` + const logo = data && data.logo + + DiscordRPC.updatePresence({ + state: `»${slogan}«`, + details, + largeImageKey: logo, + largeImageText: data && data.description, + //smallImageKey: , + //smallImageText: 'string', + //partyId: 'ae488379-351d-4a4f-ad32-2b9b01c91657', + //partySize: 1, + //partyMax: 999, + //matchSecret: 'string', + //joinSecret: 'string', + //spectateSecret: 'string', + //startTimestamp }); } -rpc.on('ready', () => { +DiscordRPC.on('connected', () => { setActivity(); // activity can only be set every 15 seconds @@ -35,11 +68,27 @@ rpc.on('ready', () => { }, 15e3); }); -rpc.login(ClientId).catch(console.error); +DiscordRPC.on("error", console.log); -rpc.subscribe("",console.log); +DiscordRPC.on('join', (secret:string) => { + console.log('we should join with', secret); +}); + +DiscordRPC.on('spectate', (secret:string) => { + console.log('we should spectate with', secret); +}); + +// DiscordRPC.on('joinRequest', (user) => { +// if (user.discriminator === '1337') { +// DiscordRPC.reply(user, 'YES'); +// } else { +// DiscordRPC.reply(user, 'IGNORE'); +// } +// }); export function quit(){ - rpc.destroy(); + DiscordRPC.disconnect(); console.log("Shutting down Discord RPC integration"); } + +process.on('unhandledRejection', console.error);
\ No newline at end of file diff --git a/src/main/status.ts b/src/main/status.ts index fb99b35..2e59d0f 100644 --- a/src/main/status.ts +++ b/src/main/status.ts @@ -7,6 +7,9 @@ type STATUS = { ActivityIsError:boolean, playing:boolean, gameRunning:boolean, + gameStatus:{ + server: string + } } const status:STATUS = { @@ -15,6 +18,9 @@ const status:STATUS = { playing:false, //Is manaplus starting or started ActivityIsError:false, gameRunning:false, + gameStatus: { + server: "Launcher" + } } export namespace Status { @@ -50,6 +56,10 @@ export namespace Status { status.playing=playing; updateStatus(); } + export function setGameStatus(gameStatus:{ server: string }){ + status.gameStatus=gameStatus; + updateStatus(); + } export function getStatus():STATUS{ return status; } |