public bool _startControl(ClientCall invoker) { if (activeSpotifyAccount != null) { return(false); } SpotifyAccount account = spotifyPluginConfig.getAccount(invoker.ClientUid.Value); if (!account.Exists()) { return(false); } SpotifyControl tempControl = new SpotifyControl(spotifyPluginConfig, rootConf); tempControl._refreshtoken(account.refreshToken).Wait(); if (!tempControl.hasInit()) { return(false); } activeSpotifyAccount = account; activeSpotifyAccount.setClient(invoker.ClientId.ToString()); activeSpotifyControl = tempControl; activeSpotifyControl.setTimer(activeSpotifyAccount.refreshToken); return(true); }
public void LoginStepOne(SpotifyAccount account, ClientCall invoker) { //get Auth-Key account.id = invoker.ClientUid.Value; var newControl = new SpotifyControl(spotifyPluginConfig, rootConf); newControl.firstTimeLogin((link) => { string information = ""; information += "Grant rights and place the code from GET-Param into this chat."; Ts3Client.SendMessage(information, invoker.ClientId.Value); Ts3Client.SendMessage(link, invoker.ClientId.Value); void handler(object sender, TextMessage textMessage) { if (textMessage.InvokerId == invoker.ClientId) { account.code = textMessage.Message.ToString(); Ts3Client.OnMessageReceived -= handler; LoginStepTwo(account, invoker); } }; Ts3Client.OnMessageReceived += handler; }); }
private void stopSpotify() { lock (_lock) { if (spotifyInstance != null && !spotifyInstance.hasExited()) { spotifyInstance.stopProcess(); } producer?.Dispose(); producer = null; spotifyInstance = null; activeSpotifyControl = null; activeSpotifyAccount = null; } }
public void LoginStepFour(SpotifyAccount account, ClientCall invoker, string password) { //Start Librespot and check Password string information = ""; information += "Lets check it quickly."; Ts3Client.SendMessage(information, invoker.ClientId.Value); SpotifyInstance newInstance = new SpotifyInstance(spotifyPluginConfig, account); newInstance.useLogin(account.email, password); newInstance.startProcess(); int tries = 0; while (!newInstance.connected && tries++ < 4) { Thread.Sleep(500); } if (!newInstance.connected || newInstance.hasExited()) { Ts3Client.SendMessage("Credentials not right.", invoker.ClientId.Value); return; } SpotifyControl newControl = new SpotifyControl(spotifyPluginConfig, rootConf); newControl.logintoken(account.code, (bool success, bool tell, string accessToken, string refreshToken) => { if (success) { account.refreshToken = refreshToken; account.accessToken = accessToken; spotifyPluginConfig.accountList.Add(account); saveConfig(); Ts3Client.SendMessage("You can use Spotify now.", invoker.ClientId.Value); } else { Ts3Client.SendMessage("Something went wrong check your Auth-Token.", invoker.ClientId.Value); } }); }