Example #1
0
        private async Task UpdateChannelOverviewAsync(string updateChannel)
        {
            if (!(_client.GetChannel(Convert.ToUInt64(updateChannel)) is ITextChannel channel))
            {
                return;
            }
            try
            {
                var embeds = new List <Embed>
                {
                    TempusServerStatusService.GetServerStatusOverviewEmbed(
                        await _tempusDataAccess.GetServerStatusAsync()),
                    await TempusApiService.UpdateStalkTopEmbedAsync(_tempusDataAccess)
                };

                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));
            }
        }
Example #2
0
 public async Task ServerOverviewAsync()
 {
     await ReplyEmbedAsync(TempusServerStatusService.GetServerStatusOverviewEmbed(await TempusDataAccess.GetServerStatusAsync()));
 }