protected async Task <bool> ConfigureBroadcasterAccount(
            API.Twitch.IBroadcasterTokenValidator broadcasterTokenValidator,
            API.Twitch.HelixHelper helixHelper)
        {
            bool successful = true;

            if (string.IsNullOrEmpty(botConfig.Broadcaster))
            {
                WritePrompt("Broadcaster Username");

                string inputUserName = Console.ReadLine()?.Trim();

                if (!string.IsNullOrEmpty(inputUserName))
                {
                    botConfig.Broadcaster = inputUserName;
                    botConfig.Serialize();
                }
                else
                {
                    WriteError("No Broadcaster Username received.");
                    successful = false;
                }
            }

            if (!string.IsNullOrEmpty(botConfig.TwitchClientId) &&
                !string.IsNullOrEmpty(botConfig.TwitchClientSecret) &&
                !string.IsNullOrEmpty(botConfig.Broadcaster))
            {
                if (await broadcasterTokenValidator.TryToConnect())
                {
                    //Set broadcasterID if it's not set
                    if (string.IsNullOrEmpty(botConfig.BroadcasterId))
                    {
                        //Fetch the Broadcaster ID
                        API.Twitch.TwitchUsers userData = await helixHelper.GetUsers(null, new List <string>() { botConfig.Broadcaster });

                        if (userData.Data is not null && userData.Data.Count > 0)
                        {
                            botConfig.BroadcasterId = userData.Data[0].ID;
                            botConfig.Serialize();
                        }
                        else
                        {
                            WriteError("Unable to fetch BroadcasterId.  Please check broadcaster credentials and try again.");
                            successful = false;
                        }
                    }
                }
                else
                {
                    WriteError("Unable to connect to Twitch.  Please check broadcaster credentials and try again.");
                    successful = false;
                }
            }
Example #2
0
 public StandardConfigurator(
     Config.BotConfiguration botConfig,
     ICommunication communication,
     ErrorHandler errorHandler,
     API.Twitch.HelixHelper helixHelper,
     API.Twitch.IBotTokenValidator botTokenValidator,
     API.Twitch.IBroadcasterTokenValidator broadcasterTokenValidator)
     : base(botConfig, communication, errorHandler)
 {
     this.helixHelper               = helixHelper;
     this.botTokenValidator         = botTokenValidator;
     this.broadcasterTokenValidator = broadcasterTokenValidator;
 }