SmartIrc4Net を使用して C# で IRC ボットを作成しました。ボットの目的は、コマンドが認識されたときに情報を提供することだけです。
私の問題は、アプリケーションを閉じる原因となるコードで例外が発生する可能性がありますが、アプリケーションを実行し続け、「続行するには何かキーを押してください」というメッセージが表示されないことです。これは理想的には、例外をログに記録して続行する必要があります。
そもそも例外を管理できることはわかっていますが、コマンドごとにすべての入力を検証するには時間がかかります。または、私がカバーしていない他の例外があるかもしれません.
static void Main(string[] args)
{
IrcClient bot = new IrcClient();
// attach events
try
{
// connect to server, login etc
// 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
bot.Listen();
// disconnect when Listen() returns our IRC session is over
bot.Disconnect();
}
catch (ConnectionException e)
{
Console.WriteLine("Couldn't connect! Reason: " + e.Message);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(">> Error: " + e);
}
}