private async void MandarMensaje_CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            mensajes.Add(new Mensaje(false, ChatTextBox.Text));
            Mensaje mensajeBot = new Mensaje(true, "Pensando...");

            mensajes.Add(mensajeBot);

            string respuesta = "";

            try
            {
                var cliente = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Properties.Settings.Default.EndPointKey))
                {
                    RuntimeEndpoint = Properties.Settings.Default.EndPoint
                };
                QnASearchResultList response = await cliente.Runtime.GenerateAnswerAsync(Properties.Settings.Default.KnowledgeBaseId, new QueryDTO { Question = ChatTextBox.Text });

                respuesta = response.Answers[0].Answer;
            }
            catch (IOException)
            {
                respuesta = "Estoy muy cansado para hablar";
            }

            mensajeBot.Texto = respuesta;
            ChatTextBox.Text = "";
            ChatScrollViewer.ScrollToVerticalOffset(ChatScrollViewer.ExtentHeight);
        }
Beispiel #2
0
        public void SendMessage(string Text, Player Speaker = null, bool Host = false)
        {
            if (CurrentRoom.IsHost(App.CurrentUser))
            {
                foreach (var Client in App.Server)
                {
                    Client.SendAsync(Encoding.UTF8.GetBytes("ChatMessage|*|" +
                                                            (Speaker?.Id.ToString() ?? "System") + "|*|" + Text));
                }
            }
            else
            {
                App.Client.SendAsync(Encoding.UTF8.GetBytes("ChatMessage|*|" +
                                                            (Speaker?.Id.ToString() ?? "System") + "|*|" + Text));
            }

            bool        ScrollToBottom = ChatScrollViewer.HorizontalOffset >= ChatStack.ActualHeight - ChatScrollViewer.ActualHeight;
            ChatterItem Item           = new ChatterItem();

            Item.Init(Text, Speaker, Host);

            Item.Opacity = 0;
            ChatStack.Children.Add(Item);
            var HeightAnimation = new DoubleAnimation()
            {
                From           = ChatStack.ActualHeight,
                To             = ChatStack.Children.OfType <FrameworkElement>().Sum(O => O.Height),
                Duration       = TimeSpan.FromSeconds(0.3),
                EasingFunction = new ExponentialEase()
                {
                    EasingMode = EasingMode.EaseInOut
                }
            };

            HeightAnimation.Completed += delegate
            {
                Item.BeginAnimation(OpacityProperty, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 1,
                    Duration       = TimeSpan.FromSeconds(0.2),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    }
                });
                if (ScrollToBottom)
                {
                    ChatScrollViewer.ScrollToBottom();
                }
            };
            ChatStack.BeginAnimation(HeightProperty, HeightAnimation);
        }
Beispiel #3
0
        public void AppendPlayerText(KeyValuePair <string, string> player, bool isIn)
        {
            var text = $"[ {DateTime.UtcNow.UtcToLocalFromSettings():HH:mm:ss} ] ";

            var p = new Paragraph
            {
                Margin     = new Thickness(0),
                Foreground = new SolidColorBrush(isIn ? Colors.Green : Colors.Red),
                FontSize   = 13
            };
            // remove indent between paragraphs

            var link = new Hyperlink
            {
                IsEnabled   = true,
                DataContext = player.Key
            };

            link.Inlines.Add(player.Value);
            link.NavigateUri      = new Uri("http://local/");
            link.RequestNavigate += (sender, args) =>
            {
                var context = (sender as FrameworkContentElement)?.DataContext as string;
                if (string.IsNullOrEmpty(context) == false)
                {
                    var aggregator = ServiceLocator.Current.TryResolve <IEventAggregator>();
                    aggregator.GetEvent <ShowUserInfoEvent>().Publish(new ShowUserModel(context));
                }
            };

            p.Inlines.Add(text);
            p.Inlines.Add(link);
            p.Inlines.Add(new Run(isIn ? " Connected" : " Disconnected")
            {
                FontSize = 10
            });

            msgBox.Document.Blocks.Add(p);

            if (IsAutoScroll)
            {
                ChatScrollViewer.ScrollToEnd();
            }
        }
        private async void SendMessage_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            isThinking = true;
            string pregunta = MensajeTextBox.Text.ToString();

            listMessages.Add(new Message(Message.SenderMessage.Person, pregunta));
            MensajeTextBox.Text = "";

            try
            {
                await botQnM.SendQuestion(pregunta, listMessages);
            }
            catch (Exception)
            {
                listMessages.Add(new Message(Message.SenderMessage.Bot, "Algo va mal..."));
            }
            ChatScrollViewer.ScrollToEnd();
            isThinking = false;
        }
Beispiel #5
0
        public ProgressItem BeginProgress(string Description, double Length)
        {
            bool        ScrollToBottom = ChatScrollViewer.HorizontalOffset >= ChatStack.ActualHeight - ChatScrollViewer.ActualHeight;
            ChatterItem Item           = new ChatterItem();
            var         ProgressItem   = Item.SystemProgressInit(Description, Length);

            Item.Opacity = 0;
            ChatStack.Children.Add(Item);
            var HeightAnimation = new DoubleAnimation()
            {
                From           = ChatStack.ActualHeight,
                To             = ChatStack.Children.OfType <FrameworkElement>().Sum(O => O.Height),
                Duration       = TimeSpan.FromSeconds(0.3),
                EasingFunction = new ExponentialEase()
                {
                    EasingMode = EasingMode.EaseInOut
                }
            };

            HeightAnimation.Completed += delegate
            {
                Item.BeginAnimation(OpacityProperty, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 1,
                    Duration       = TimeSpan.FromSeconds(0.2),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    }
                });
                if (ScrollToBottom)
                {
                    ChatScrollViewer.ScrollToBottom();
                }
            };
            ChatStack.BeginAnimation(HeightProperty, HeightAnimation);

            return(ProgressItem);
        }
Beispiel #6
0
        public void SendMessageAlone(string Text, Player Speaker = null, bool Host = false)
        {
            bool        ScrollToBottom = ChatScrollViewer.HorizontalOffset >= ChatStack.ActualHeight - ChatScrollViewer.ActualHeight;
            ChatterItem Item           = new ChatterItem();

            Item.Init(Text, Speaker, Host);

            Item.Opacity = 0;
            ChatStack.Children.Add(Item);
            var HeightAnimation = new DoubleAnimation()
            {
                From           = ChatStack.ActualHeight,
                To             = ChatStack.Children.OfType <FrameworkElement>().Sum(O => O.Height),
                Duration       = TimeSpan.FromSeconds(0.3),
                EasingFunction = new ExponentialEase()
                {
                    EasingMode = EasingMode.EaseInOut
                }
            };

            HeightAnimation.Completed += delegate
            {
                Item.BeginAnimation(OpacityProperty, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 1,
                    Duration       = TimeSpan.FromSeconds(0.2),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    }
                });
                if (ScrollToBottom)
                {
                    ChatScrollViewer.ScrollToBottom();
                }
            };
            ChatStack.BeginAnimation(HeightProperty, HeightAnimation);
        }
Beispiel #7
0
        private void InputTextBox_OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Return)
            {
                return;
            }

            string text = InputTextBox.Text;

            // Check for slash command
            if (text.IndexOf('/') == 0)
            {
                SlashParser.Parse(this, text);
            }
            else
            {
                // Send to active channel
                Client.ChannelMessage(text);
            }

            // Clear input, scroll to bottom
            InputTextBox.Text = string.Empty;
            ChatScrollViewer.ScrollToBottom();
        }
Beispiel #8
0
        public ChatView()
        {
            ViewModel = new ChatViewModel();


            App.RustRcon.ChatLogUpdated += (s, args) =>
            {
                if (ViewModel.ChatSettings.IsAutoScrollEnabled)
                {
                    ChatScrollViewer.ScrollToBottom();
                }
            };

            App.RustRcon.ChatLogUpdated += (s, args) =>
            {
                string message = args.Message;
                //Console.WriteLine("Message: {0}", message);
                if (ViewModel.ChatSettings.IsTimestampingEnabled)
                {
                    message = args.Timestamp.ToString("(hh:mm tt) ") + message;
                }

                //var p = new Paragraph();
                //var part1 = new Run(message.Substring(0, message.Length / 2));
                //part1.Background = Brushes.Black;
                //part1.Foreground = Brushes.White;

                //var part2 = new Run(message.Substring(message.Length / 2, (message.Length / 2) - 1));
                //p.Inlines.Add(part1);
                //p.Inlines.Add(part2);

                //ChatTextBox.Document.Blocks.Add(p);

                //ChatTextBox.AppendText(message);
                //ChatTextBox.
                //if(message.Contains("admin"))
                //{
                //    //var start = ChatTextBox.Document.ContentEnd.GetLineStartPosition(0);
                //    //var end= ChatTextBox.Document.ContentEnd;

                //    //TextRange range = new TextRange(start, end);
                //    //range.ApplyPropertyValue(RichTextBox.ForegroundProperty, Brushes.Red);
                //    //ChatTextBox.Document.Blocks.LastBlock.Foreground = Brushes.Red;
                //}

                //ChatTextBox.AppendText(Environment.NewLine);
                //ChatTextBox.Document.Blocks.LastBlock.Foreground = Brushes.Black;

                var run = new Run(message);
                if (ViewModel.ChatSettings.IsNotificationsEnabled && ViewModel.ChatSettings.NotificationWords != null)
                {
                    foreach (var notificationWord in ViewModel.ChatSettings.NotificationWords)
                    {
                        if (message.Contains(notificationWord))
                        {
                            run.Foreground = new SolidColorBrush(Color.FromRgb(68, 138, 255));

                            if (ViewModel.ChatSettings.IsFlashWindowNotificationEnabled)
                            {
                                Application.Current.MainWindow.FlashWindow();
                            }
                            break;
                        }
                    }
                }

                // TODO: Fix this when garry adds steamids to chat messages
                //if(ViewModel.AutoModerationSettings.IsChatModerationEnabled)
                //{
                //    foreach(var kickWord in ViewModel.AutoModerationSettings.ChatKickModerationWords)
                //    {
                //        if(message.Contains(kickWord))
                //        {
                //            App.RustRcon.KickPlayer(
                //        }
                //    }
                //}

                ChatTextBox.Document.Blocks.Add(new Paragraph(run));

                //Chat += message;
            };
            InitializeComponent();
        }