Search in sources :

Example 1 with ModuleEntry

use of de.notecho.spotify.database.user.entities.module.ModuleEntry in project spotifybot by NotEchoDE.

the class PauseCommand method exec.

@SneakyThrows
@Override
public void exec(String userName, String id, UserLevel userLevel, String[] args) {
    ModuleEntry sPause = getModule().getEntry("sPause");
    if (!userLevel.isHigherOrEquals(sPause.getUserLevel())) {
        sendMessage(getModule(ModuleType.SYSTEM).getEntry("noPerms"), "$USER", userName, "$ROLE", sPause.getUserLevel().getPrettyName());
        return;
    }
    getRoot().getSpotifyApi().pauseUsersPlayback().build().execute();
    sendMessage(sPause, "$USER", userName);
}
Also used : ModuleEntry(de.notecho.spotify.database.user.entities.module.ModuleEntry) SneakyThrows(lombok.SneakyThrows)

Example 2 with ModuleEntry

use of de.notecho.spotify.database.user.entities.module.ModuleEntry in project spotifybot by NotEchoDE.

the class PlayCommand method exec.

@SneakyThrows
@Override
public void exec(String userName, String id, UserLevel userLevel, String[] args) {
    ModuleEntry sPlay = getModule().getEntry("sPlay");
    if (!userLevel.isHigherOrEquals(sPlay.getUserLevel())) {
        sendMessage(getModule(ModuleType.SYSTEM).getEntry("noPerms"), "$USER", userName, "$ROLE", sPlay.getUserLevel().getPrettyName());
        return;
    }
    if (args.length >= 1) {
        StringBuilder searchQuery = new StringBuilder();
        for (int i = 0; i < args.length; i++) if (i != 0)
            searchQuery.append(" ");
        else
            searchQuery.append(args[i]);
        Paging<Track> search = getRoot().getSpotifyApi().searchTracks(searchQuery.toString()).build().execute();
        if (search.getTotal() == 0) {
            sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notFound"), "$USER", userName);
            return;
        }
        String uri = search.getItems()[0].getUri();
        CountryCode country = getRoot().getSpotifyApi().getCurrentUsersProfile().build().execute().getCountry();
        Track track = getRoot().getSpotifyApi().getTrack(uri.replace("spotify:track:", "")).build().execute();
        if (Arrays.stream(track.getAvailableMarkets()).noneMatch(countryCode -> countryCode.equals(CountryCode.DE))) {
            sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notAvailable"), "$USER", userName, "$SONG", track.getName());
            return;
        }
        getRoot().getSpotifyApi().addItemToUsersPlaybackQueue(uri).build().execute();
        getRoot().getSpotifyApi().skipUsersPlaybackToNextTrack().build().execute();
        sendMessage(sPlay, "$USER", userName, "$SONG", track.getName());
        return;
    }
    getRoot().getSpotifyApi().startResumeUsersPlayback().build().execute();
    String uri = SpotifyUtils.getUriFromJson(getRoot().getSpotifyApi().getUsersCurrentlyPlayingTrack().build().getJson());
    Track track = getRoot().getSpotifyApi().getTrack(SpotifyUtils.getIdFromUri(uri)).build().execute();
    sendMessage(sPlay, "$USER", userName, "$SONG", track.getName(), "$ARTISTS", SpotifyUtils.getArtists(track));
}
Also used : ModuleEntry(de.notecho.spotify.database.user.entities.module.ModuleEntry) CountryCode(com.neovisionaries.i18n.CountryCode) Track(se.michaelthelin.spotify.model_objects.specification.Track) SneakyThrows(lombok.SneakyThrows)

Example 3 with ModuleEntry

use of de.notecho.spotify.database.user.entities.module.ModuleEntry in project spotifybot by NotEchoDE.

the class PlayAddCommand method exec.

@SneakyThrows
@Override
public void exec(String userName, String id, UserLevel userLevel, String[] args) {
    ModuleEntry sPlayAdd = getModule().getEntry("sPlayAdd");
    if (!userLevel.isHigherOrEquals(sPlayAdd.getUserLevel())) {
        sendMessage(getModule(ModuleType.SYSTEM).getEntry("noPerms"), "$USER", userName, "$ROLE", sPlayAdd.getUserLevel().getPrettyName());
        return;
    }
    StringBuilder searchQuery = new StringBuilder();
    if (args.length >= 1)
        for (int i = 0; i < args.length; i++) if (i != 0)
            searchQuery.append(" ");
        else
            searchQuery.append(args[i]);
    else {
        sendMessage(getModule(ModuleType.SYSTEM).getEntry("syntax"), "$USER", userName, "$USAGE", "!sPlayAdd [song]");
        return;
    }
    Paging<Track> search = getRoot().getSpotifyApi().searchTracks(searchQuery.toString()).build().execute();
    if (search.getTotal() == 0) {
        sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notFound"), "$USER", userName);
        return;
    }
    String uri = search.getItems()[0].getUri();
    CountryCode country = getRoot().getSpotifyApi().getCurrentUsersProfile().build().execute().getCountry();
    Track track = getRoot().getSpotifyApi().getTrack(uri.replace("spotify:track:", "")).build().execute();
    if (Arrays.stream(track.getAvailableMarkets()).noneMatch(countryCode -> countryCode.equals(CountryCode.DE))) {
        sendMessage(getModule(ModuleType.SONGREQUEST).getEntry("notAvailable"), "$USER", userName, "$SONG", track.getName());
        return;
    }
    getRoot().getSpotifyApi().addItemToUsersPlaybackQueue(uri).build().execute();
    sendMessage(sPlayAdd, "$USER", userName, "$SONG", track.getName());
}
Also used : ModuleEntry(de.notecho.spotify.database.user.entities.module.ModuleEntry) CountryCode(com.neovisionaries.i18n.CountryCode) Track(se.michaelthelin.spotify.model_objects.specification.Track) SneakyThrows(lombok.SneakyThrows)

Aggregations

ModuleEntry (de.notecho.spotify.database.user.entities.module.ModuleEntry)3 SneakyThrows (lombok.SneakyThrows)3 CountryCode (com.neovisionaries.i18n.CountryCode)2 Track (se.michaelthelin.spotify.model_objects.specification.Track)2