ã©ããã¦ã IRC ãããã JavaScript ã§ä½ãããã¦
Rhino ãåå¼·ãããï¼ï¼ï¼
ã§
ã§ãããã¼ï¼¼ï¼ï¼¾oï¼¾ï¼ï¼
ãã¦ã³ãã¼ã (CodeRepos ã ã)
http://svn.coderepos.org/share/lang/java/jsbot/org/coderepos/botchang/Botchang.java
使ãæ¹
- ã¾ããããã js.jar (Rhino) ãæ¾ã£ã¦ãã -> http://www.mozilla-japan.org/rhino/download.html
- 次㫠pircbot.jar (PircBot) ãæ¾ã£ã¦ãã -> PircBot - Java IRC Bot Framework (Java IRC API for Bots)
- 次㫠これ ã org/coderepos/botchang/ ã£ã¦ãã£ã¬ã¯ããªã«å ¥ã㦠javac ã§ã³ã³ãã¤ã«ããï¼
- ã§ã以ä¸ã¿ãã㪠JS ã®ãã¡ã¤ã«ãä½ã
defineClass('org.coderepos.botchang.Botchang'); // ããã¯ãã¼ã ã¨ã¨ã³ã³ã¼ãã®åå var botchang = new Botchang('botchang', 'utf-8'); // verbose (ãããã°ç¨ botchang.verbose = true; // æ¥ç¶ botchang.connect('irc.freenode.net'); // ãã£ã³ãã«ã« join ãã botchang.joinChannel('#1981'); // ã¡ãã»ã¼ã¸ãã³ãã© botchang.onMessage = function(channel, sender, login, hostname, message) { if (message.match(/^botchang/)) { botchang.sendMessage(channel, 'My name is botchang'); } else if (message.match(/^change nick:(.*)$/)) { botchang.nick = RegExp.$1; // dynamic change nick } }; // ãã¨ãã°ã Notice ããã³ããªã³ã°ãããã£ãã以ä¸ã®ããã«é¢æ°è¿½å botchang.onNotice = function(channel, sender, login, hostname, notice) { //... };
ã§ãæå¾ã« org.mozilla.javascript.tools.shell.Main ã java ã³ãã³ãã§å®è¡ãã¦ãã® JS ã渡ãã¦ããã ãï¼ï¼ï¼*1
java -cp ".:js.jar:pircbot.jar" org.mozilla.javascript.tools.shell.Main sample.js
ã¡ãªã¿ã«
onMessage ã onNotice ã sendMessage ã nick ã®å¤æ´ã ããããªãã¦ãããããã§ãã¾ãï¼ï¼
çãããã½ã¼ã¹èªãã§ã¿ã¦ï¼ï¼
ãã¨ã
ãããããã¹ããã¦ãªããã¼ï¼ CodeRepos ã ããã¿ããªãã¹ãã¨ããã¦ãã¦ã¼
ãã®ãã¼
ï¼¼ï¼ï¼¾oï¼¾ï¼ï¼