Ejemplo n.º 1
0
        /// <summary>
        /// Handler for "analyse" message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AnalyseHandler(object sender, ChatActionEventArgs e)
        {
            Client.Self.Chat("Voy a analizar tu frase. Conectando...", 0, ChatType.Whisper);

            WebClient webClient = new WebClient();
            webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_OpenNLPDownloadStringCompleted);
            webClient.DownloadStringAsync(new Uri("http://localhost:8080/OpenSimNLP/OpenNLP?phrase=" + Uri.EscapeUriString(e.Message.Replace("Analiza ", ""))));
        }
Ejemplo n.º 2
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;

            Client.Self.Chat("Hola por " + knownUsers[e.FromName] + "ª vez, " + e.FromName + "!", 0, ChatType.Whisper);
        }
Ejemplo n.º 3
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 ", ""))));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handler for "translate" message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TranslateHandler(object sender, ChatActionEventArgs e)
        {
            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(e.Message.Replace("Traduce ", ""))
                + "&from=en"
                + "&to=es"));
        }
Ejemplo n.º 5
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.StartsWith(action))
             {
                 ChatActionEventArgs args = new ChatActionEventArgs();
                 args.Message = e.Message.Replace(action + " ", "");
                 args.FromName = e.FromName;
                 Handlers[action].Invoke(this, args);
             }
         }
     }
 }