Skip to content

Commit

Permalink
feat(lastfm): notify switch disabled/online/all
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Sep 5, 2022
1 parent 43aca95 commit f814cde
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -11,7 +11,7 @@
"author": "Michal Orlik <sogehige@gmail.com>",
"license": "MIT",
"dependencies": {
"@sogebot/ui-admin": "^62.0.0",
"@sogebot/ui-admin": "^63.0.0",
"@sogebot/ui-helpers": "^3.1.0",
"@sogebot/ui-oauth": "~3.1.1",
"@sogebot/ui-overlay": "^31.0.0",
Expand Down
18 changes: 15 additions & 3 deletions src/integrations/lastfm.ts
Expand Up @@ -5,11 +5,16 @@ import { settings } from '../decorators';
import { onChange, onStartup } from '../decorators/on';
import Integration from './_interface';

import { isStreamOnline } from '~/helpers/api';
import { announce, prepare } from '~/helpers/commons';
import { error } from '~/helpers/log';

let canSendRequests = true;

enum NOTIFY {
disabled, all, online,
}

class LastFM extends Integration {
@settings()
apiKey = '';
Expand All @@ -18,7 +23,10 @@ class LastFM extends Integration {
username = '';

@settings()
notify = false;
notify = NOTIFY.all;

@settings()
notifyWhenOffline = false;

currentSong: null | string = null;

Expand Down Expand Up @@ -48,8 +56,12 @@ class LastFM extends Integration {
for (const track of tracks) {
if (track['@attr'] && track['@attr'].nowplaying === 'true') {
const song = `${track.name} - ${track.artist['#text']}`;
if (this.currentSong !== song && this.notify) {
this.notifySong(song);
if (this.currentSong !== song) {
if (this.notify != NOTIFY.disabled
&& (this.notify == NOTIFY.all
|| (this.notify == NOTIFY.online && isStreamOnline.value))) {
this.notifySong(song);
}
}
this.currentSong = song;
}
Expand Down

0 comments on commit f814cde

Please sign in to comment.