Esempio n. 1
0
        public void Connect()
        {
            if (isconnected)
            {
                Logger.Warning(this, "Already connected");
                return;
            }

            string chatchannel = context.GetModule <TwitchChatModule>().Username;
            string usertoken   = context.GetModule <TwitchChatModule>().AccessToken;

            if (string.IsNullOrEmpty(usertoken))
            {
                Logger.Warning(this, "User not connected");
                return;
            }

            twitchapi   = new TwitchApi(TwitchConstants.ClientID, usertoken);
            channels    = new Channels(TwitchConstants.ClientID, usertoken);
            channeldata = channels.GetChannel();

            userdata = twitchapi.GetUsersByLogin(chatchannel).Data.FirstOrDefault();
            if (userdata == null)
            {
                Logger.Warning(this, $"No userdata found for '{chatchannel}'");
            }

            if (string.IsNullOrEmpty(botname) || string.IsNullOrEmpty(accesstoken))
            {
                Logger.Warning(this, "No credentials set");
                return;
            }

            if (!string.IsNullOrEmpty(chatchannel))
            {
                Logger.Info(this, $"Connecting to @{botname} to #{chatchannel}");
                chatclient.Connect(botname, accesstoken);
                chatclient.Join(chatchannel);
            }

            isconnected = true;
            Connected?.Invoke();
        }