Last active
December 21, 2015 15:58
-
-
Save blizzarddreams/cf8c95f565ca6150c786 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package ircscalabot | |
| import java.io._ | |
| import java.net.Socket | |
| object Bot extends App { | |
| val scalabot = new Bot("scalaevalbot", "", "irc.freenode.net", 6667, List("#botwars"), '$') | |
| scalabot.connect() | |
| } | |
| class Bot(name: String, pass: String, server: String, port: Int, channels: List[String], symbol: Char) { | |
| val conn: Socket = new Socket("irc.freenode.net", 6667) | |
| val writer: BufferedWriter = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream())) | |
| val reader: BufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream())) | |
| val commands = Commands.commands | |
| def login(): Unit = { | |
| writer.write(s"USER $name 8 * :$name\r\n") | |
| writer.flush() | |
| writer.write(s"NICK $name\r\n") | |
| writer.flush() | |
| writer.write(s"PASS $pass\r\n") | |
| writer.flush() | |
| } | |
| def joinChannels(): Unit = { | |
| for (i <- channels) { | |
| writer.write(s"JOIN $i\r\n") | |
| writer.flush() | |
| } | |
| } | |
| def connect(): Unit = { | |
| login() | |
| joinChannels() | |
| while (true) { | |
| println(reader.readLine()) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment