我正在用 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));
}
}