Update approximate play time, date format in Discord activities

This commit is contained in:
Samuel Elliott 2025-08-01 21:51:09 +01:00
parent 2ddac1619f
commit d00c988220
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 11 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import Table from '../../util/table.js';
import { PresenceState } from '../../api/coral-types.js';
import { PresencePlatform, PresenceState } from '../../api/coral-types.js';
import type { Arguments as ParentArguments } from './index.js';
import createDebug from '../../util/debug.js';
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
@ -83,9 +83,13 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
friend.name,
online ?
'name' in friend.presence.game ?
'Playing ' + friend.presence.game.name + ';\nplayed for ' +
'Playing ' + friend.presence.game.name +
('platform' in friend.presence ?
friend.presence.platform === PresencePlatform.NX ? ' (Nintendo Switch)' :
friend.presence.platform === PresencePlatform.OUNCE ? ' (Nintendo Switch 2)' : '' : '') +
';\nplayed for ' +
hrduration(friend.presence.game.totalPlayTime) + ' since ' +
new Date(friend.presence.game.firstPlayedAt * 1000).toLocaleDateString('en-GB') :
new Date(friend.presence.game.firstPlayedAt * 1000).toISOString() :
'Online' :
friend.presence.state === PresenceState.INACTIVE ?
'Console online' + (friend.presence.logoutAt ?

View File

@ -120,7 +120,8 @@ function getPlayTimeText(type: DiscordPresencePlayTime, game: PresenceGame) {
if (type === DiscordPresencePlayTime.HIDDEN || game.totalPlayTime < 0) return null;
const since = game.firstPlayedAt ? new Date(game.firstPlayedAt * 1000).toLocaleDateString('en-GB') : 'now';
const since = game.firstPlayedAt ? new Date(game.firstPlayedAt * 1000)
.toLocaleDateString('en-GB', {dateStyle: 'medium'}) : 'now';
switch (type) {
case DiscordPresencePlayTime.APPROXIMATE_PLAY_TIME:
@ -160,8 +161,8 @@ function getFirstPlayedText(first_played_at: number) {
}
function getApproximatePlayTime(minutes: number) {
if (minutes < 300) {
// Less than 5 hours
if (minutes < 600) {
// Less than 10 hours
return Math.floor(minutes / 60) * 60;
} else {
return Math.floor(minutes / 300) * 300;