Created
January 16, 2011 17:14
-
-
Save lopex/781955 to your computer and use it in GitHub Desktop.
This file contains 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
import org.jibble.pircbot.PircBot | |
object Scalabot extends PircBot { | |
def main(args: Array[String]) { | |
setName("scalabotpl") | |
setVerbose(true) | |
setEncoding("UTF-8") | |
connect("irc.freenode.net") | |
// identify("******") | |
joinChannel("#scala.pl") | |
} | |
override def onMessage(channel: String, sender: String, login: String, hostname: String, message: String) { | |
import java.io._ | |
import java.net._ | |
if (message.startsWith(getName() + ": ")) { | |
val url = new | |
URL("http://www.simplyscala.com/interp?bot=irc&code=" + URLEncoder.encode("{" + message.substring((getName + ": ").length), "UTF-8") + "}") | |
val reader = new BufferedReader(new InputStreamReader(url.openConnection.getInputStream, "UTF-8")) | |
try { | |
// reader.readLine | |
var line = reader.readLine | |
if (line == "warning: there were deprecation warnings; re-run with -deprecation for details") line = reader.readLine | |
println(line.replaceAll("^res0: ", "")) | |
sendMessage(channel, line.replaceAll("^res0: ", "")) | |
} | |
finally { | |
reader.close | |
} | |
} | |
if (message.contains("#") && !getUsers(channel).exists(_.getNick== "scala-tracbot")) { | |
val url = "http://lampsvn.epfl.ch/trac/scala/ticket/" + | |
message.replaceAll("^[^#]*#", "").replaceAll("([^0-9].*)?", "") | |
println(url) | |
if (!url.endsWith("/")) sendMessage(channel, "Perhaps you meant " + url) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment