Twitch.TV チャンネル用の IRC ボットを作成することにしました。PircBot API を使用します。
実行しようとすると、次のエラー メッセージが表示されます。
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.jibble.pircbot.PircBot.connect(PircBot.java:140)
at NewbieBot.main(NewbieBot.java:19)
私がこれまでに持っているコードは次のとおりです。
import org.jibble.PircBot.*;
import java.io.IOException;
public class NewbieBot extends PircBot {
public NewbieBot() {
this.setName("newbiebot");
}
public void main(String[] args) {
NewbieBot bot = new NewbieBot();
bot.setVerbose(true);
bot.setAutoNickChange(true);
try {
System.out.println("Attempting to join server");
// bot.connect("newbiedoodle.jtvirc.com", 6667, "newbieschannel");
bot.connect("irc.esper.net", 6697, "newbiebot");
} catch (NickAlreadyInUseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IrcException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
if (bot.isConnected()) {
System.out.println("Connected!");
}
else {
System.out.println("Failed to connect.");
return;
}
}
}
public void onMessage(String channel, String sender, String login, String hostname, String message) {
if (message.equalsIgnoreCase("test!") {
sendMessage(channel, "Testing!");
}
if (message.equalsIgnoreCase(">cmds")) {
sendMessage(channel, " ------ Commands ------ ");
sendMessage(channel, ">cmds: Show the bot commands");
sendMessage(channel, ">rules: Show the stream rules");
sendMessage(channel, ">mods: Show list of online mods");
sendMessage(channel, ">info: Show channel info");
}
}
誰かが何が間違っているかを理解できる場合は、私に知らせてください。
注: これを自宅でテストし、ファイアウォールを完全に無効にしましたが、それでも接続できませんでした。