public SubPointsHandler(BotConfig config, TwitchClient client, TwitchPubSub pubSub, TwitchAPI api, SlothyService slothySvc)
 {
     _config    = config;
     _client    = client;
     _pubSub    = pubSub;
     _api       = api;
     _slothySvc = slothySvc;
 }
示例#2
0
        public SlothyBetCommandHandler(TwitchClient client, SlothyBetService betSvc, SlothyService slothySvc)
        {
            _client    = client;
            _betSvc    = betSvc;
            _slothySvc = slothySvc;

            _isBettingOpen        = false;
            _canProcessBets       = false;
            _canProcessCorrection = false;
        }
 public SlothyCommandHandler(TwitchClient client, TwitchAPI api, SlothyService slothySvc)
 {
     _client    = client;
     _api       = api;
     _slothySvc = slothySvc;
 }
示例#4
0
        public async Task RealMainAsync()
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("config.json")
                         .Build();

            _config = new BotConfig(config);

            AppDomain.CurrentDomain.UnhandledException += async(_, e) =>
                                                          await Utils.SendDiscordErrorWebhookAsync($"{_config.DiscordWebhookUserPing}: Error with Twitch bot, check logs.", _config.DiscordWebhookUrl);

            _api = new TwitchAPI();
            _api.Settings.ClientId    = _config.TwitchClientId;
            _api.Settings.AccessToken = _config.TwitchOAuth;
            _client = new TwitchClient();
            _client.Initialize(new ConnectionCredentials(_config.TwitchUsername, _config.TwitchOAuth));

            _client.OnConnected     += ChatConnected;
            _client.OnJoinedChannel += (_, e) => Utils.LogToConsole($"Joined chat channel {e.Channel}");

            _client.OnChatCommandReceived += CommandHandler;
            _client.OnConnectionError     += ChatConnectionError;
            _client.OnDisconnected        += ChatDisconnected;
            _client.OnError          += ChatError;
            _client.OnIncorrectLogin += ChatIncorrectLogin;

            _client.AddChatCommandIdentifier('!');

            _pubSub = new TwitchPubSub();

            _slothySvc = new SlothyService();
            await _slothySvc.InitializeAsync();

            _multiHandler = new MultitwitchCommandHandler(_client, _api);
            await _multiHandler.InitializeAsync();

            _crendorQuoteHandler = new QuoteCommandHandler <CrendorQuoteRecord>(_client);
            await _crendorQuoteHandler.InitializeAsync();

            _omarQuoteHandler = new QuoteCommandHandler <OmarQuoteRecord>(_client);
            await _omarQuoteHandler.InitializeAsync();

            _betSvc = new SlothyBetService();
            await _betSvc.InitializeAsync();

            _slothyHandler    = new SlothyCommandHandler(_client, _api, _slothySvc);
            _slothFactHandler = new SlothFactCommandHandler(_client);
            _woppyHandler     = new WoppyCommandHandler(_config, _client);

            _slothyBetCommandHandler = new SlothyBetCommandHandler(_client, _betSvc, _slothySvc);
            await _slothyBetCommandHandler.InitializeAsync();

            ConnectChat();

            _pubSub.OnPubSubServiceConnected += PubSubConnected;
            _pubSub.OnPubSubServiceClosed    += PubSubClosed;
            _pubSub.OnPubSubServiceError     += PubSubClosed;
            _pubSub.OnListenResponse         += ListenResponse;

            _subPointsHandler = new SubPointsHandler(_config, _client, _pubSub, _api, _slothySvc);
            await _subPointsHandler.InitializeAsync();

            _stretchTimerHandler = new StretchTimerHandler(_config, _client, _pubSub);

            _pubSubReconnectTimer = new Timer(_ => ReconnectPubSub(), null, TimeSpan.Zero, TimeSpan.FromHours(18));

            await Task.Delay(-1);
        }