Пример #1
0
 private async void button71_Click(object sender, EventArgs e)
 {
     followerService = new TwitchLib.Services.FollowerService();
     followerService.SetChannelByChannelId(textBox68.Text);
     followerService.OnNewFollowersDetected += onFollowersDetected;
     await followerService.StartService();
 }
        private async Task StartTwitchMonitoring()
        {
            var api = new TwitchLib.TwitchAPI(clientId: ClientId);

            Service = new FollowerService(api);
            Service.SetChannelByName(Channel);
            await Service.StartService();

            var v5 = new TwitchLib.Channels.V5(api);

            var follows = await v5.GetAllFollowersAsync(ChannelId);

            _CurrentFollowerCount           = follows.Count;
            Service.OnNewFollowersDetected += Service_OnNewFollowersDetected;

            var v5Stream = CreateTwitchStream(api);

            if (v5Stream == null)
            {
                await Task.Delay(2000);
                await StartTwitchMonitoring();

                return;
            }
            var myStream = await v5Stream.GetStreamByUserAsync(ChannelId);

            _CurrentViewerCount = myStream.Stream?.Viewers ?? 0;

            Logger.LogInformation($"Now monitoring Twitch with {_CurrentFollowerCount} followers and {_CurrentViewerCount} Viewers");

            _Timer = new Timer(CheckViews, v5Stream, 0, 5000);
        }
 /// <summary>
 /// Connects to Twitch.
 /// </summary>
 public void Start()
 {
     botClient.Connect();
     userClient.Connect();
     followerService.StartService();
     liveStreamMonitor.StartService();
     IsConnected = true;
 }
Пример #4
0
        public async void SetFollowerService(ITwitchAPI api)
        {
            // FollowerService
            _followerService = new FollowerService(api);
            _followerService.SetChannelByChannelId(AivaClient.Instance.ChannelId);

            _followerService.OnNewFollowersDetected
                += (sender, e)
                   => OnNewFollower?.Invoke(this, e.NewFollowers);

            await _followerService.StartService().ConfigureAwait(false);
        }
        public TwitchFollowerService(ITwitchAPI twitchApi, TwitchClientSettings settings)
        {
            _twitchApi = twitchApi;

            _settings = settings;

            _followerService = new FollowerService(twitchApi);

            _followerService.SetChannelByChannelId(settings.TwitchChannelId);

            _followerService.StartService().Wait();

            _followerService.OnNewFollowersDetected += FollowerServiceOnOnNewFollowersDetected;
        }
Пример #6
0
        private async void onPubSubConnected(object sender, object e)
        {
            try
            {
                Console.Out.WriteLine("PubSub Connected!");
                Channel = await api.Channels.v5.GetChannelAsync(config.ChatbotAccessToken);

                followerService.SetChannelByChannelId(Channel.Id);
                await followerService.StartService();

                pubsub.ListenToBitsEvents(Channel.Id);
                pubsub.OnBitsReceived += onBitsReceived;
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.ToString());
            }
        }
Пример #7
0
        public void BotStart()
        {
            try
            {
                ConnectionCredentials credentials = new ConnectionCredentials("JustAnyBot", Settings.AuthToken);

                client = new TwitchClient();
                client.Initialize(credentials);
                client.OnConnected += Client_OnConnected;
                client.AddChatCommandIdentifier(char.Parse("#"));
                client.OnConnectionError += Client_ConnectionError;
                client.OnUserTimedout    += Client_TimedOut;
                if (Settings.AnnounceJoin)
                {
                    client.OnUserJoined += Client_UserJoined;
                }
                client.OnChatCommandReceived += Client_ChatCommandReceived;
                if (Settings.AnnounceLeave)
                {
                    client.OnUserLeft += Client_UserLeft;
                }
                if (Settings.ThankSubscribers)
                {
                    client.OnNewSubscriber += Client_Subscribed;
                }

                api = new TwitchAPI();
                api.Settings.ClientId    = Settings.ClientId;
                api.Settings.AccessToken = Settings.AuthToken;

                GetInfo();

                if (Settings.ThankFollowers)
                {
                    follower = new FollowerService(api, 5);
                    follower.SetChannelByChannelId(Settings.ChannelId);
                    follower.OnNewFollowersDetected += Client_Followed;
                    follower.StartService();
                }

                if (Settings.AnnounceBan)
                {
                    client.OnUserBanned += Client_Banned;
                }
                if (Settings.AnnounceNowHosting)
                {
                    client.OnNowHosting += Client_Hosting;
                }

                UserApi = new TwitchLib.Api.Sections.Users.V5Api(api);

                client.Connect();


                window.Dispatcher.Invoke((Action)(() =>
                {
                    window.BotStarting();
                }));
            }
            catch (ThreadAbortException e)
            {
                MessageBox.Show("Erro: A Janela fechou antes de obter o AuthToken");
            }
            catch (Exception e)
            {
                MessageBox.Show($"An exception has occurred: \n\n{e.Message}");
            }
        }