yesturday i’ll try the code at the bottom of this post… it lost at the same time like the other bot…
i dont know what it is but i think it’s a problem on my site… more on twitch site but dont know…
package testing;
import java.io.*;
import java.net.*;
public class irc
{
public String server = "";
public String nick = "";
public String login = "";
public String channel = "";
public String pass = "";
private BufferedWriter writer = null;
private BufferedReader reader = null;
private String line = null;
public void sendRawLine(String line) {
try {
writer.write(line);
writer.flush();
} catch (IOException e) {}
}
public void useDefault() {
server = "irc.freenode.net";
nick = "simple_bot";
login = "simple_bot";
channel = "#irchacks";
}
public boolean login() throws Exception {
// Connect directly to the IRC server.
System.out.println("try to login");
@SuppressWarnings("resource")
Socket socket = new Socket(server, 6667);
writer = new BufferedWriter( new OutputStreamWriter(socket.getOutputStream()) );
reader = new BufferedReader( new InputStreamReader(socket.getInputStream()) );
// Log on to the server.
if (!pass.isEmpty()) {
System.out.println("using pass: "+pass);
sendRawLine("PASS " + pass + "\r\n");
}
if (!nick.isEmpty()) {
System.out.println("using nick: "+nick);
sendRawLine("NICK " + nick + "\r\n");
}
if (!login.isEmpty()) {
System.out.println("using login: "+login);
sendRawLine("USER " + login + " 8 * : Java IRC Hacks Bot\r\n");
}
// Read lines from the server until it tells us we have connected.
line = null;
while ((line = reader.readLine( )) != null) {
System.out.println("loop " + line);
if (line.indexOf("004") >= 0) {
// We are now logged in.
System.out.println("Login success.");
break;
} else if (line.indexOf("433") >= 0) {
System.out.println("Nickname is already in use.");
return false;
}
}
return true;
}
public void join() throws Exception {
// Join the channel.
if (!channel.isEmpty()) {
sendRawLine("JOIN " + channel + "\r\n");
sendRawLine("CAP REQ :twitch.tv/membership\r\n");
sendRawLine("CAP REQ :twitch.tv/tags\r\n");
sendRawLine("CAP REQ :twitch.tv/commands\r\n");
}
}
public void start() throws Exception {
// Keep reading lines from the server.
while ((line = reader.readLine( )) != null) {
if (line.trim().toUpperCase().startsWith("PING ")) {
// We must respond to PINGs to avoid being disconnected.
sendRawLine("PONG " + line.substring(5) + "\r\n");
} else {
// Print the raw line received by the bot.
System.out.println(line);
}
}
}
public void send(String message) throws Exception {
System.out.println(message.isEmpty());
if (!message.isEmpty()) {
System.out.println( "Message: > PRIVMSG " + channel + " :" + message + "\r\n");
sendRawLine("PRIVMSG " + channel + " :" + message + "\r\n");
}
}
public void leave() throws Exception {
sendRawLine("PART " + channel + "\r\n");
}
}