Skip to content

Commit e1f2734

Browse files
committed
feat: add total warning on peak command
1 parent 83ecc35 commit e1f2734

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

assets/locales/en/commands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
},
198198
"peak": [
199199
"📊 Peak day for **{{displayName}}**",
200-
"🔥 **{{peakDate}}** - {{totalScrobbles}} scrobbles",
200+
"🔥 **{{peakDate}}** - {{totalScrobbles}} scrobbles ({{listeningHours}}h in a single day) {{-totalSirenEmoji}}",
201201
"📅 Period: {{period}}",
202202
"\n🎵 Top tracks that day:",
203203
"{{- topTracks}}",

src/commands/commands/targetable/peak.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ export default async (ctx: Context) => {
8080
? ctx.t('commands:peak.moreData')
8181
: ''
8282

83+
const totalSirenEmoji = cachedData.totalIsSuspicious ? '🚨 ' : ''
84+
const listeningHours = ((cachedData.totalScrobbles * 3) / 60).toFixed(1)
85+
8386
ctx.reply('commands:peak', {
8487
displayName,
8588
peakDate: format(new Date(cachedData.date), 'MMMM dd, yyyy'),
89+
totalSirenEmoji,
8690
totalScrobbles: cachedData.totalScrobbles,
91+
listeningHours,
8792
period: getPeriodLabel(period),
8893
topTracks: cachedData.topTracks,
8994
topArtists: cachedData.topArtists,
@@ -213,40 +218,49 @@ export default async (ctx: Context) => {
213218
Array.from(peakDay.artists.values()).some(a => isSuspicious(a)) ||
214219
Array.from(peakDay.albums.values()).some(a => isSuspicious(a.count))
215220

216-
const suspiciousHours = hasSuspicious
221+
const totalIsSuspicious = isSuspicious(peakDay.totalScrobbles)
222+
223+
const suspiciousHours = hasSuspicious || totalIsSuspicious
217224
? Math.max(
218225
...Array.from(peakDay.tracks.values()).map(t => (t.count * 3) / 60),
219226
...Array.from(peakDay.artists.values()).map(a => (a * 3) / 60),
220-
...Array.from(peakDay.albums.values()).map(a => (a.count * 3) / 60)
227+
...Array.from(peakDay.albums.values()).map(a => (a.count * 3) / 60),
228+
(peakDay.totalScrobbles * 3) / 60
221229
)
222230
: 0
223231

224232
const resultData = {
225233
date: peakDay.date,
226234
totalScrobbles: peakDay.totalScrobbles,
235+
totalIsSuspicious,
227236
topTracks,
228237
topArtists,
229238
topAlbums,
230-
hasSuspicious,
239+
hasSuspicious: hasSuspicious || totalIsSuspicious,
231240
suspiciousHours,
232241
hasMorePages
233242
}
234243

235244
const ttl = period === 'overall' ? 60 * 60 * 6 : 60 * 60
236245
await backend?.setTTL(cacheKey, JSON.stringify(resultData), ttl)
237246

238-
const wandaVisionWarning = hasSuspicious
247+
const wandaVisionWarning = (hasSuspicious || totalIsSuspicious)
239248
? ctx.t('commands:peak.wandaVision', { hours: suspiciousHours.toFixed(1) })
240249
: ''
241250

242251
const moreDataNote = hasMorePages
243252
? ctx.t('commands:peak.moreData')
244253
: ''
245254

255+
const totalSirenEmoji = totalIsSuspicious ? '🚨 ' : ''
256+
const listeningHours = ((peakDay.totalScrobbles * 3) / 60).toFixed(1)
257+
246258
ctx.reply('commands:peak', {
247259
displayName,
248260
peakDate: format(new Date(peakDay.date), 'MMMM dd, yyyy'),
261+
totalSirenEmoji,
249262
totalScrobbles: peakDay.totalScrobbles,
263+
listeningHours,
250264
period: getPeriodLabel(period),
251265
topTracks,
252266
topArtists,

0 commit comments

Comments
 (0)