Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
FILE HOSTS PREMIUM ACCOUNT
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
Java IRC Bot
<pre class='prettyprint' language='java'>package ircbot; /** * JavaBot (version 1.2) * * MIT License, dydx (Josh Sandlin) <dydx@thenullbyte.org> * */ import java.io.*; import java.net.*; import java.util.regex.*; import java.util.Date; public class Main { public static void main( String[] args ) throws IOException { //connection variables String server = "irc.snappeh.com"; String nick = "JavaBot"; String login = "JavaBot"; String channel = "#bots"; int port = 6667; //for security String owner = "dydx"; try { //our socket we're connected with Socket irc = new Socket( server, port ); //out output stream BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( irc.getOutputStream() ) ); //our input stream BufferedReader br = new BufferedReader( new InputStreamReader( irc.getInputStream() ) ); //authenticate with the server bw.write( "NICK " + nick + "\n" ); bw.write( "USER " + login + " thenullbyte.org JB: Java Bot\n" ); bw.flush(); //join a channel bw.write( "JOIN " + channel + "\n" ); bw.write( "PRIVMSG " + channel + " :Whats up everybody?\n" ); bw.flush(); System.out.println( "Successfully connected to IRC" ); String currLine = null; while( ( currLine = br.readLine() ) != null ) { //checks for PING, if one is found; return a PONG Pattern pingRegex = Pattern.compile( "^PING", Pattern.CASE_INSENSITIVE ); Matcher ping = pingRegex.matcher( currLine ); if( ping.find() ) { bw.write( "PONG " + channel + "\n" ); bw.flush(); } //check for ownership Pattern checkOwner = Pattern.compile( "^:"+owner, Pattern.CASE_INSENSITIVE ); Matcher ownership = checkOwner.matcher( currLine ); //!exit - quit current irc room Pattern exitRegex = Pattern.compile( "!exit", Pattern.CASE_INSENSITIVE ); Matcher exit = exitRegex.matcher( currLine ); if( exit.find() && ownership.find() ) { bw.write( "PRIVMSG " + channel + " :Bye Bye\n" ); bw.write( "PART " + channel + "\n" ); bw.flush(); irc.close(); } //!time - return current time Pattern timeRegex = Pattern.compile( "!time", Pattern.CASE_INSENSITIVE ); Matcher time = timeRegex.matcher( currLine ); if( time.find() && ownership.find() ) { Date d = new Date(); bw.write( "PRIVMSG " + channel + " :" + d +"\n" ); bw.flush(); } //!sayhi - shows a little message saying hello Pattern helloRegex = Pattern.compile( "!sayhi", Pattern.CASE_INSENSITIVE ); Matcher hello = helloRegex.matcher( currLine ); if( hello.find() && ownership.find() ) { bw.write( "PRIVMSG " + channel + " :Hello, I'm a JavaBot. I was coded by dydx in Java!\n"); bw.flush(); } //!join <room> - changes to a new room and sets the variables accordingly Pattern joinRegex = Pattern.compile( "!join", Pattern.CASE_INSENSITIVE ); Matcher join = joinRegex.matcher( currLine ); if( join.find() && ownership.find() ) { String[] token = currLine.split( " " ); bw.write( "PRIVMSG " + channel + " :Im going over to " + token[4] + "\n" ); bw.write( "PART " + channel + "\n" ); channel = token[4]; bw.write( "JOIN " + channel + "\n" ); bw.flush(); } } } catch ( UnknownHostException e ) { System.err.println( "No such host" ); } catch ( IOException e ) { System.err.println( "There was an error connecting to the host" ); } } }</pre> <a href="http://www.refactormycode.com/codes/490-java-irc-bot" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>