Exemple #1
0
        /// <summary>
        /// Handler for "analyse" message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AnalyseHandler(object sender, ChatActionEventArgs e)
        {
            string phrase = e.Message.Replace("Analiza ", "").Replace("?", " ?").Replace(".", " .");

            if (alreadyAnalyzedPhrases.Contains(phrase.GetHashCode()))
            {
                Client.Self.Chat("¡Esa frase ya la analicé antes! Dime una frase nueva :)", 0, ChatType.Whisper);
            }else{
                Client.Self.Chat("Voy a analizar tu frase. Conectando...", 0, ChatType.Whisper);

                string language = "English";

                if (phrase.Contains(" es ") || phrase.Contains("Ese "))
                    language = "Spanish";

                WebClient webClient = new WebClient();
                webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_OpenNLPDownloadStringCompleted);
                webClient.DownloadStringAsync(new Uri("http://localhost:8080/OpenSimNLP/OpenNLP?phrase=" + Uri.EscapeUriString(phrase) + "&language=" + language));

                alreadyAnalyzedPhrases.Add(phrase.GetHashCode());
            }
        }
Exemple #2
0
 /// <summary>
 /// Handles a chat message received from the server
 /// </summary>
 /// <param name="sender">Client that received the chat</param>
 /// <param name="e">Parameters of the chat message</param>
 private void Self_ChatFromSimulator(object sender, ChatEventArgs e)
 {
     if (e.SourceType == ChatSourceType.Agent && e.Type == ChatType.Normal && e.SourceID != Client.Self.AgentID)
     {
         //Iterate through each action and call its handler in case the received message tries to invoke that action
         //The Message that is sent with the event is the original message without the verb
         foreach (string action in Handlers.Keys)
         {
             if (e.Message.ToLower().StartsWith(action))
             {
                 ChatActionEventArgs args = new ChatActionEventArgs();
                 args.Message = e.Message.Replace(action + " ", "");
                 args.FromName = e.FromName;
                 Handlers[action].Invoke(this, args);
             }
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Handler for greeting message.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GreetingHandler(object sender, ChatActionEventArgs e)
        {
            if (knownUsers.ContainsKey(e.FromName))
                knownUsers[e.FromName]++;
            else
                knownUsers[e.FromName] = 1;

            if(knownUsers[e.FromName] == 1)
                Client.Self.Chat("Hola " + e.FromName + "! Encantado de conocerte :)", 0, ChatType.Whisper);
            else
                Client.Self.Chat("Hola de nuevo, " + e.FromName + "!", 0, ChatType.Whisper);
        }
Exemple #4
0
        /// <summary>
        /// Handler for "translate" message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TranslateHandler(object sender, ChatActionEventArgs e)
        {
            string phrase = e.Message.Replace("Traduce ", "");

            if (alreadyTranslatedPhrases.Contains(phrase.GetHashCode()))
            {
                Client.Self.Chat("¡Esa frase ya la traduje antes! Dime una frase nueva :)", 0, ChatType.Whisper);
            }
            else
            {
                Client.Self.Chat("Voy a traducir tu frase. Conectando...", 0, ChatType.Whisper);

                WebClient webClient = new WebClient();
                webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_TranslationDownloadStringCompleted);
                webClient.DownloadStringAsync(new Uri("http://api.microsofttranslator.com/V2/Http.svc/Translate?"
                    + "appId=5F1D586DEE19CCA530C52B5BA70F57800BAAC2F9"
                    + "&text=" + Uri.EscapeUriString(phrase)
                    + "&from=en"
                    + "&to=es"));

                alreadyTranslatedPhrases.Add(phrase.GetHashCode());
            }
        }
Exemple #5
0
 /// <summary>
 /// Handler for "tell me" message
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void TellMeHandler(object sender, ChatActionEventArgs e)
 {
     Client.Self.Chat("Ahí iría un edificio del Camino de Santiago.", 0, ChatType.Whisper);
 }
Exemple #6
0
        /// <summary>
        /// Handler for "reverse sentence" message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReverseHandler(object sender, ChatActionEventArgs e)
        {
            Client.Self.Chat("Voy a dar la vuelta a tu frase con una aplicación web. Conectando...", 0, ChatType.Whisper);

            WebClient webClient = new WebClient();
            webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_ReverseDownloadStringCompleted);
            webClient.DownloadStringAsync(new Uri("http://www.ieru.org/projects/mmol/reverse.php?phrase=" + Uri.EscapeUriString(e.Message.Replace("Invierte ", ""))));
        }