コード例 #1
0
ファイル: DiscordConnector.cs プロジェクト: tankyx/actools
 private async void UpdateSafe(DiscordConnection connection, DiscordRichPresence presence)
 {
     try {
         await connection.UpdateAsync(presence, _overrideProcessId ?? _processId);
     } catch (Exception e) {
         Utils.Warn(e.ToString());
     }
 }
コード例 #2
0
ファイル: DiscordConnector.cs プロジェクト: tankyx/actools
        private async Task RunAsync()
        {
            var delay = OptionMinReconnectionDelay;

            while (!IsDisposed)
            {
                try {
                    Utils.Log("(Re)creating connection…");
                    using (var connection = new DiscordConnection(_handler)) {
                        await connection.LaunchAsync(_clientId).ConfigureAwait(false);

                        delay = OptionMinReconnectionDelay;

                        _currentConnection = connection;
                        if (_currentPresence != null)
                        {
                            await connection.UpdateAsync(_currentPresence, _overrideProcessId ?? _processId).ConfigureAwait(false);
                        }

                        await connection.ListenAsync().ConfigureAwait(false);

                        if (connection.IsDisposed)
                        {
                            continue;
                        }
                    }
                } catch (TimeoutException e) {
                    Utils.Log(e.Message);
                } catch (IOException e) {
                    Utils.Warn(e.Message);
                } catch (DiscordException e) {
                    Utils.Warn(e.Message);
                } catch (Exception e) {
                    Utils.Warn(e.ToString());
                }

                _currentConnection = null;
                using (_currentDelay = new CancellationTokenSource()) {
                    await Task.Delay(delay, _currentDelay.Token).ConfigureAwait(false);
                }

                _currentDelay = null;
                delay         = TimeSpan.FromSeconds(Math.Min(delay.TotalSeconds * 2, OptionMaxReconnectionDelay.TotalSeconds));
            }
        }