【问题标题】:c# Skype application send text to current chat on triggerc# Skype 应用程序在触发时向当前聊天发送文本
【发布时间】:2023-03-29 10:01:02
【问题描述】:

好的,所以我正在制作一个可以做很多事情的 Skype 工具箱程序,但是我在使用 Aui 时遇到了问题。

程序的这一部分旨在查看在与人聊天时发送的命令并打印文本。例如,如果你在与某人聊天时说 !fatty,它会写成“yo fat boy”。

我在网上发现了这段代码:

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 如果您需要更多信息或想参与其开发,请询问。

【问题讨论】:

    标签: c# winforms skype visual-c#-express-2010 skype4com


    【解决方案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);
    

    这是您可以做什么的基本大纲,从那里很容易扩展。希望这可以解决问题。

    【讨论】:

      猜你喜欢
      • 2011-08-22
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      • 2018-11-02
      • 2013-06-15
      • 2014-08-27
      • 1970-01-01
      • 2012-10-26
      相关资源
      最近更新 更多