예제 #1
0
        private Task DiscordClient_MessageDeleted(ulong msgId, Optional <SocketMessage> msg)
        {
            var found = ChatLogList.FirstOrDefault(x => x.Id == msgId);

            if (found.Id == 0)
            {
                return(Task.CompletedTask);
            }
            DispatcherHelper.CheckBeginInvokeOnUI(() => {
                ChatLogList.Remove(found);
            });
            return(Task.CompletedTask);
        }
예제 #2
0
        private void AddChatMessageToChatLog(IMessage message)
        {
            Color roleColor = new Color(0xff, 0xff, 0xff);
            var   server    = LocatorService.DiscordSocketClient.GetGuild(selectedGuildId);
            var   guildUser = server.GetUser(message.Author.Id);

            // todo: figure out how to pick 'highest' role and take that color
            foreach (var role in guildUser.Roles)
            {
                if (!role.IsEveryone)
                {
                    roleColor = role.Color;
                }
            }

            // Serialize UI update to the main UI thread
            bool sameAuthor = message.Author.Id == lastAuthorId;

            lastAuthorId = message.Author.Id;

            DispatcherHelper.CheckBeginInvokeOnUI(() => {
                if (sameAuthor)
                {
                    ChatLogList.Add(new ChatTextListModel {
                        Id            = message.Id,
                        Username      = "",
                        UserRoleColor = roleColor.ToWinColor(),
                        ChatText      = GetReplacedMessageText(message),
                        TimeSent      = message.Timestamp.ToLocalTime().ToString("g"),
                        TimeEdited    = message.EditedTimestamp?.ToLocalTime().ToString("g"),
                        AvatarUrl     = "",
                        Embeds        = message.Embeds,
                        Attachments   = message.Attachments
                    });
                }
                else
                {
                    ChatLogList.Add(new ChatTextListModel {
                        Id            = message.Id,
                        Username      = message.Author.Username,
                        UserRoleColor = roleColor.ToWinColor(),
                        ChatText      = GetReplacedMessageText(message),
                        TimeSent      = message.Timestamp.ToLocalTime().ToString("g"),
                        TimeEdited    = message.EditedTimestamp?.ToLocalTime().ToString("g"),
                        AvatarUrl     = message.Author.GetAvatarUrlOrDefault(),
                        Embeds        = message.Embeds,
                        Attachments   = message.Attachments
                    });
                }
            });
        }
예제 #3
0
        private async Task PopulateChatLog()
        {
            ChatLogList.Clear();
            lastAuthorId = 0L;
            IEnumerable <IMessage> messageLog = null;

            // todo: use message.type or something
            if (selectedGuildId == 0L)
            {
                var channel = LocatorService.DiscordSocketClient.GetChannel(channelId) as SocketDMChannel;
                messageLog = await channel.GetMessagesAsync(40).Flatten().ConfigureAwait(false);
            }
            else
            {
                var channel = LocatorService.DiscordSocketClient.GetChannel(channelId) as SocketTextChannel;
                messageLog = await channel.GetMessagesAsync(40).Flatten().ConfigureAwait(false);
            }

            foreach (var message in messageLog.Reverse())
            {
                AddChatMessageToChatLog(message);
            }
        }
예제 #4
0
        private Task DiscordClient_MessageUpdated(Optional <SocketMessage> before, SocketMessage after)
        {
            if (after.Channel.Id != selectedChannel.ChannelId)
            {
                return(Task.CompletedTask);
            }

            var found = ChatLogList.FirstOrDefault(x => x.Id == after.Id);

            // didnt find
            if (found.Id == 0)
            {
                return(Task.CompletedTask);
            }

            DispatcherHelper.CheckBeginInvokeOnUI(() => {
                found.ChatText    = GetReplacedMessageText(after);
                found.TimeEdited  = after.EditedTimestamp?.ToLocalTime().ToString("g");
                found.Embeds      = after.Embeds;
                found.Attachments = after.Attachments;
                chatLogList.Refresh();
            });
            return(Task.CompletedTask);
        }