コード例 #1
0
ファイル: SpotifyCommand.cs プロジェクト: l0raine/TS3Spotify
    public void LoginStepTwo(SpotifyAccount account, ClientCall invoker)
    {
        //get Email
        string information = "";

        information += "Now your Spotify-E-Mail.";
        Ts3Client.SendMessage(information, invoker.ClientId.Value);

        void handler(object sender, TextMessage textMessage)
        {
            if (textMessage.InvokerId == invoker.ClientId)
            {
                string mail = textMessage.Message.ToString();
                Match  m    = Regex.Match(mail, @"\[URL=.*\](.*)\[\/URL\]");
                if (m.Success)
                {
                    account.email = m.Groups[m.Groups.Count - 1].Value;
                }
                else
                {
                    account.email = mail;
                }

                Ts3Client.OnMessageReceived -= handler;
                LoginStepThree(account, invoker);
            }
        };

        Ts3Client.OnMessageReceived += handler;
    }
コード例 #2
0
ファイル: SpotifyCommand.cs プロジェクト: l0raine/TS3Spotify
    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;
        });
    }
コード例 #3
0
        public static void SendMessage(Ts3Client client, ClientCall cc, string message)
        {
            if (cc?.ClientId == null)
            {
                return;
            }

            client.SendMessage(message, cc.ClientId.Value);
        }
コード例 #4
0
ファイル: SpotifyCommand.cs プロジェクト: l0raine/TS3Spotify
    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);
            }
        });
    }
コード例 #5
0
ファイル: SpotifyCommand.cs プロジェクト: l0raine/TS3Spotify
    public void CommandSpotifyAccount(ClientCall invoker)
    {
        SpotifyAccount account            = spotifyPluginConfig.getAccount(invoker.ClientUid.Value);
        string         accountInformation = "";

        if (account.Exists())
        {
            accountInformation += "Your Accountinformation:\n\n";
            accountInformation += "Your E-Mail: " + account.email + "\n";
            accountInformation += "Your Code: " + account.code + "\n";
        }
        else
        {
            accountInformation += "Yout dont have an Spotify-Account stored. Type !spotify account add";
        }
        Ts3Client.SendMessage(accountInformation, invoker.ClientId.Value);
    }
コード例 #6
0
ファイル: SpotifyCommand.cs プロジェクト: l0raine/TS3Spotify
    public void LoginStepThree(SpotifyAccount account, ClientCall invoker)
    {
        //get password
        string information = "";

        information += "Now your Spotify-Password.";
        Ts3Client.SendMessage(information, invoker.ClientId.Value);

        void handler(object sender, TextMessage textMessage)
        {
            if (textMessage.InvokerId == invoker.ClientId)
            {
                Ts3Client.OnMessageReceived -= handler;
                LoginStepFour(account, invoker, textMessage.Message.ToString());
            }
        };

        Ts3Client.OnMessageReceived += handler;
    }
コード例 #7
0
ファイル: SpotifyCommand.cs プロジェクト: l0raine/TS3Spotify
    public void CommandSpotifyAccountAdd(ClientCall invoker)
    {
        SpotifyAccount account = spotifyPluginConfig.getAccount(invoker.ClientUid.Value);

        bool cancel = false;

        if (spotifyPluginConfig.returnUrl.Length < 10)
        {
            Ts3Client.SendMessage("Return-URL is not set", invoker.ClientId.Value);
            cancel = true;
        }
        if (spotifyPluginConfig.clientSecret.Length < 10)
        {
            Ts3Client.SendMessage("clientSecret is not set", invoker.ClientId.Value);
            cancel = true;
        }
        if (spotifyPluginConfig.clientId.Length < 10)
        {
            Ts3Client.SendMessage("clientId is not set", invoker.ClientId.Value);
            cancel = true;
        }

        if (cancel == true)
        {
            Ts3Client.SendMessage("aborting", invoker.ClientId.Value);
            return;
        }

        if (account.Exists())
        {
            CommandSpotifyAccount(invoker);
        }
        else
        {
            string information = "Follow instructions";
            Ts3Client.SendMessage(information, invoker.ClientId.Value);
            LoginStepOne(account, invoker);
        }
    }