コード例 #1
0
        /// <summary>
        ///     Attempts to update the existing announcement message.
        ///     If failure to update after
        ///     <value>_failedRetryCount</value>
        ///     (default 60) tries, the message is
        ///     assumed to be lost, and will be recreated. This may result in double announcement messages that require
        ///     manual cleanup.
        /// </summary>
        /// <returns></returns>
        private async Task UpdateAnnouncementMessage()
        {
            try
            {
                //Compare the current event edit time with the last know.
                //The current event edit time will be different from last known if the event has changed.
                var eventEditTime = _calendar.GetTestEventNoUpdate().EventEditTime;
                if (eventEditTime != null && eventEditTime.Value.Equals(_lastSeenEditTime))
                {
                    await PlaytestAnnouncementMessage.ModifyAsync(x =>
                    {
                        x.Embed = _announcementMessage.CreatePlaytestEmbed(
                            _calendar.GetTestEventNoUpdate().IsCasual);
                    });

                    _failedToFetch = 0;
                }
                else
                {
                    //Being in this else means we know the message is different, remake it.
                    await _data.AnnouncementChannel.DeleteMessageAsync(PlaytestAnnouncementMessage);
                    await PostNewAnnouncement();
                }

                var lastEditTime = _calendar.GetTestEventNoUpdate().LastEditTime;
                if (lastEditTime != null)
                {
                    _lastSeenEditTime = lastEditTime.Value;
                }
            }
            catch
            {
                //Have we failed enough to rebuild?
                if (_failedToFetch >= _failedRetryCount)
                {
                    _ = _log.LogMessage($"Tried to update announcement messages {_failedToFetch}, but failed." +
                                        "\nCreated a new message next time.", false, color: LOG_COLOR);
                    PlaytestAnnouncementMessage = null;
                }
                else
                {
                    //Have not failed enough, lets keep trying.
                    _failedToFetch++;
                    if (_data.RSettings.ProgramSettings.Debug)
                    {
                        _ = _log.LogMessage($"Failed to update playtest announcement {_failedToFetch} times", false,
                                            color: LOG_COLOR);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Attempts to update the existing announcement message.
        ///     If failure to update after
        ///     <value>_failedRetryCount</value>
        ///     (default 60) tries, the message is
        ///     assumed to be lost, and will be recreated. This may result in double announcement messages that require
        ///     manual cleanup.
        /// </summary>
        /// <returns></returns>
        private async Task UpdateAnnouncementMessage(PlaytestEvent playtestEvent)
        {
            if (_dataService.RSettings.ProgramSettings.Debug)
            {
                _ = _log.LogMessage($"Updating playtest announcement for {playtestEvent.Title}", false,
                                    color: LOG_COLOR);
            }

            try
            {
                //Compare the current title and the last known title.
                if (_knownTests.ContainsKey(playtestEvent.Game) &&
                    playtestEvent.EventEditTime.Value.Equals(_knownTests[playtestEvent.Game]))
                {
                    await playtestEvent.AnnouncementMessage.ModifyAsync(x =>
                    {
                        x.Embed = _announcementMessage.CreatePlaytestEmbed(playtestEvent);
                    });

                    _failedToFetch = 0;
                }
                else
                {
                    //Being in this else means we know the message is different, remake it.
                    await playtestEvent.AnnouncmentChannel.DeleteMessageAsync(playtestEvent.AnnouncementMessage);
                    await PostNewAnnouncement(playtestEvent);
                }
            }
            catch
            {
                //Have we failed enough to rebuild?
                if (_failedToFetch >= _failedRetryCount)
                {
                    _ = _log.LogMessage($"Tried to update announcement message {_failedToFetch} times, but failed." +
                                        "\nCreated a new message next time.", false, color: LOG_COLOR);
                    playtestEvent.SetAnnouncementMessage(null);
                }
                else
                {
                    //Have not failed enough, lets keep trying.
                    _failedToFetch++;
                    if (_dataService.RSettings.ProgramSettings.Debug)
                    {
                        _ = _log.LogMessage($"Failed to update playtest announcement {_failedToFetch} times", false,
                                            color: LOG_COLOR);
                    }
                }
            }
        }