private async Task ConfigLiveMonitorAsync(string clientid, string access_token, string channel) { API = new TwitchAPI(); API.Settings.ClientId = clientid; API.Settings.AccessToken = access_token; Monitor = new LiveStreamMonitorService(API, 60); Monitor.SetChannelsByName(new List <string> { channel }); /* * Monitor.OnStreamOnline += Monitor_OnStreamOnline; * Monitor.OnStreamOffline += Monitor_OnStreamOffline; * Monitor.OnStreamUpdate += Monitor_OnStreamUpdate; * * Monitor.OnServiceStarted += Monitor_OnServiceStarted; * Monitor.OnChannelsSet += Monitor_OnChannelsSet; */ Service = new FollowerService(API); if (Program.config.format_onfollow != null) { Service.OnNewFollowersDetected += Monitor_onNewFollowersDetected; } Service.Start(); Monitor.Start(); //Keep at the end! await Task.Delay(-1); }
public async Task InitializeAsync(string userName, string oauthToken, string channel) { var credentials = new ConnectionCredentials(userName, oauthToken); _client = new TwitchClient(); _client.Initialize(credentials, channel); _client.OnLog += OnLog; _client.OnConnectionError += OnConnectionError; _client.OnConnected += OnConnected; _client.OnJoinedChannel += OnJoinedChannel; _client.OnNewSubscriber += OnNewSubscriber; //_client.OnMessageReceived += OnMessageReceived; _twitchAPI.Settings.ClientId = _options.TwitchClientId; _twitchAPI.Settings.AccessToken = _options.TwitchSecret; _service = new FollowerService(_twitchAPI); _service.SetChannelsByName(new List <string> { "SpyderHunter03" }); _service.OnServiceStarted += OnServiceStarted; _service.OnServiceTick += OnServiceTick; _service.OnNewFollowersDetected += OnNewFollowersDetected; await Task.Run(() => _client.Connect()); _logger.LogInformation($"Got passed Connect"); await Task.Run(() => _service.Start()); _logger.LogInformation($"Got passed Start"); }
public void Start_Throws_InvalidOperationException_When_ServiceAlreadyStarted() { _followerService = new FollowerService(_api); _followerService.SetChannelsById(Utils.CreateListWithEmptyString()); _followerService.Start(); AssertException.Throws <InvalidOperationException>(AlreadyStartedExceptionMessage, () => _followerService.Start()); }
internal void Connect() { Console.WriteLine("Connecting..."); client = new TwitchClient(); client.Initialize(credentials, TwitchInfo.ChannelName); //Client Events client.OnLog += Client_OnLog; client.OnConnectionError += Client_OnConnectionError; client.OnMessageReceived += Client_OnMessageReceived; client.OnNewSubscriber += Client_OnNewSubscriber; client.Connect(); api = new TwitchAPI(); api.Settings.ClientId = TwitchInfo.ClientID; api.Settings.AccessToken = TwitchInfo.BotToken; //API Events monitor = new LiveStreamMonitorService(api, int.Parse(TwitchInfo.UpdateInterval)); List <string> channels = new List <string>(); channels.Add(TwitchInfo.ChannelName); monitor.SetChannelsByName(channels); monitor.OnStreamOffline += Monitor_OnStreamOffline; monitor.OnStreamOnline += Monitor_OnStreamOnline; monitor.Start(); fservice = new FollowerService(api, int.Parse(TwitchInfo.UpdateInterval)); fservice.SetChannelsByName(channels); fservice.OnNewFollowersDetected += Fservice_OnNewFollowersDetected; fservice.Start(); //Excel Stuff excel = new Application(); excel.Visible = true; wb = excel.Workbooks.Open(TwitchInfo.ExcelPath); foreach (Worksheet sheet in wb.Sheets) { if (sheet.Name == TwitchInfo.ChannelName) { Console.WriteLine("Found exisiting channel..."); ws = sheet; break; } } if (ws == null) { //Create/copy a new worksheet from base worksheet Console.WriteLine("New channel detected, creating a new sheet..."); ws = (Worksheet)excel.Worksheets.Add(); ws.Name = TwitchInfo.ChannelName; } }
public void ConnectToTwitch(TwitchConfiguration twitchConfiguration) { SetUpEvents(); api = InitializeTwitchApi(twitchConfiguration); CreateFollowerService(twitchConfiguration, api); RegisterFollowerServiceCallback(); followerService.Start(); }
public BroadcasterInfo(DrakeBot bot, string id, string accessToken) { ID = id; AccessToken = accessToken; follows = new FollowerService(bot.Service); follows.SetChannelsById(new List <string>(new [] { id })); follows.OnNewFollowersDetected += bot.Follows_OnNewFollowersDetected; follows.Start(); }
public void OnServiceStarted_Raised_When_ServiceStarted() { var eventRaised = false; _followerService = new FollowerService(_api); _followerService.SetChannelsById(Utils.CreateListWithEmptyString()); _followerService.OnServiceStarted += (sender, e) => eventRaised = true; _followerService.Start(); Assert.True(eventRaised); }
public TwitchFollowerService(ITwitchAPI twitchApi, TwitchClientSettings settings) { _twitchApi = twitchApi; _settings = settings; _followerService = new FollowerService(twitchApi); _followerService.SetChannelsById(new List <string> { settings.TwitchChannelId }); _followerService.Start(); _followerService.OnNewFollowersDetected += FollowerServiceOnOnNewFollowersDetected; }
public void OnServiceTick_Raised_When_ServiceTicked() { var usersFollowsResponseJson = JMock.Of <GetUsersFollowsResponse>(o => o.Follows == new[] { Mock.Of <Follow>() } ); _api = TwitchLibMock.TwitchApi( ("https://api.twitch.tv/helix/users/follows", usersFollowsResponseJson) ); var signalEvent = new ManualResetEvent(false); _followerService = new FollowerService(_api, checkIntervalInSeconds: 1); _followerService.SetChannelsById(Utils.CreateListWithEmptyString()); _followerService.OnServiceTick += (sender, e) => signalEvent.Set(); _followerService.Start(); Assert.True(signalEvent.WaitOne(1500)); }
public void Start_Throws_InvalidOperationException_When_ChannelsNotSet() { _followerService = new FollowerService(_api); AssertException.Throws <InvalidOperationException>(ChannelsNotSetExceptionMessage, () => _followerService.Start()); }
public void ConnectToTwitch() { try { if (string.IsNullOrWhiteSpace(Settings.Username)) { ShowMessage("Twitch Benutzername ist in den Einstellungen nicht gesetzt", new NotificationSetting(false, true)); return; } if (string.IsNullOrWhiteSpace(Settings.OAuthToken)) { ShowMessage("Twitch O Auth Token ist in den Einstellungen nicht gesetzt", new NotificationSetting(false, true)); return; } if (Settings.CheckForNewFollowers) { if (string.IsNullOrWhiteSpace(Settings.ClientId)) { ShowMessage("Twitch Api Client ID ist in den Einstellungen nicht gesetzt", new NotificationSetting(false, true)); return; } if (string.IsNullOrWhiteSpace(Settings.AccessToken)) { ShowMessage("Twitch Api Access Token ist in den Einstellungen nicht gesetzt", new NotificationSetting(false, true)); return; } } var loggerfactory = new LoggerFactory() .AddSerilog( new LoggerConfiguration() .WriteTo.File("logs\\twitch.log") .CreateLogger()); twitchAPI = new TwitchAPI(loggerfactory); twitchAPI.Settings.ClientId = Settings.ClientId; twitchAPI.Settings.AccessToken = Settings.AccessToken; twitchAPI.Settings.Secret = Settings.OAuthToken; twitchClient = new TwitchClient(logger: loggerfactory.CreateLogger <TwitchClient>()); twitchClient.OnConnected += TwitchClient_OnConnected; twitchClient.OnNewSubscriber += TwitchClient_OnNewSubscriber; twitchClient.OnRaidNotification += TwitchClient_OnRaidNotification; twitchClient.OnUserJoined += TwitchClient_OnUserJoined; twitchClient.OnUserLeft += TwitchClient_OnUserLeft; twitchClient.OnBeingHosted += TwitchClient_OnBeingHosted; twitchClient.OnMessageReceived += TwitchClient_OnMessageReceived; twitchClient.Initialize(new ConnectionCredentials(Settings.Username, Settings.OAuthToken), Settings.ChannelToJoin); twitchClient.Connect(); if (Settings.CheckForNewFollowers) { followerService = new FollowerService(twitchAPI, checkIntervalInSeconds: 5); followerService.SetChannelsByName(new List <string>() { Settings.ChannelToJoin }); followerService.OnNewFollowersDetected += FollowerService_OnNewFollowersDetected; followerService.UpdateLatestFollowersAsync(false); followerService.Start(); } IsTwitchConnected = true; } catch (Exception ex) { mainViewModel.ShowError(ex); } }