2013-07-12 23 views
0

好吧,我正在製作一個Skype工具箱程序,可以做很多事情,但我在Aui遇到了問題。c#Skype應用程序發送文本到觸發器上的當前聊天

程序的這一部分是爲了查看與某人聊天時發送的命令並打印文本。例如,如果你在與某人聊天時說「胖」,它會寫「喲胖男孩」。

我發現這個代碼在線:

using System; 
using System.Windows.Forms; 
using SKYPE4COMLib; // Our COM library 

namespace SkypeBing 
{ 
    public partial class Form1 : Form 
    { 
     private Skype skype; 
     private const string trigger = "!"; // Say !help 
     private const string nick = "Skype Admin"; 

     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      skype = new Skype(); 
      // Use skype protocol version 7 
      skype.Attach(7, false); 
      // Listen 
      skype.MessageStatus += 
       new _ISkypeEvents_MessageStatusEventHandler(skype_MessageStatus); 
     } 
     private void skype_MessageStatus(ChatMessage msg, 
        TChatMessageStatus status) 
     { 
      // Proceed only if the incoming message is a trigger 
      if (msg.Body.IndexOf(trigger) == 0) 
      { 
       // Remove trigger string and make lower case 
       string command = msg.Body.Remove(0, trigger.Length).ToLower(); 

       // Send processed message back to skype chat window 
       skype.SendMessage(msg.Sender.Handle, nick + 
         " Says: " + ProcessCommand(command)); 
      } 
     } 

     private string ProcessCommand(string str) 
     { 
      string result; 
      switch (str) 
      { 
       case "hello": 
        result = "Hello!"; 
        break; 
       case "help": 
        result = "Sorry no help available"; 
        break; 
       case "date": 
        result = "Current Date is: " + 
          DateTime.Now.ToLongDateString(); 
        break; 
       case "time": 
        result = "Current Time is: " + 
          DateTime.Now.ToLongTimeString(); 
        break; 
       case "who": 
        result = "It is Praveen, aka NinethSense " + 
          "who wrote this tutorial"; 
        break; 
       default: 
        result = "Sorry, I do not recognize your command"; 
        break; 
      } 

      return result; 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 

     } 
    } 
} 

但是,這並不工作,因爲它需要發送給用戶。我對這個Aui相當陌生。如果有人對我可以用來正確調用此事件的方法有任何想法,因爲網上沒有太多支持,所以我想我會問你超級人。 :D如果您需要更多信息或希望成爲其發展的一部分,請提問。

回答

1
private void skype_MessageStatus(ChatMessage msg, TChatMessageStatus status) 
{ 
     if (msg.Body.Contains("faty")) 
     { 
      skype.SendMessage(msg.Sender.Handle,"Go away fatty!"); 
     } 
    } 

skype.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(skype_MessageStatus); 

這是你可以做的基本輪廓,它很容易從那裏擴展。希望這可以解決問題。

相關問題