예제 #1
0
        private async Task WebSocketClosed()
        {
            Log.Warning("Patreon WebSocket was closed. Retrying in 10 seconds...");
            await Task.Delay(10000);

            RiasUtilities.RunTask(() => ConnectWebSocket(true));
        }
예제 #2
0
        public VotesService(IServiceProvider serviceProvider)
            : base(serviceProvider)
        {
            if (Configuration.VotesConfiguration == null)
            {
                return;
            }

            _webSocket = new WebSocketClient(Configuration.VotesConfiguration);
            RiasUtilities.RunTask(() => ConnectWebSocket());
            _webSocket.DataReceived += VoteReceivedAsync;
            _webSocket.Closed       += WebSocketClosed;

            RiasUtilities.RunTask(CheckVotesAsync);
        }
예제 #3
0
        public PatreonService(IServiceProvider serviceProvider)
            : base(serviceProvider)
        {
            if (Configuration.PatreonConfiguration is null)
            {
                return;
            }

            _webSocket = new WebSocketClient(Configuration.PatreonConfiguration);
            RiasUtilities.RunTask(() => ConnectWebSocket());
            _webSocket.DataReceived += PledgeReceivedAsync;
            _webSocket.Closed       += WebSocketClosed;

            RiasUtilities.RunTask(CheckPatronsAsync);

            _httpClient         = serviceProvider.GetRequiredService <IHttpClientFactory>().CreateClient();
            _httpClient.Timeout = TimeSpan.FromMinutes(1);
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Configuration.PatreonConfiguration.Authorization !);
            _sendPatronsTimer = new Timer(_ => RiasUtilities.RunTask(SendPatronsAsync), null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
        }
예제 #4
0
        private async Task ConnectWebSocket(bool recheckPatrons = false)
        {
            while (true)
            {
                try
                {
                    await _webSocket !.ConnectAsync();
                    Log.Information("Patreon WebSocket connected");

                    if (recheckPatrons)
                    {
                        RiasUtilities.RunTask(CheckPatronsAsync);
                    }

                    break;
                }
                catch
                {
                    Log.Warning("Patreon WebSocket couldn't connect. Retrying in 10 seconds...");
                    await Task.Delay(10000);
                }
            }
        }