C# SmartIRC4Net赢得了';t连接/显示无活动

C# SmartIRC4Net赢得了';t连接/显示无活动,c#,irc,bots,C#,Irc,Bots,我正在用c#制作一个机器人,使用SmartIRC4Net库(http://www.meebey.net/projects/smartirc4net/). 如果您不熟悉该库,请随时告诉我其他选择 我使用它是因为它是我能找到的最受支持的库。我阅读了“测试”示例bot,并试图通过删除查询和响应输入将其剥离到基本内容 我将其编程为尝试连接到他们的网络频道,因为缺少更好的测试频道,但它似乎无法连接。调试bot时,我的客户端上没有显示任何内容(我现在在他们的频道上)。控制台也不显示任何IRC错误消息或异常,

我正在用c#制作一个机器人,使用SmartIRC4Net库(http://www.meebey.net/projects/smartirc4net/). 如果您不熟悉该库,请随时告诉我其他选择

我使用它是因为它是我能找到的最受支持的库。我阅读了“测试”示例bot,并试图通过删除查询和响应输入将其剥离到基本内容

我将其编程为尝试连接到他们的网络频道,因为缺少更好的测试频道,但它似乎无法连接。调试bot时,我的客户端上没有显示任何内容(我现在在他们的频道上)。控制台也不显示任何IRC错误消息或异常,只显示我在末尾的暂停。 代码:

[更新:按照@Russ C的建议添加了irc_OnConnected事件。事件被触发,并且“已连接”被记录在控制台上。但是,频道上没有任何事情发生。我将添加sendmessage行,看看会发生什么。]


[Update2:添加了SendMessage和OnRawMessage事件。频道上没有显示输出,OnRawMessage事件下的文本没有写入控制台。(我对OnMessage使用了正确的事件吗?“OnMessage”事件不存在,测试机器人说OnMessage将“获取所有IRC消息”。)

Ok;与所有基于事件的逻辑(此处读取异步逻辑)一样,您需要订阅一个事件,以便库在有事情要做时通知您。 因为您的测试代码没有订阅/附加SmartIRC库中的任何事件,所以该库只是静止不动,什么也不做

您正在使用irc.OnError行执行部分操作,但还需要添加以下方法:

irc.OnQueryMessage += new IrcEventHandler(OnQueryMessage);
irc.OnRawMessage += new IrcEventHandler(OnRawMessage);
然后是两种方法:

// this method we will use to analyse queries (also known as private messages)
public static void OnQueryMessage(object sender, IrcEventArgs e)
{
    switch (e.Data.MessageArray[0]) {
        case "hello":
           // this is where you decipher private messages posted to the bot.
           // if someone does "/privmsg HGPBot hello" this will reply "Hello!"
           irc.SendMessage(SendType.Message, "HGPBot, "Hello!");
           break;
        default:
           break;
    }
}

// this method will get all IRC messages
public static void OnRawMessage(object sender, IrcEventArgs e)
{
    System.Console.WriteLine("Received: "+e.Data.RawMessage);
}
如果你在这个System.Console行上设置了一个断点,那么你应该开始看到来自bot的东西。 如果这似乎不起作用,您可以尝试在IRC服务器上创建自己的频道

另外,别忘了:如果您确信您的机器人正在使用的用户名是唯一的并且正在工作(即您可以通过mirc或其他方式登录),只要在程序连接后尝试向您的机器人发送/privmsg命令,用户就可以连接到IRC,而无需进入通道

编辑:还有,我刚刚注意到你的程序没有循环。 您需要添加irc.Listen();在暂停声明之前。这将使irc bot进入侦听模式,并且是一个阻塞循环,因此在这一点上退出程序的唯一方法是结束任务,但至少它会显示它正在工作

编辑2:使机器人侦听:

// here we tell the IRC API to go into a receive mode, all events
// will be triggered by _this_ thread (main thread in this case)
// Listen() blocks by default, you can also use ListenOnce() if you
// need that does one IRC operation and then returns, so you need then 
// an own loop 
irc.Listen();
//pause
Console.WriteLine("Press any key to continue");
Console.ReadKey(true);

它不是有一个你要连接的onConnected/onMessage-received事件吗?我确信它有一个onConnected事件,我会添加它,看看会发生什么,但是你说的“你要连接的”是什么意思,onMessage-received事件会做什么?我下车后会写一个答案,给我几分钟。这里,我更新了。我将尝试添加sendmessage行。顺便说一句,谢谢你的帮助。很可能是因为你错过了irc;catch语句关闭后的命令。
// here we tell the IRC API to go into a receive mode, all events
// will be triggered by _this_ thread (main thread in this case)
// Listen() blocks by default, you can also use ListenOnce() if you
// need that does one IRC operation and then returns, so you need then 
// an own loop 
irc.Listen();
//pause
Console.WriteLine("Press any key to continue");
Console.ReadKey(true);