Example #1
0
        // GET: api/Chat/5
        public OutputChat Get(int id)
        {
            using (ChatContextDataContext db = new ChatContextDataContext())
            {
                var tkn = Token.GetToken(Request);
                //string nama = tkn.Name;
                int userid = tkn.IdUser;
                //int userid = 1;
                OutputChat     output = new OutputChat();
                List <Message> pesan  = new List <Message>();
                pesan = (from a in db.TblUser
                         join b in db.Conversation on a.Id equals b.From_Id
                         join c in db.ConversationReply on b.Con_Id equals c.Con_Id
                         join d in db.TblUser on c.From_Id equals d.Id
                         where b.Con_Id == id
                         select new Message
                {
                    Name = d.Name,
                    Text = c.Reply,
                    Date = c.Timestamp,
                    Avatar = d.Photo,
                    Type = "received",
                    To_Id = c.To_Id,
                    From_Id = c.From_Id
                }).ToList();
                string username = (from a in db.TblUser
                                   where a.Id == userid select a.Name).FirstOrDefault();
                List <Message> DataPesan = new List <Message>();
                var            dd        = (from a in pesan select a).ToList();
                foreach (var dt in dd)
                {
                    if (dt.From_Id == userid)
                    {
                        dt.Type    = "sent";
                        dt.From_Id = dt.To_Id;
                    }
                }
                output.Messages = dd;

                output.DateTime = pesan.FirstOrDefault().Date;
                output.Avatar   = pesan.FirstOrDefault().Avatar;
                output.To_Id    = pesan.FirstOrDefault().To_Id;
                int    toid   = output.To_Id;
                string userto = (from a in db.TblUser
                                 where a.Id == toid
                                 select a.Name).FirstOrDefault();
                output.userid    = userid;
                output.Con_Id    = id;
                output.NameLogin = username;
                output.From_Id   = dd.FirstOrDefault().From_Id;
                string to = (from a in db.TblUser
                             where a.Id == pesan.FirstOrDefault().From_Id
                             select a.Name).FirstOrDefault();
                output.Name = to;
                return(output);
            }
        }
Example #2
0
        /// <summary>
        /// When Enter is clicked, many operations happen.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Enter_Click(object sender, EventArgs e)
        {
            // Output user message
            OutputChat.AppendText("User: "******"\r\n" +
                                  "--------------------------------------------------------------------------------------------------------\r\n");

            // Add convo to history
            tempText.Add(InputChat.Text);
            historyIndex++;

            // Refresh Chatbox
            InputChat.Text = "";
            prevIndex      = historyIndex;
            OutputChat.Refresh();
            InputChat.Refresh();

            // Call Chakbot to respond
            ChakBot_Convo();
        }
Example #3
0
        // ============================ END UI Features ================================


        // ============================ Chakbot Settings ================================
        /// <summary>
        /// Robot Response
        /// </summary>
        private async void ChakBot_Convo()
        {
            // Delay for aesthetics
            for (int i = 0; i < rnd.Next(1, 2); i++)
            {
                TypingDisplay.Text = "ChakBot is typing.";
                await Task.Delay(400);

                TypingDisplay.Text = "ChakBot is typing..";
                await Task.Delay(400);

                TypingDisplay.Text = "ChakBot is typing...";
                await Task.Delay(400);
            }

            if (tempText[historyIndex - 1] == "//help")
            {
                OutputChat.AppendText("ChakBot: " +
                                      "List of functions\r\n" +
                                      "====================================================\r\n" +
                                      "//clear\t| Clear the messages on screen\r\n" +
                                      "//time\t| Display the current time\r\n" +
                                      "teach=\t| Teach chakbot (root>message>corres>message)\r\n" +
                                      "e;n=\t| Encrypt by shifting n times\r\n" +
                                      "d;n=\t| Decrypt by shifting n times\r\n" +
                                      "morse=\t| Encrypr/decrypt message into morse code\r\n" +
                                      "cal=\t| Calculate\r\n" +
                                      "convert=\t| Convert units (#unit>unit)\r\n" +
                                      "====================================================\r\n");
                TypingDisplay.Text = "";
            }
            else if (tempText[historyIndex - 1] == "//clear")
            {
                OutputChat.Clear();
                TypingDisplay.Text = "";
            }
            else if (tempText[historyIndex - 1] == "//time")
            {
                OutputChat.AppendText("ChakBot:\r\n >>> " +
                                      DateTime.Now.ToString() + " EST\r\n");
                TypingDisplay.Text = "";
            }
            else if (tempText[historyIndex - 1] == "//brain")
            {
                System.IO.StreamReader read = new System.IO.StreamReader(PATH);

                // Read line and put into list
                string line;
                string message = "";

                while ((line = read.ReadLine()) != null)
                {
                    message += line + "\r\n";
                    message += "---\r\n";
                }

                read.Close();
                OutputChat.AppendText(message + "\r\n");
                TypingDisplay.Text = "";
            }
            else if (tempText[historyIndex - 1].Contains("="))
            {
                if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf('=') + 1).ToLower() == "teach=")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          teach_chakbot(tempText[historyIndex - 1].Substring(6,
                                                                                             tempText[historyIndex - 1].Length - 6), PATH + "/brain.txt") + SEP);
                    TypingDisplay.Text = "";
                }
                else if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf(';') + 1).ToLower() == "e;" ||
                         tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf(';') + 1).ToLower() == "d;")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          chakbot_en_de(tempText[historyIndex - 1]) + SEP);
                    TypingDisplay.Text = "";
                }
                else if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf('=') + 1).ToLower() == "mc=")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          MorseCode(tempText[historyIndex - 1].Substring(3, tempText[historyIndex - 1].Length - 3)) + SEP);
                    TypingDisplay.Text = "";
                }
                else if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf('=') + 1).ToLower() == "cal=")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          Calculate(tempText[historyIndex - 1].Substring(4, tempText[historyIndex - 1].Length - 4)) + SEP);
                    TypingDisplay.Text = "";
                }
                else if (tempText[historyIndex - 1].Substring(0, tempText[historyIndex - 1].IndexOf('=') + 1).ToLower() == "convert=")
                {
                    OutputChat.AppendText("ChakBot: " +
                                          Convert(tempText[historyIndex - 1].Substring(8, tempText[historyIndex - 1].Length - 8)) + SEP);
                    TypingDisplay.Text = "";
                }
                else
                {
                    OutputChat.AppendText("ChakBot: " +
                                          "Please check your syntax." + SEP);
                    TypingDisplay.Text = "";
                }
            }
            else
            {
                OutputChat.AppendText("ChakBot: " +
                                      getMessage(tempText[historyIndex - 1]) + SEP);
                TypingDisplay.Text = "";
            }
        }
Example #4
0
 private void OutputChat_TextChanged(object sender, EventArgs e)
 {
     OutputChat.SelectionStart = OutputChat.Text.Length;
     OutputChat.ScrollToCaret();
 }