-7

我正在用 C# 制作一个 Skype 机器人,但我遇到了问题。它不是读取我自己的命令,而是读取其他人收到的命令。

当我添加诸如“!解决(用户名)”之类的内容时,它会使代码全部被窃听,我的意思是当我启动它时它只会使工具崩溃。

有人可以看看,看看是否有任何重大问题。

private Skype skype;
    private const string trigger = "!";
    private const string nick = "The OG Bot";

和这个

private string ProcessCommand(string str)
    {
        string result;
        switch (str)
        {
            case "resolve":
                result = "Currently Not Working Will Fix Soon.";
                break;
            case "help":
                result = "Here are some commands you can run. \n !resolve \n !date \n !time \n !who \n !swag \n !ip";
                break;
            case "date":
                result = "Current Date is: " + DateTime.Now.ToLongDateString();
                break;
            case "time":
                result = "Current Time is: " + DateTime.Now.ToLongTimeString();
                break;
            case "who":
                result = "This API was created by TehMerkMods";
                break;
            case "ip":
                result = new WebClient().DownloadString("http://icanhazip.com");
                break;
            case "swag":
                result = "(mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) (mm) ";
                break;
            default:
                result = "Sorry, I do not recognize your command";
                break;
        }

        return result;
    }

最后一点

private void skype_MessageStatus(ChatMessage msg, TChatMessageStatus status)
    {
        if (TChatMessageStatus.cmsRead == status)
        {
            return;
        }

        if (msg.Body.IndexOf(trigger) == 0 && TChatMessageStatus.cmsReceived == status)
        {
            string command = msg.Body.Remove(0, trigger.Length).ToLower();
            skype.SendMessage(msg.Sender.Handle, nick + " : " + ProcessCommand(command));
        }
    }
4

2 回答 2

1

你只是得到'接收',你还需要得到'发送'

例子:

if (TChatMessageStatus.cmsReceived Or Status = TChatMessageStatus.cmsSent)
于 2015-04-26T15:20:28.653 回答
0

您在最后一段代码中有一个 if 语句,它只查找 TChatMessageStatus.cmsReceived。当您发送消息时,此声明永远不会正确,因为您没有收到自己的消息。

至于程序崩溃……您需要提供更多信息。

于 2015-04-09T06:13:29.737 回答