Пример #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("User Name:");
            userName = Console.ReadLine();

            service = new ChatService();
            service.OnReceivedMessage += Service_OnReceivedMessage;


            await service.InitAsync(userName);

            Console.WriteLine("You are now connected");

            var keepGoing = true;

            do
            {
                var text = Console.ReadLine();
                if (text == "exit")
                {
                    await service.DisconnectAsync();

                    keepGoing = false;
                }
                else
                {
                    var message = new SimpleTextMessage(userName)
                    {
                        Text = text
                    };
                    await service.SendMessageAsync(message);
                }
            } while (keepGoing);
        }
Пример #2
0
        public ulong PredictUser(SimpleTextMessage message)
        {
            PredictionEngine <SimpleTextMessage, SimpleMessagePrediction> predictionEngine =
                _context.Model.CreatePredictionEngine <SimpleTextMessage, SimpleMessagePrediction>(_trainedModel);
            SimpleMessagePrediction prediction = predictionEngine.Predict(message);

            return(prediction.Id);
        }
Пример #3
0
 public LocalSimpleTextMessage(SimpleTextMessage message)
 {
     Id        = message.Id;
     Sender    = message.Sender;
     TypeInfo  = message.TypeInfo;
     Timestamp = message.Timestamp;
     Recipient = message.Recipient;
     IsPrivate = message.IsPrivate;
     GroupName = message.GroupName;
     Text      = message.Text;
 }
Пример #4
0
        public async Task Predict([Remainder] String content)
        {
            SimpleTextMessage simpleMessage = new SimpleTextMessage
            {
                Content = content
            };
            var userId   = ClassificationService.PredictUser(simpleMessage);
            var username = Context.Guild.GetUser(userId).Username;
            var eb       = new BotEmbedBuilder();

            eb.WithDescription($"\"{content}\" - {username} (probably)");
            await ReplyAsync("", false, eb.Build());
        }
Пример #5
0
        /// <summary>
        /// Invoked when the send button is clicked.
        /// </summary>
        /// <param name="obj">The object</param>
        private async void SendClicked(object obj)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(this.NewMessage))
                {
                    int userid = Preferences.Get("UserID", 0);

                    JobMe.Models.Chat.ChatMessage msg = new JobMe.Models.Chat.ChatMessage()
                    {
                        Message    = this.NewMessage,
                        Time       = DateTime.Now,
                        ContactID  = ChatDetail.ContactID,
                        UserID     = ChatDetail.UserID,
                        IDPosition = ChatDetail.IDPosition,
                        IsReceived = false,
                    };

                    var message = new SimpleTextMessage(ProfileName)
                    {
                        Text      = this.NewMessage,
                        Recipient = ChatDetail.ContactID.ToString(),
                        Avatar    = userid.ToString(),
                        Color     = ChatDetail.IDPosition.ToString(),
                        //GroupName = ChatDetail.IDPosition.ToString(),
                    };

                    //Este mensaje es el que se agrega a la lista
                    ChatMessageInfo.Add(msg);

                    //borra el mensaje para que actualice el chat
                    this.NewMessage = null;

                    //Verifica que este conectado al hub
                    if (!App.ChatService1.IsConnected)
                    {
                        App.ChatService1 = new TheChat.Core.Services.ChatService();

                        if (Preferences.Get("UserID", 0) > 0)
                        {
                            await App.ChatService1.InitAsync(Preferences.Get("UserID", 0).ToString());
                        }
                    }

                    //Este es el mensaje que se envia al hub
                    await App.ChatService1.SendMessageAsync(message);

                    if (Preferences.Get("UserType", 0) == 1) //Employee
                    {
                        Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Name", string.Empty), msg.Message, "chat"));
                    }
                    else
                    {
                        Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Company", string.Empty), msg.Message, "chat"));
                    }

                    //Esto es para agregarlo a la base de datos
                    await Services.Chat.ChatService.AddMessageAsync(msg);
                }
            }
            catch (Exception ex)
            {
                // throw;
            }
        }
Пример #6
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("User Name:");
            userName = Console.ReadLine();

            service = new ChatService();
            service.OnReceivedMessage += Service_OnReceivedMessage;

            await service.InitAsync(userName);

            Console.WriteLine("You are now connected");

            await JoinRoom();

            var keepGoing = true;

            do
            {
                var text = Console.ReadLine();
                if (text == "exit")
                {
                    await service.DisconnectAsync();

                    keepGoing = false;
                }
                else if (text == "leave")
                {
                    var message = new UserConnectedMessage(userName, room);
                    await service.LeaveChannelAsync(message);
                    await JoinRoom();
                }
                else if (text == "private")
                {
                    Console.WriteLine("Enter UserName: "******"Enter private message: ");
                    text = Console.ReadLine();

                    var message = new SimpleTextMessage(userName)
                    {
                        Text      = text,
                        Recipient = user
                    };
                    await service.SendMessageAsync(message);
                }
                else if (text == "image")
                {
                    var imagePath   = @"D:\temp\Pictures\tests\emma.jpg";
                    var imageStream =
                        new FileStream(imagePath, FileMode.Open, FileAccess.Read);
                    var bytes       = ImageHelper.ReadFully(imageStream);
                    var base64Photo = Convert.ToBase64String(bytes);
                    var message     = new PhotoMessage(userName)
                    {
                        Base64Photo = base64Photo,
                        FileEnding  = imagePath.Split('.').Last(),
                        GroupName   = room
                    };
                    await service.SendMessageAsync(message);
                }
                else
                {
                    var message = new SimpleTextMessage(userName)
                    {
                        Text      = text,
                        GroupName = room
                    };

                    await service.SendMessageAsync(message);
                }
            } while (keepGoing);
        }