所以我决定尝试编写一个 twitch IRC 机器人,只是为了体验。到目前为止,我已经学到了很多东西,但现在我遇到了障碍,似乎无法让机器人连接起来。
我有一个 IRC 客户端,可以很好地连接到 twitch irc,尽管我无法 ping irc.twitch.tv 我的机器人使用 PircBotX 框架作为它的基础,到目前为止它应该做的只是连接到服务器,但它没有吨。我在 Eclipse 中设置了所有内容,一切看起来都很好,但机器人从未真正连接过。它尝试并尝试,但似乎从未通过。
我不确定为什么它不起作用。我还端口转发了端口,以防万一它需要在路由器上但没有运气。当我在 Eclipse 中运行机器人时,它开始尝试连接然后停止运行。
我一直在从 pircbotx 的文档中拼凑出一些东西,这个机器人的代码:https ://github.com/MattsMc/MankiniBot和我发现的这个 youtube 系列:https ://www.youtube.com/watch?v=a1WDUKI5-PI . 你能提供的任何帮助都会很棒。谢谢。
PS:我更改了 OAUTH 代码,因此无需担心 :)
基本上这是我的代码:
package firedingo.project.bot;
import com.google.common.collect.*;
import com.google.guava.*;
import org.pircbotx.Configuration;
import org.pircbotx.PircBotX;
public class TheDingoPack {
private int count;
//starting config again in case config derp is issue, will need clean up HERE
Configuration<PircBotX> Config = new Configuration.Builder<PircBotX>()
.setServerPassword(firedingo.project.bot.reference.Reference.OAUTH)
.setName(firedingo.project.bot.reference.Reference.NICK)
.setLogin(firedingo.project.bot.reference.Reference.NICK)
.setAutoNickChange(true)
.setServerHostname(firedingo.project.bot.reference.Reference.HOST)
.setServerPort(firedingo.project.bot.reference.Reference.PORT)
.addAutoJoinChannel(firedingo.project.bot.reference.Reference.BOTCHAN)
.buildConfiguration();
//Constructor to actually create the bot
public TheDingoPack() {
PircBotX TheDingoPack = new PircBotX(Config);
try {
TheDingoPack.startBot();
System.out.println("Attempting To Connect");
}
catch(Exception e) {
System.out.println("Connection Failed - Error Thrown");
}
}
//realized constructor needed a call so added it here. Nearly derped :P
public static void main(String[] args) {
new TheDingoPack();
}
}
package firedingo.project.bot.reference;
public class Reference {
//Connection Details As Constants For Easy Customizability
public static final String NICK = "thedingopack";
public static final String HOST = "irc.twitch.tv";
public static final String OAUTH = "6lw8eg2zw81pmpj09kbr9pa62d006f";
public static final int PORT = 6667;
//these two channels can be changed as necessary, extras can also be added.
public static final String BOTCHAN = "#thedingopack";
public static final String MODCHAN = "#firedingo99365";
}