public TwitchPubSubClient(
     string twitchChannelId,
     ITwitchPubSub twitchPubSub,
     ILoggerFactory loggerFactory)
 {
     _twitchChannelId = twitchChannelId;
     _logger          = loggerFactory.CreateLogger <TwitchPubSub>();
     if (_client == null)
     {
         _client = new TwitchPubSub(_logger);
         Init();
     }
 }
Пример #2
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;
 }
Пример #3
0
        /// <summary>
        /// Async main method
        /// </summary>
        /// <param name="args">Arguments</param>
        /// <returns>the Task</returns>
        private async Task MainAsync(string[] args)
        {
            var channelId   = mySettings.twitch.channelId;
            var clientId    = mySettings.twitch.api.clientId;
            var secret      = mySettings.twitch.api.secret;
            var accessToken = mySettings.twitch.token.userAccess;

            // Set up twitchlib api
            API = new AmongUsTwitchAPI(mySettings);
            API.getAPI().Settings.ClientId = clientId;
            API.getAPI().Settings.Secret = secret;

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

            // Create Among Us Twitch Channel Points
            await API.CreateAmongUsTwitchRewards();

            // Set up listeners
            ListenToRewards(channelId);

            // Connect to pubsub
            PubSub.Connect();

            // Sets up the pipe server
            pipeServer = new NamedPipeServerStream("AmongUsTwitchModPipe", PipeDirection.InOut, 4);
            sw         = new StreamWriter(pipeServer);
            sr         = new StreamReader(pipeServer);
            _logger.Information("NamedPipeServerStream object created.");

            // Wait for a client to connect
            _logger.Information("Waiting for client connection...");
            await pipeServer.WaitForConnectionAsync();

            _logger.Information("Client connected.");

            // Keep the program going
            await Task.Delay(Timeout.Infinite);
        }
Пример #4
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;
        }