Beispiel #1
0
        private async Task UpdateChannelAsync(string updateChannel)
        {
            if (!(_client.GetChannel(Convert.ToUInt64(updateChannel)) is ITextChannel channel))
            {
                return;
            }
            try
            {
                var activity = await _tempusDataAccess.GetRecentActivityAsync();

                var embeds = new List <Embed>
                {
                    TempusActivityService.GetMapRecordsEmbed(activity.MapRecords),
                    TempusActivityService.GetMapTopTimesEmbed(activity.MapTopTimes),
                    TempusActivityService.GetCourseRecordsEmbed(activity.CourseRecords),
                    TempusActivityService.GetBonusRecordsEmbed(activity.BonusRecords)
                };

                var existingMessages = (await channel.GetMessagesAsync().FlattenAsync()).ToList();

                foreach (var embed in embeds)
                {
                    var existingMessage = existingMessages.FirstOrDefault(x =>
                                                                          x.Embeds.Count == 1 && x.Embeds.First().Title == embed.Title);

                    if (existingMessage != null && existingMessage is IUserMessage userMessage)
                    {
                        await userMessage.ModifyAsync(message => message.Embed = embed);

                        existingMessages.Remove(existingMessage);
                    }
                    else
                    {
                        await channel.SendMessageAsync(embed : embed);
                    }
                }

                if (existingMessages.Count > 0)
                {
                    foreach (var oldMessage in existingMessages)
                    {
                        await oldMessage.DeleteAsync();
                    }
                }
            }
            catch (Exception e)
            {
                await channel.SendMessageAsync(embed : Logger.LogException(e));
            }
        }
Beispiel #2
0
        public async Task GetRecentBonusRecordsAsync()
        {
            var activity = await TempusDataAccess.GetRecentActivityAsync();

            await ReplyEmbedAsync(TempusActivityService.GetBonusRecordsEmbed(activity.BonusRecords));
        }