Esempio n. 1
0
        // Connect the PubSub client.
        public async void ConnectPubSubClient()
        {
            PubSubClient = new TwitchPubSub();

            string channelId = await GetChannelId(ChannelName);

            // Listen to events.
            PubSubClient.OnPubSubServiceConnected += Client_OnPubSubServiceConnected;
            PubSubClient.OnListenResponse         += Client_OnListenResponse;

            if (Alerts[0])
            {
                // Follow alert.
                PubSubClient.ListenToFollows(channelId);
                PubSubClient.OnFollow += Client_OnFollow;
            }

            if (Alerts[1])
            {
                // Sub alert.
                PubSubClient.ListenToSubscriptions(channelId);
                PubSubClient.OnChannelSubscription += Client_OnChannelSubscription;
            }

            if (Alerts[2])
            {
                // Bits alert.
                PubSubClient.ListenToBitsEvents(channelId);
                PubSubClient.OnBitsReceived += Client_OnBitsReceived;
            }

            PubSubClient.Connect();
        }
        public static void Init(TwitchClient client, TwitchPubSub pubsubClient, ApplicationSettings appSettings, Account account,
                                CouchDbStore <Viewer> viewerCollection, List <Command> settings)
        {
            _client           = client;
            _account          = account;
            _viewerCollection = viewerCollection;
            _commandSettings  = settings;
            _twitchService    = new TwitchService(appSettings);

            _client.OnJoinedChannel               += OnJoinedChannel;
            _client.OnMessageReceived             += OnMessageReceived;
            _client.OnWhisperReceived             += OnWhisperReceived;
            _client.OnNewSubscriber               += OnNewSubscriber;
            _client.OnLog                         += OnLog;
            _client.OnConnectionError             += OnConnectionError;
            _client.OnChatCommandReceived         += OnChatCommandReceived;
            _client.OnUserTimedout                += OnUserTimedOut;
            _client.OnUserBanned                  += ClientOnUserBanned;
            pubsubClient.OnPubSubServiceConnected += TwitchPubSubOnOnPubSubServiceConnected;
            pubsubClient.OnPubSubServiceClosed    += TwitchPubSubOnOnPubSubServiceClosed;
            pubsubClient.OnChannelSubscription    += TwitchPubSubOnOnChannelSubscription;
            pubsubClient.OnFollow                 += TwitchPubSubOnOnFollow;
            pubsubClient.OnEmoteOnly              += TwitchPubSubOnOnEmoteOnly;
            pubsubClient.OnEmoteOnlyOff           += TwitchPubSubOnOnEmoteOnlyOff;

            pubsubClient.ListenToFollows(appSettings?.Keys.Twitch.ChannelId);
            pubsubClient.ListenToSubscriptions(appSettings?.Keys.Twitch.ChannelId);
            pubsubClient.ListenToChatModeratorActions(_account?.TwitchBotSettings.Username, appSettings?.Keys.Twitch.ChannelId);
        }
Esempio n. 3
0
        private static void onPubSubServiceConnected(object sender, EventArgs e)
        {
            _twitchPubSub.ListenToFollows(Constants.TwitchChannelId);
            _twitchPubSub.ListenToBitsEvents(Constants.TwitchChannelId);
            _twitchPubSub.ListenToSubscriptions(Constants.TwitchChannelId);

            _twitchPubSub.SendTopics(Constants.TwitchChannelAccessToken);
        }
Esempio n. 4
0
        public TwitchEvents(ConnectionCredentials credentials, string username)
        {
            try
            {
                Dictionary <string, string> channels = new Dictionary <string, string>()
                {
                    { "phenomalytv", "PaymoneyWubby" }
                };

                livemonitor = new LiveStreamMonitorService(TwitchApi, 20);
                livemonitor.SetChannelsByName(channels.Keys.ToList());
                livemonitor.Start();

                livemonitor.OnStreamOnline  += OnStreamOnline;
                livemonitor.OnStreamOffline += OnStreamOffline;
            } catch (Exception ex) { Console.WriteLine(ex); }

            try
            {
                client = new TwitchClient {
                    AutoReListenOnException = true
                };
                client.Initialize(credentials, username);

                client.Connect();

                client.OnConnected    += OnConnected;
                client.OnReconnected  += OnReconnected;
                client.OnDisconnected += OnDisconnected;


                client.OnNewSubscriber   += OnNewSubscriber;
                client.OnMessageReceived += OnMessageReceived;


                pubsub.ListenToBitsEvents("109598326");
                pubsub.ListenToFollows("109598326");
                pubsub.ListenToSubscriptions("109598326");
                pubsub.OnFollow       += OnNewFollower;
                pubsub.OnBitsReceived += OnBitsReceived;


                pubsub.Connect();

                if (!client.IsConnected)
                {
                    throw new NotImplementedException("Error out no connection");
                }
            } catch (Exception ex) { Console.WriteLine(ex); }
        }
Esempio n. 5
0
        internal async void Connect()
        {
            UserEntry botUser = await Program.Users.GetUserByTwitchUserName("juanthebot");

            int botClientID = -1;

            int.TryParse(botUser._twitchUID, out botClientID);

            Client.ListenToFollows(_twitchID);
            Client.ListenToVideoPlayback(_twitchChannelName);
            Client.ListenToSubscriptions(_twitchID);
            Client.ListenToBitsEvents(_twitchID);
            // Verify
            //Client.ListenToRaid(_twitchID);
            //Client.ListenToWhispers(botUser._twitchUID);
            Client.Connect();
        }
        public ValueTask Register(IMessageContextSink messageContextSink)
        {
            var api = new TwitchAPI();

            api.Settings.ClientId = _twitchSettings.ClientId;
            api.Settings.Secret   = _twitchSettings.ClientSecret;
            AccessToken           = api.V5.Root.GetAccessToken();
            // var client = _factory.CreateClient();
            // var url = $"https://id.twitch.tv/oauth2/token?grant_type=client_credentials&client_id={_twitchSettings.ClientId}&client_secret={_twitchSettings.ClientSecret}&scope=user_read";
            // var kraken_rul = "https://api.twitch.tv/kraken/user";
            // var tokenResponse = await client.PostAsync(url, null);
            // var dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(await tokenResponse.Content.ReadAsStringAsync());
            // var AccessToken = dict["access_token"].ToString();


            _pubsub.OnPubSubServiceConnected += (s, e) =>
            {
                _pubsub.ListenToFollows("428420296");
                //pubsub.ListenToSubscriptions("428420296");
                _pubsub.SendTopics(AccessToken);
            };

            _pubsub.OnFollow += (s, e) => messageContextSink.Send(new(
                                                                      new TwitchFollow(e.Username),
                                                                      e.FollowedChannelId,
                                                                      Constants.Sources.TwitchPubsub
                                                                      ));

            _pubsub.OnChannelSubscription += (s, e) => messageContextSink.Send(new(
                                                                                   new TwitchSubscription(
                                                                                       e.Subscription.UserId,
                                                                                       e.Subscription.Username,
                                                                                       e.Subscription.Time,
                                                                                       e.Subscription.TotalMonths,
                                                                                       e.Subscription.StreakMonths,
                                                                                       e.Subscription.Context
                                                                                       ),
                                                                                   e.Subscription.ChannelId,
                                                                                   Constants.Sources.TwitchPubsub
                                                                                   ));

            _pubsub.Connect();

            return(ValueTask.CompletedTask);
        }
Esempio n. 7
0
        public void Connect()
        {
            client = new TwitchPubSub();

            client.OnPubSubServiceConnected += onPubSubServiceConnected;
            client.OnListenResponse         += onListenResponse;
            client.OnStreamUp            += onStreamUp;
            client.OnStreamDown          += onStreamDown;
            client.OnBitsReceived        += onBitsReceived;
            client.OnRewardRedeemed      += onRewardRedeemed;
            client.OnFollow              += onFollow;
            client.OnChannelSubscription += onSubscription;

            client.ListenToBitsEvents("57026834");
            client.ListenToFollows("57026834");
            client.ListenToRewards("57026834");
            client.ListenToSubscriptions("57026834");
            client.ListenToVideoPlayback("57026834");

            client.Connect();
        }
Esempio n. 8
0
        private void RegisterEventsToListenTo()
        {
            if (isConnected)
            {
                Logger.Instance.LogMessage(TracingLevel.INFO, $"RegisterEventsToListenTo called but already connected");
                return;
            }

            if (!TwitchTokenManager.Instance.TokenExists)
            {
                Logger.Instance.LogMessage(TracingLevel.INFO, $"RegisterEventsToListenTo called but token does not exist");
                return;
            }

            if (TwitchTokenManager.Instance.User == null || String.IsNullOrEmpty(TwitchTokenManager.Instance.User.UserName))
            {
                Logger.Instance.LogMessage(TracingLevel.INFO, $"RegisterEventsToListenTo called but user info does not exist");
                Thread.Sleep(5000);

                if (TwitchTokenManager.Instance.User == null || String.IsNullOrEmpty(TwitchTokenManager.Instance.User.UserName))
                {
                    Logger.Instance.LogMessage(TracingLevel.ERROR, $"RegisterEventsToListenTo called but user info does not exist! Cannot register for events");
                    return;
                }
            }

            isConnected = true;
            channelName = TwitchTokenManager.Instance.User.UserId;
            Logger.Instance.LogMessage(TracingLevel.INFO, $"PubSub registering to events for {TwitchTokenManager.Instance.User.UserName} ({channelName})");
            var token = TwitchTokenManager.Instance.GetToken();

            pubsub.ListenToBitsEvents(channelName);
            pubsub.ListenToFollows(channelName);
            pubsub.ListenToSubscriptions(channelName);
            pubsub.ListenToRewards(channelName);
            pubsub.ListenToRaid(channelName);
            pubsub.SendTopics($"{token.Token}");

            Logger.Instance.LogMessage(TracingLevel.INFO, $"PubSub SendTopics oauth length {token.Token.Length}");
        }
Esempio n. 9
0
        public TwitchPubSubService(
            TwitchSettings settings,
            HubConnection connection)
        {
            _settings = settings;

            _connection = connection;
            _connection.StartAsync();


            _client = new TwitchPubSub();

            _client.OnPubSubServiceConnected += onPubSubServiceConnected;
            _client.OnListenResponse         += onListenResponse;
            _client.OnStreamUp       += onStreamUp;
            _client.OnStreamDown     += onStreamDown;
            _client.OnRewardRedeemed += onRewardRedeemed;
            _client.OnFollow         += onFollow;

            _client.ListenToFollows(_settings.ChannelId);
            _client.ListenToRewards(_settings.ChannelId);

            _client.Connect();
        }
 private void ListenToFollows(string channelId)
 {
     PubSub.OnFollow += PubSub_OnFollow;
     PubSub.ListenToFollows(channelId);
 }