/** * PhantomBot Example Commands for Spotify Tracker * * Place these in your PhantomBot scripts directory or add to existing command files * Make sure your Spotify Tracker server is running: cargo run -- server */ (function() { // Simple current track command $.bind('command', function(event) { var command = event.getCommand(); if (command.equalsIgnoreCase('song') || command.equalsIgnoreCase('track')) { try { var response = $.customAPI.get('http://localhost:8888/phantombot'); if (response.content && response.content.trim() !== 'No track currently playing') { $.say(response.content); } else { $.say('🎡 No music is currently playing'); } } catch (e) { $.say('❌ Could not get current track - is Spotify Tracker running?'); } } }); // Detailed track info command $.bind('command', function(event) { var command = event.getCommand(); if (command.equalsIgnoreCase('songinfo') || command.equalsIgnoreCase('np')) { try { var response = $.customAPI.get('http://localhost:8888/current'); var data = JSON.parse(response.content); if (data.playing && data.track) { var playStatus = data.is_playing ? '▢️' : '⏸️'; var message = playStatus + ' ' + data.track + ' by ' + data.artist + ' (' + data.album + ')'; // Add progress if available if (data.progress_ms && data.duration_ms) { var progressSec = Math.floor(data.progress_ms / 1000); var durationSec = Math.floor(data.duration_ms / 1000); var progressMin = Math.floor(progressSec / 60); var progressSecRemain = progressSec % 60; var durationMin = Math.floor(durationSec / 60); var durationSecRemain = durationSec % 60; message += ' [' + progressMin + ':' + (progressSecRemain < 10 ? '0' : '') + progressSecRemain + '/' + durationMin + ':' + (durationSecRemain < 10 ? '0' : '') + durationSecRemain + ']'; } $.say(message); // Optional: Also post Spotify link if (data.url) { $.say('πŸ”— Listen: ' + data.url); } } else { $.say('🎡 No music is currently playing'); } } catch (e) { $.say('❌ Error getting track info: ' + e.message); } } }); // Command to show last played when nothing is playing $.bind('command', function(event) { var command = event.getCommand(); if (command.equalsIgnoreCase('lastsong')) { try { var response = $.customAPI.get('http://localhost:8888/current'); var data = JSON.parse(response.content); if (data.track) { var status = data.is_playing ? 'Currently playing' : 'Last played'; $.say(status + ': ' + data.track + ' by ' + data.artist); } else { $.say('🎡 No recent track information available'); } } catch (e) { $.say('❌ Could not get track information'); } } }); // Fun command that can trigger actions based on what's playing $.bind('command', function(event) { var command = event.getCommand(); if (command.equalsIgnoreCase('songaction')) { try { var response = $.customAPI.get('http://localhost:8888/current'); var data = JSON.parse(response.content); if (data.playing && data.track) { var track = data.track.toLowerCase(); var artist = data.artist.toLowerCase(); // Add your own fun reactions here! if (artist.includes('queen')) { $.say('πŸ‘‘ Legendary! Queen is playing: ' + data.track); } else if (track.includes('never gonna give you up')) { $.say('🎡 Rick Rolled! Never gonna give you up! πŸ˜„'); } else if (artist.includes('lofi') || track.includes('lofi')) { $.say('😌 Chill vibes with some lofi: ' + data.track); } else { $.say('🎡 Great choice! ' + data.track + ' by ' + data.artist); } } else { $.say('🎡 No music playing for a song reaction!'); } } catch (e) { $.say('❌ Could not get current track'); } } }); // Initialize $.say('βœ… Spotify Tracker PhantomBot integration loaded!'); $.say('πŸ“‹ Commands: !song, !songinfo (!np), !lastsong, !songaction'); })();