示例#1
0
文件: Bot.cs 项目: ZombieCorn80/WhMgr
        /// <summary>
        /// Stop the Discord bot(s)
        /// </summary>
        /// <returns></returns>
        public async Task Stop()
        {
            _logger.Trace("Stop");
            _logger.Info("Disconnecting from Discord...");

            // Loop through each Discord server and terminate the connection
            foreach (var(guildId, client) in _servers)
            {
                _logger.Info($"Attempting disconnection from Discord server {guildId}");
                await client.DisconnectAsync();

                await Task.Delay(1000);
            }

            // Unregister alarm event handlers
            _whm.PokemonAlarmTriggered    -= OnPokemonAlarmTriggered;
            _whm.RaidAlarmTriggered       -= OnRaidAlarmTriggered;
            _whm.QuestAlarmTriggered      -= OnQuestAlarmTriggered;
            _whm.PokestopAlarmTriggered   -= OnPokestopAlarmTriggered;
            _whm.GymAlarmTriggered        -= OnGymAlarmTriggered;
            _whm.GymDetailsAlarmTriggered -= OnGymDetailsAlarmTriggered;
            _whm.WeatherAlarmTriggered    -= OnWeatherAlarmTriggered;
            if (_whConfig.Instance.Servers.FirstOrDefault(x => x.Value.Subscriptions.Enabled).Value != null)
            {
                //At least one server wanted subscriptions, unregister the subscription event handlers
                _whm.PokemonSubscriptionTriggered  -= OnPokemonSubscriptionTriggered;
                _whm.RaidSubscriptionTriggered     -= OnRaidSubscriptionTriggered;
                _whm.QuestSubscriptionTriggered    -= OnQuestSubscriptionTriggered;
                _whm.InvasionSubscriptionTriggered -= OnInvasionSubscriptionTriggered;
            }
            _whm.Stop();

            _logger.Info("WebhookManager is stopped...");
        }
示例#2
0
文件: Bot.cs 项目: diendanyoi54/WhMgr
        /// <summary>
        /// Stop the Discord bot(s)
        /// </summary>
        /// <returns></returns>
        public async Task Stop()
        {
            _logger.Trace("Stop");
            _logger.Info("Disconnecting from Discord...");

            // Loop through each Discord server and terminate the connection
            var keys = _servers.Keys.ToList();

            for (var i = 0; i < keys.Count; i++)
            {
                var guildId = keys[i];
                var client  = _servers[guildId];

                _logger.Info($"Attempting connection to Discord server {guildId}");
                await client.DisconnectAsync();

                await Task.Delay(1000);
            }

            // Unregister alarm event handlers
            _whm.PokemonAlarmTriggered    -= OnPokemonAlarmTriggered;
            _whm.RaidAlarmTriggered       -= OnRaidAlarmTriggered;
            _whm.QuestAlarmTriggered      -= OnQuestAlarmTriggered;
            _whm.PokestopAlarmTriggered   -= OnPokestopAlarmTriggered;
            _whm.GymAlarmTriggered        -= OnGymAlarmTriggered;
            _whm.GymDetailsAlarmTriggered -= OnGymDetailsAlarmTriggered;
            _whm.WeatherAlarmTriggered    -= OnWeatherAlarmTriggered;
            if (_whConfig.Servers.FirstOrDefault(x => x.Value.EnableSubscriptions).Value != null)
            {
                //At least one server wanted subscriptions, unregister the subscription event handlers
                _whm.PokemonSubscriptionTriggered  -= OnPokemonSubscriptionTriggered;
                _whm.RaidSubscriptionTriggered     -= OnRaidSubscriptionTriggered;
                _whm.QuestSubscriptionTriggered    -= OnQuestSubscriptionTriggered;
                _whm.InvasionSubscriptionTriggered -= OnInvasionSubscriptionTriggered;
            }
            _whm.Stop();

            _logger.Info("WebhookManager is stopped...");
        }