コード例 #1
0
 public GiveGilCommand(GilBank gilBank, ITwitchClient twitchClient, ITwitchAPI api)
     : base(x => x.GiveGilCommandWords, x => true)
 {
     _gilBank      = gilBank;
     _twitchClient = twitchClient;
     _api          = api;
 }
コード例 #2
0
        public Server(ITwitchNETDALService twitchNETService,
                      TwitchClient client,
                      IBot bot,
                      IServerDTO serverDTO,
                      ITwitchAPI twitchAPI,
                      int maxMessagesInQueue)
        {
            _twitchNetService = twitchNETService;
            _serverDTO        = serverDTO;
            _bot                = bot;
            _twitchAPI          = twitchAPI;
            _maxMessagesInQueue = maxMessagesInQueue;

            _client = client;
            _client.OnUserJoined       += OnUserJoined;
            _client.OnUserLeft         += OnUserLeft;
            _client.OnJoinedChannel    += OnJoinedChannel;
            _client.OnMessageReceived  += OnMessageReceived;
            _client.OnNewSubscriber    += OnNewSubscriber;
            _client.OnLeftChannel      += OnLeaveChannel;
            _client.OnChatColorChanged += OnChatColorChanged;

            if (_client.IsConnected &&
                !_client.JoinedChannels.Any(s => s.Channel.Trim().ToLower() == serverDTO.Username.Trim().ToLower()))
            {
                _client.JoinChannel(_serverDTO.Username.Trim().ToLower());
            }
        }
コード例 #3
0
        /// <summary>
        /// Async main method
        /// </summary>
        /// <param name="args">Arguments</param>
        /// <returns>the Task</returns>
        private async Task MainAsync(string[] args)
        {
            var channelId = Settings.GetSection("twitch").GetValue <string>("channelId");

            //set up twitchlib api
            API = new TwitchAPI();
            API.Settings.ClientId = Settings.GetSection("twitch.api").GetValue <string>("client-id");
            API.Settings.Secret   = Settings.GetSection("twitch.api").GetValue <string>("secret");


            //Set up twitchlib pubsub
            PubSub = new TwitchPubSub();
            PubSub.OnListenResponse         += OnListenResponse;
            PubSub.OnPubSubServiceConnected += OnPubSubServiceConnected;
            PubSub.OnPubSubServiceClosed    += OnPubSubServiceClosed;
            PubSub.OnPubSubServiceError     += OnPubSubServiceError;

            //Set up listeners
            ListenToBits(channelId);
            ListenToChatModeratorActions(channelId, channelId);
            ListenToFollows(channelId);
            ListenToLeaderboards(channelId);
            ListenToPredictions(channelId);
            ListenToRaid(channelId);
            ListenToRewards(channelId);
            ListenToSubscriptions(channelId);
            ListenToVideoPlayback(channelId);
            ListenToWhispers(channelId);

            //Connect to pubsub
            PubSub.Connect();

            //Keep the program going
            await Task.Delay(Timeout.Infinite);
        }
コード例 #4
0
ファイル: AtAll.cs プロジェクト: EvanQuan/Chubberino
 public AtAll(ITwitchClientManager client,
              TextWriter writer,
              ITwitchAPI api)
     : base(client, writer)
 {
     Api = api;
 }
コード例 #5
0
        public LiveStreamMonitorService(ITwitchAPI api, int secondsBetweenChecks)
        {
            this.api = api;

            //Load the info for streams that have been reported on.
            //string monitoredUsersResult = SaveLoadService.Load(monitoredUsersFilename);
            Dictionary <string, Stream> monitoredChannels = SaveLoadService.Load <Dictionary <string, Stream> >(monitoredUsersFilename);

            if (monitoredChannels == null)
            {
                monitoredChannels = new Dictionary <string, Stream>();
                SaveLoadService.Save(monitoredUsersFilename, monitoredChannels);
            }

            LiveStreams.Clear();
            foreach (var key in monitoredChannels.Keys)
            {
                LiveStreams.TryAdd(key, monitoredChannels[key]);
            }

            // Call the check with the given interval between the calls.
            timer           = new Timer(TimeSpan.FromSeconds(secondsBetweenChecks).TotalMilliseconds);
            timer.AutoReset = true;
            timer.Elapsed  += new ElapsedEventHandler(Tick);
            timer.Start();
        }
コード例 #6
0
        public UnityFollowerService(ITwitchAPI api, int checkIntervalSeconds = 60, int queryCount = 25) : base(api, checkIntervalSeconds, queryCount)
        {
            ThreadDispatcher.EnsureCreated();

            base.OnServiceStarted       += ((object sender, OnServiceStartedArgs e) => { ThreadDispatcher.Enqueue(() => OnServiceStarted?.Invoke(sender, e)); });
            base.OnServiceStopped       += ((object sender, OnServiceStoppedArgs e) => { ThreadDispatcher.Enqueue(() => OnServiceStopped?.Invoke(sender, e)); });
            base.OnNewFollowersDetected += ((object sender, OnNewFollowersDetectedArgs e) => { ThreadDispatcher.Enqueue(() => OnNewFollowersDetected?.Invoke(sender, e)); });
        }
コード例 #7
0
 public TwitchRewardsManager(ILogger <TwitchRewardsManager> logger, ITwitchAPI twitchApi, ICustomRewardsHolder rewardsHolder, AppSettings settings)
 {
     this.logger        = logger;
     this.twitchApi     = twitchApi;
     this.rewardsHolder = rewardsHolder;
     this.settings      = settings;
     options            = new JsonSerializerOptions {
         WriteIndented = true, Converters = { new JsonStringEnumConverter(allowIntegerValues: true) }
     };
 }
コード例 #8
0
        /// <summary>
        /// The constructor from the LiveStreamMonitorService
        /// </summary>
        /// <exception cref="ArgumentNullException">When the <paramref name="api"/> is null.</exception>
        /// <exception cref="ArgumentException">When the <paramref name="checkIntervalInSeconds"/> is lower than one second.</exception>
        /// <exception cref="ArgumentException">When the <paramref name="maxStreamRequestCountPerRequest"/> is less than 1 or more than 100.</exception>
        /// <param name="api">The api used to query information.</param>
        /// <param name="checkIntervalInSeconds"></param>
        /// <param name="maxStreamRequestCountPerRequest"></param>
        public LiveStreamMonitorService(ITwitchAPI api, int checkIntervalInSeconds = 60, int maxStreamRequestCountPerRequest = 100) :
            base(api, checkIntervalInSeconds)
        {
            if (maxStreamRequestCountPerRequest < 1 || maxStreamRequestCountPerRequest > 100)
            {
                throw new ArgumentException("Twitch doesn't support less than 1 or more than 100 streams per request.", nameof(maxStreamRequestCountPerRequest));
            }

            MaxStreamRequestCountPerRequest = maxStreamRequestCountPerRequest;
        }
コード例 #9
0
        public TwitchBot(ConnectionCredentials credentials, string accessToken, string clientID, string channel)
        {
            _client = new TwitchClient();
            _client.Initialize(credentials, channel, Prefix, Prefix);
            _client.SetConnectionCredentials(credentials);

            _api = new TwitchAPI();
            _api.Settings.AccessToken = accessToken;
            _api.Settings.ClientId    = clientID;
        }
コード例 #10
0
        public UnityFollowerService(ITwitchAPI api, int checkIntervalSeconds = 60, int queryCount = 25) : base(api, checkIntervalSeconds, queryCount)
        {
            _threadDispatcher = new GameObject("ThreadDispatcher");
            _threadDispatcher.AddComponent <ThreadDispatcher>();
            UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

            base.OnServiceStarted       += ((object sender, OnServiceStartedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnServiceStarted?.Invoke(sender, e)); });
            base.OnServiceStopped       += ((object sender, OnServiceStoppedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnServiceStopped?.Invoke(sender, e)); });
            base.OnNewFollowersDetected += ((object sender, OnNewFollowersDetectedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnNewFollowersDetected?.Invoke(sender, e)); });
        }
コード例 #11
0
 /// <summary>Service constructor.</summary>
 /// <exception cref="BadResourceException">If channel is invalid, an InvalidChannelException will be thrown.</exception>
 /// <param name="checkIntervalSeconds">Param representing number of seconds between calls to Twitch Api.</param>
 /// <param name="queryCount">Number of recent followers service should request from Twitch Api. Max: 100, Min: 1</param>
 /// <param name="clientId">Optional param representing Twitch Api-required application client id, not required if already set.</param>
 public FollowerService(ITwitchAPI api, int checkIntervalSeconds = 60, int queryCount = 25, string clientId = "")
 {
     _api = api;
     CheckIntervalSeconds           = checkIntervalSeconds;
     QueryCount                     = queryCount;
     _followerServiceTimer.Elapsed += _followerServiceTimerElapsed;
     if (clientId != "")
     {
         ClientId = clientId;
     }
 }
コード例 #12
0
        public UnityLiveStreamMonitor(ITwitchAPI api, int checkIntervalSeconds = 60, int maxStreamRequestCountPerRequest = 100) : base(api, checkIntervalSeconds, maxStreamRequestCountPerRequest)
        {
            ThreadDispatcher.EnsureCreated();

            base.OnStreamOnline   += ((object sender, OnStreamOnlineArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamOnline?.Invoke(sender, e)); });
            base.OnStreamOffline  += ((object sender, OnStreamOfflineArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamOffline?.Invoke(sender, e)); });
            base.OnStreamUpdate   += ((object sender, OnStreamUpdateArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamUpdate?.Invoke(sender, e)); });
            base.OnServiceStarted += ((object sender, OnServiceStartedArgs e) => { ThreadDispatcher.Enqueue(() => OnServiceStarted?.Invoke(sender, e)); });
            base.OnServiceStopped += ((object sender, OnServiceStoppedArgs e) => { ThreadDispatcher.Enqueue(() => OnServiceStopped?.Invoke(sender, e)); });
            base.OnChannelsSet    += ((object sender, OnChannelsSetArgs e) => { ThreadDispatcher.Enqueue(() => OnChannelsSet?.Invoke(sender, e)); });
        }
コード例 #13
0
        public UnityLiveStreamMonitor(ITwitchAPI api, int checkIntervalSeconds = 60, bool checkStatusOnStart = true, bool invokeEventsOnStart = false) : base(api, checkIntervalSeconds, checkStatusOnStart, invokeEventsOnStart)
        {
            ThreadDispatcher.EnsureCreated();

            base.OnStreamOnline         += ((object sender, OnStreamOnlineArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamOnline?.Invoke(sender, e)); });
            base.OnStreamOffline        += ((object sender, OnStreamOfflineArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamOffline?.Invoke(sender, e)); });
            base.OnStreamUpdate         += ((object sender, OnStreamUpdateArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamUpdate?.Invoke(sender, e)); });
            base.OnStreamMonitorStarted += ((object sender, OnStreamMonitorStartedArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamMonitorStarted?.Invoke(sender, e)); });
            base.OnStreamMonitorEnded   += ((object sender, OnStreamMonitorEndedArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamMonitorEnded?.Invoke(sender, e)); });
            base.OnStreamsSet           += ((object sender, OnStreamsSetArgs e) => { ThreadDispatcher.Enqueue(() => OnStreamsSet?.Invoke(sender, e)); });
        }
コード例 #14
0
ファイル: TwitchBot.cs プロジェクト: SpyderHunter03/SpyderWeb
        // private readonly IDatabaseService<TwitchUser> _database;

        public TwitchBot(
            ILoggerFactory loggerFactory
            , ITwitchAPI twitchApi
            , IOptionsMonitor <Credentials> options
            // , IDatabaseService<TwitchUser> database
            )
        {
            _logger    = loggerFactory.CreateLogger("twitch");
            _twitchAPI = twitchApi;
            _options   = options.CurrentValue;
            // _database = database;
        }
コード例 #15
0
 public ServerManager(ITwitchNETDALService twitchNETService,
                      TwitchClient client,
                      ITwitchAPI twitchAPI,
                      IBot bot,
                      int maxNumberMessagesInQueue)
 {
     _twitchNetService = twitchNETService;
     _client           = client;
     _bot       = bot;
     _twitchAPI = twitchAPI;
     _maxNumberMessagesInQueue = maxNumberMessagesInQueue;
 }
コード例 #16
0
        public TwitchChatClient(TwitchClientSettings settings, ITwitchAPI twitchApi)
        {
            _settings  = settings;
            _twitchApi = twitchApi;
            var credentials = new ConnectionCredentials(settings.TwitchUsername, settings.TwitchOAuth);

            _twitchClient = new TwitchClient(credentials, settings.TwitchChannel);
            _twitchClient.OnChatCommandReceived += ChatCommandReceived;
            _twitchClient.OnNewSubscriber       += NewSubscriber;
            _twitchClient.OnUserJoined          += TwitchClientOnOnUserJoined;
            _twitchClient.OnUserLeft            += TwitchClientOnOnUserLeft;
        }
コード例 #17
0
ファイル: Events.cs プロジェクト: fredyfx/Aiva
        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);
        }
コード例 #18
0
        public UnityFollowerService(ITwitchAPI api, int checkIntervalSeconds = 60, bool checkStatusOnStart = true, bool invokeEventsOnStart = false) : base(api, checkIntervalSeconds, checkStatusOnStart, invokeEventsOnStart)
        {
            _threadDispatcher = new GameObject("ThreadDispatcher");
            _threadDispatcher.AddComponent <ThreadDispatcher>();
            UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

            base.OnStreamOnline         += ((object sender, OnStreamOnlineArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamOnline?.Invoke(sender, e)); });
            base.OnStreamOffline        += ((object sender, OnStreamOfflineArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamOffline?.Invoke(sender, e)); });
            base.OnStreamUpdate         += ((object sender, OnStreamUpdateArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamUpdate?.Invoke(sender, e)); });
            base.OnStreamMonitorStarted += ((object sender, OnStreamMonitorStartedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamMonitorStarted?.Invoke(sender, e)); });
            base.OnStreamMonitorEnded   += ((object sender, OnStreamMonitorEndedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamMonitorEnded?.Invoke(sender, e)); });
            base.OnStreamsSet           += ((object sender, OnStreamsSetArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamsSet?.Invoke(sender, e)); });
        }
コード例 #19
0
        public TwitchChatClient(TwitchClientSettings settings, ITwitchAPI twitchApi, ILoggerAdapter <TwitchChatClient> logger)
        {
            _settings  = settings;
            _twitchApi = twitchApi;
            _logger    = logger;
            var credentials = new ConnectionCredentials(settings.TwitchUsername, settings.TwitchBotOAuth);

            _twitchClient = new TwitchClient();
            _twitchClient.Initialize(credentials, channel: settings.TwitchChannel);
            _twitchClient.OnChatCommandReceived += ChatCommandReceived;
            _twitchClient.OnNewSubscriber       += NewSubscriber;
            _twitchClient.OnUserJoined          += TwitchClientOnOnUserJoined;
            _twitchClient.OnUserLeft            += TwitchClientOnOnUserLeft;
        }
コード例 #20
0
        public TwitchFollowerService(ITwitchAPI twitchApi, TwitchClientSettings settings)
        {
            _twitchApi = twitchApi;

            _settings = settings;

            _followerService = new FollowerService(twitchApi);

            _followerService.SetChannelByChannelId(settings.TwitchChannelId);

            _followerService.StartService().Wait();

            _followerService.OnNewFollowersDetected += FollowerServiceOnOnNewFollowersDetected;
        }
コード例 #21
0
ファイル: ApiService.cs プロジェクト: xRoier/TwitchLib.Api
        /// <summary>
        /// Constructor from the ApiService.
        /// </summary>
        /// <exception cref="ArgumentNullException">When the <paramref name="api"/> is null.</exception>
        /// <exception cref="ArgumentException">When the <paramref name="checkIntervalInSeconds"/> is lower than one second.</exception>
        /// <param name="api">The api used to query information.</param>
        /// <param name="checkIntervalInSeconds"></param>
        protected ApiService(ITwitchAPI api, int checkIntervalInSeconds)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            if (checkIntervalInSeconds < 1)
            {
                throw new ArgumentException("The interval must be 1 second or more.", nameof(checkIntervalInSeconds));
            }

            _api          = api;
            _serviceTimer = new ServiceTimer(OnServiceTimerTick, checkIntervalInSeconds);
        }
コード例 #22
0
        /// <summary>
        /// FollowerService constructor.
        /// </summary>
        /// <exception cref="ArgumentNullException">When the <paramref name="api"/> is null.</exception>
        /// <exception cref="ArgumentException">When the <paramref name="checkIntervalInSeconds"/> is lower than one second.</exception>
        /// <exception cref="ArgumentException">When the <paramref name="queryCountPerRequest" /> is less than 1 or more than 100 followers per request.</exception>
        /// <exception cref="ArgumentException">When the <paramref name="cacheSize" /> is less than the queryCountPerRequest.</exception>
        /// <param name="api">The api to use for querying followers.</param>
        /// <param name="checkIntervalInSeconds">How often new followers should be queried.</param>
        /// <param name="queryCountPerRequest">The amount of followers to query per request.</param>
        /// <param name="cacheSize">The maximum amount of followers to cache per channel.</param>
        public FollowerService(ITwitchAPI api, int checkIntervalInSeconds = 60, int queryCountPerRequest = 100, int cacheSize = 1000) :
            base(api, checkIntervalInSeconds)
        {
            if (queryCountPerRequest < 1 || queryCountPerRequest > 100)
            {
                throw new ArgumentException("Twitch doesn't support less than 1 or more than 100 followers per request.", nameof(queryCountPerRequest));
            }

            if (cacheSize < queryCountPerRequest)
            {
                throw new ArgumentException($"The cache size must be at least the size of the {nameof(queryCountPerRequest)} parameter.", nameof(cacheSize));
            }

            QueryCountPerRequest = queryCountPerRequest;
            CacheSize            = cacheSize;
        }
コード例 #23
0
 public ConsoleApplication(
     ILogger <ConsoleApplication> logger,
     IOptions <AppSettings> config,
     ITwitchAPI twitchApi,
     IApiSettings apiSettings,
     IWebhookService webhookService
     )
 {
     _logger         = logger;
     _config         = config;
     _twitchApi      = twitchApi;
     _apiSettings    = apiSettings;
     _webhookService = webhookService;
     _twitchMonitor  = new LiveStreamMonitorService(_twitchApi, config.Value.TwitchApiCheckIntervalSeconds);
     _token          = new CancellationToken();
 }
コード例 #24
0
        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;
        }
コード例 #25
0
 public TwitchBot(
     ILogger <TwitchBot> logger,
     AppSettings settings,
     ConnectionCredentials credentials,
     ITwitchAPI api,
     ITwitchPubSub pubSub,
     ITwitchClient client,
     IOnRewardHandler onRewardHandler,
     IOnMessageHandler onMessageHandler)
 {
     this.logger           = logger;
     this.settings         = settings;
     this.credentials      = credentials;
     this.api              = api;
     this.pubSub           = pubSub;
     this.client           = client;
     this.onRewardHandler  = onRewardHandler;
     this.onMessageHandler = onMessageHandler;
 }
コード例 #26
0
        public AmongUsTwitchAPI(Settings settings)
        {
            var outputTemplate = "[{Timestamp:HH:mm:ss} {Level}] {Message}{NewLine}{Exception}";

            _logger = new LoggerConfiguration()
                      .Enrich.FromLogContext()
                      .WriteTo.Console(outputTemplate: outputTemplate)
                      .WriteTo.File("log/api_log_.txt", outputTemplate: outputTemplate, rollingInterval: RollingInterval.Day)
                      .CreateLogger();

            rewards = new Dictionary <int, CustomReward>();

            API = new TwitchAPI();

            this.channelId    = settings.twitch.channelId;
            this.clientId     = settings.twitch.api.clientId;
            this.secret       = settings.twitch.api.secret;
            this.accessToken  = settings.twitch.token.userAccess;
            this.refreshToken = settings.twitch.token.refresh;
        }
コード例 #27
0
        public TwitchService
        (
            string clientId,
            ConfigurationService configurationService,
            ISpeechSynthesizerService speechSynthesizerService,
            ITwitchAPI api       = null,
            ITwitchPubSub pubSub = null,
            ITwitchClient client = null
        )
        {
            if (string.IsNullOrWhiteSpace(clientId))
            {
                throw new ArgumentException(Resources.Argument_cannot_be_null_or_whitespace_, nameof(clientId));
            }

            _configurationService     = configurationService;
            _speechSynthesizerService = speechSynthesizerService;
            _twitchApi    = api ?? new TwitchAPI();
            _twitchPubSub = pubSub ?? new TwitchPubSub();

            _twitchClient = client ?? new TwitchClient();

            ClientId = clientId;
        }
コード例 #28
0
 public TopViewersDiscovery(ITwitchAPI api)
 {
     _api = api;
 }
コード例 #29
0
 protected CoreMonitor(ITwitchAPI api)
 {
     _api = api;
 }
コード例 #30
0
 public NameBasedMonitor(ITwitchAPI api) : base(api)
 {
 }