Improve voice turns, local commands and Spotify controls
This commit is contained in:
+6
-4
@@ -1,6 +1,6 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import WebSocket from 'ws';
|
||||
import { searchSpotify } from './spotify.mjs';
|
||||
import { searchSpotify, playlistTool } from './spotify.mjs';
|
||||
|
||||
const spotifyUri = /^spotify:(track|artist|album|playlist|episode):[A-Za-z0-9]{22}$/;
|
||||
|
||||
@@ -38,20 +38,22 @@ export function deviceTools(client, signal) {
|
||||
return true;
|
||||
},
|
||||
async execute(name, args) {
|
||||
if (name !== 'spotify_play') return request(name, args);
|
||||
if (name === 'spotify_playlist') return playlistTool(args, signal);
|
||||
const enqueue = name === 'spotify_control' && args.action === 'enqueue';
|
||||
if (name !== 'spotify_play' && !enqueue) return request(name, args);
|
||||
let selected;
|
||||
if (args.uri) {
|
||||
if (!spotifyUri.test(args.uri)) return { error: 'invalid_spotify_uri' };
|
||||
selected = { uri: args.uri };
|
||||
} else {
|
||||
try {
|
||||
selected = (await searchSpotify(args.query, signal))[0];
|
||||
selected = (await searchSpotify(args.query, signal, enqueue ? 'track' : args.type))[0];
|
||||
} catch {
|
||||
return { error: 'spotify_search_unavailable', hint: 'Подключи Spotify в пульте Telegram и повтори запрос.' };
|
||||
}
|
||||
}
|
||||
if (!selected) return { error: 'spotify_not_found' };
|
||||
const result = await request(name, { uri: selected.uri });
|
||||
const result = await request(name, enqueue ? { action: 'enqueue', uri: selected.uri } : { uri: selected.uri });
|
||||
return { ...result, selection: selected };
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user