private async Task ConfigLiveMonitorAsync() { API = new TwitchAPI(); API.Settings.ClientId = Settings.ClientId; API.Settings.AccessToken = Settings.AccessToken; Monitor = new LiveStreamMonitorService(API, 10); Monitor.OnServiceStarted += Monitor_OnServiceStarted; Monitor.OnServiceStopped += Monitor_OnServiceStopped; Monitor.OnServiceTick += Monitor_OnServiceTick; Monitor.OnChannelsSet += Monitor_OnChannelsSet; List <string> lst = new List <string> { Settings.ChannelName, "TaleLearnCode" }; Monitor.SetChannelsByName(lst); Monitor.OnStreamOnline += Monitor_OnStreamOnline; Monitor.OnStreamOffline += Monitor_OnStreamOffline; Monitor.OnStreamUpdate += Monitor_OnStreamUpdate; Monitor.Start(); await Task.Delay(-1); }
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); }
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; } }
private readonly string _developmentRoomId = string.Empty; // Only for use in debug mode public ChatbotService(ICommandHelper commandHelper, ITwitchClientFactory twitchClientFactory, TwitchPubSub pubsub, ITwitchLiveStreamMonitorFactory twitchLiveStreamMonitorFactory, IVipApiClient vipApiClient, IConfigService configService, IStreamStatusApiClient streamStatusApiClient, ISecretService secretService, ILogger <ChatbotService> logger) { _commandHelper = commandHelper; _pubsub = pubsub; _twitchLiveStreamMonitorFactory = twitchLiveStreamMonitorFactory; _vipApiClient = vipApiClient; _configService = configService; _streamStatusApiClient = streamStatusApiClient; _secretService = secretService; _logger = logger; _streamerChannel = _configService.Get <string>("StreamerChannel"); _isDevelopmentBuild = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development" || Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Local"; _client = twitchClientFactory.Get(); _client.OnJoinedChannel += OnJoinedChannel; _client.OnChatCommandReceived += OnCommandReceived; _client.OnCommunitySubscription += OnSubBomb; _client.OnBeingHosted += OnBeingHosted; _client.OnRaidNotification += OnRaidNotification; _client.OnDisconnected += OnDisconnected; _client.OnError += OnError; _client.OnConnectionError += OnConnectionError; _client.Connect(); _liveStreamMonitor = _twitchLiveStreamMonitorFactory.Get(); _liveStreamMonitor.SetChannelsByName(new List <string> { _streamerChannel }); _liveStreamMonitor.OnStreamOnline += OnStreamOnline; _liveStreamMonitor.OnStreamOffline += OnStreamOffline; _liveStreamMonitor.OnServiceStarted += OnStreamMonitorStarted; //this.liveStreamMonitor.OnStreamUpdate += OnStreamUpdate; _liveStreamMonitor.Start(); _pubsub.OnPubSubServiceConnected += OnPubSubConnected; _pubsub.OnBitsReceived += OnBitsReceived; _pubsub.OnListenResponse += OnListenResponse; _pubsub.OnChannelSubscription += OnSub; _pubsub.Connect(); }
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); } }
private static void StartMonitor() { try { _StreamMonitor = new LiveStreamMonitorService(_TwitchApi, 30); _StreamMonitor.SetChannelsByName(SettingsManager.Configuration.TwitchStream.UsernameAsList); _StreamMonitor.Start(); _StreamMonitor.OnStreamOnline += OnStreamOnline; _StreamMonitor.OnStreamOffline += OnStreamOffline; LoggingManager.Log.Info($"Stream monitoring is running for: {SettingsManager.Configuration.TwitchStream.DisplayName}"); } catch (Exception ex) { LoggingManager.Log.Error(ex); } }
private async void ConfigLiveMonitorAsync() { API = new TwitchAPI(); Client = new TwitchClient(); Log = new LogHelper(); FindSettings(); API.Settings.ClientId = Settings.ClientId; API.Settings.AccessToken = Settings.AccessToken; // Monitor stuff Monitor = new LiveStreamMonitorService(API); Monitor.SetChannelsByName(Settings.MonitoredChannels); Monitor.OnStreamOnline += Monitor_OnStreamOnline; Monitor.OnStreamOffline += Monitor_OnStreamOffline; Monitor.OnStreamUpdate += Monitor_OnStreamUpdate; Monitor.OnServiceStarted += Monitor_OnServiceStarted; Monitor.OnChannelsSet += Monitor_OnChannelSet; Monitor.Start(); // Client Stuff ConnectionCredentials credentials = new ConnectionCredentials(Settings.BotConnectionDetails.UserName, Settings.BotConnectionDetails.OAuth); Client.Initialize(credentials, Settings.MonitoredChannels.FirstOrDefault()); Client.AddChatCommandIdentifier(Settings.ChatCommandIdentifier); Client.OnLog += Client_OnLog; Client.OnJoinedChannel += Client_OnJoinedChannel; Client.OnMessageReceived += Client_OnMessageReceived; Client.OnConnected += Client_OnConnected; Client.OnNewSubscriber += Client_OnNewSubscriber; Client.OnReSubscriber += Client_OnResubscriber; Client.OnGiftedSubscription += Client_GiftedSubscription; Client.OnChatCommandReceived += Client_OnChatCommandReceived; Client.Connect(); Log.SetBotUsername(Client.TwitchUsername); SetupCommands(); await Task.Delay(-1); }
private static async Task BindHandlers() { twitchAPI = new TwitchAPI(); twitchAPI.Settings.ClientId = CredentialsKeeper.TWITCH_CID; monitor = new LiveStreamMonitorService(twitchAPI, 60); Console.WriteLine("Starting binds"); monitor.SetChannelsByName(UserProvider.GetTwitchUsers()); monitor.OnStreamOnline += StreamEventHandler.OnStreamOnline; monitor.OnStreamOffline += StreamEventHandler.OnStreamOffline; monitor.OnServiceStarted += StreamEventHandler.OnServiceStarted; monitor.Start(); Console.WriteLine("Binds finished"); }
// Start the Twitch API service to monitor Livestreams private void StartApi() { TwitchAPI twitchAPI = new TwitchAPI(); twitchAPI.Settings.ClientId = CredentialsKeeper.TwitchId; twitchAPI.Settings.AccessToken = CredentialsKeeper.TwitchSecret; LiveStreamMonitorService monitor = new LiveStreamMonitorService(twitchAPI, 60); Console.WriteLine("Starting Twitch API services"); monitor.SetChannelsByName(UserProvider.GetTwitchUsers()); monitor.OnStreamOnline += _eventHandler.OnStreamOnline; monitor.OnStreamOffline += _eventHandler.OnStreamOffline; monitor.OnServiceStarted += _eventHandler.OnServiceStarted; monitor.Start(); Console.WriteLine("Twitch API services started"); }
public StreamNotifier(DiscordSocketClient discordClient) { Configuration = ConfigurationHost.Current; DiscordClient = discordClient; TwitchAPI = new TwitchAPI(); TwitchAPI.Settings.ClientId = EnvUtils.VariableOrThrow(Constants.Environment.TwitchClientId); TwitchAPI.Settings.AccessToken = EnvUtils.VariableOrThrow(Constants.Environment.TwitchBotToken); LiveStreamMonitor = new LiveStreamMonitorService(TwitchAPI, 20); LiveStreamMonitor.SetChannelsByName(Configuration.TwitchFriends.ToList()); LiveStreamMonitor.OnStreamOnline += async(s, e) => { await LiveStreamMonitor_OnStreamOnline(e); }; ConfigurationHost.ConfigurationChanged += ConfigurationChanged; }
public ServiceMonitor(IConfiguration config) { _config = config; var channels = _config.GetSection("Values:Twitch:Channels").Get <List <string> >(); _processFileName = $@"{_config["Values:BotAssembly:Directory"]}\{_config["Values:BotAssembly:Name"]}"; var twitchApi = new TwitchAPI(); twitchApi.Settings.ClientId = config["Values:Twitch:ClientId"]; twitchApi.Settings.AccessToken = config["Values:Twitch:AccessToken"]; _liveStreamMonitorService = new LiveStreamMonitorService(twitchApi); _liveStreamMonitorService.SetChannelsByName(channels); _liveStreamMonitorService.OnStreamOnline += async(s, e) => await LiveStreamMonitorServiceOnOnStreamOnline(s, e); _liveStreamMonitorService.OnStreamOffline += async(s, e) => await LiveStreamMonitorServiceOnOnStreamOffline(s, e); }
public async Task Run() { _logger.LogInformation($"{nameof(MarkEKraus.TwitchDiscordNotificationBot)} Start"); _twitchMonitor.SetChannelsByName( _config.Value.TwitchChannels .Select(channel => channel.Channel) .ToList()); _twitchMonitor.OnStreamOnline += Monitor_OnStreamOnline; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(TwitchApiExceptionHandler); // TwitchLib monintors treat already streaming streams as an OnStreamOnline. // This workaround uses a delay to ignore OnStreamOnline for a few seconds // after the monitor's first interval. _startNotificationTime = DateTime.Now.AddSeconds(_twitchMonitor.IntervalInSeconds + _delayNotificationsSeconds); _twitchMonitor.Start(); await Task.Delay(-1, _token); }
public void SetChannelsByName_Throws_ArgumentException_When_ChannelsArgumentEmpty() { _liveStreamMonitor = new LiveStreamMonitorService(_api); AssertException.Throws <ArgumentException>(ChannelListEmptyExceptionMessage, () => _liveStreamMonitor.SetChannelsByName(new List <string>())); }
public void SetChannelsByName_Throws_ArgumentNullException_When_ChannelsArgumentNull() { _liveStreamMonitor = new LiveStreamMonitorService(_api); AssertException.Throws <ArgumentNullException>(() => _liveStreamMonitor.SetChannelsByName(null)); }