Java IRC bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CharlieBravo.java 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2009-2010 Chris Smith
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.md87.charliebravo;
  23. import com.dmdirc.parser.irc.IRCParser;
  24. import com.dmdirc.parser.irc.MyInfo;
  25. import com.dmdirc.parser.irc.ServerInfo;
  26. import com.dmdirc.parser.irc.callbacks.interfaces.IDataIn;
  27. import com.dmdirc.parser.irc.callbacks.interfaces.IDataOut;
  28. import com.dmdirc.parser.irc.callbacks.interfaces.IDebugInfo;
  29. import com.dmdirc.parser.irc.callbacks.interfaces.IPost005;
  30. /**
  31. *
  32. * @author chris
  33. */
  34. public class CharlieBravo implements Runnable, IPost005, IDebugInfo, IDataIn, IDataOut {
  35. protected final Config config = new Config();
  36. protected final InputHandler handler = new InputHandler(config);
  37. protected final String[] servers = {"irc.quakenet.org","83.140.172.211"};
  38. public void run() {
  39. int server = 0;
  40. while (true) {
  41. final MyInfo myinfo = new MyInfo();
  42. myinfo.setNickname("CharlieBravo");
  43. myinfo.setRealname("Charlie Bravo");
  44. myinfo.setUsername("charliebravo");
  45. final IRCParser parser = new IRCParser(myinfo, new ServerInfo(servers[server], 6667, ""));
  46. handler.setParser(parser);
  47. parser.getCallbackManager().addCallback("OnPost005", this);
  48. parser.getCallbackManager().addCallback("OnDebugInfo", this);
  49. parser.getCallbackManager().addCallback("OnDataIn", this);
  50. parser.getCallbackManager().addCallback("OnDataOut", this);
  51. parser.run();
  52. server = ++server % servers.length;
  53. try {
  54. Thread.sleep(5000);
  55. } catch (InterruptedException ex) {
  56. // Don't care!
  57. }
  58. }
  59. }
  60. public void onPost005(final IRCParser tParser) {
  61. tParser.joinChannel("#MD87");
  62. tParser.joinChannel("#DMDirc");
  63. tParser.joinChannel("#DMDirc.dev");
  64. tParser.joinChannel("#MDbot");
  65. }
  66. public void onDebugInfo(final IRCParser tParser, final int nLevel, final String sData) {
  67. System.out.println(nLevel + ": " + sData);
  68. }
  69. public static void main(final String ... args) throws Exception {
  70. new Thread(new CharlieBravo()).start();
  71. }
  72. public void onDataIn(final IRCParser tParser, final String sData) {
  73. System.out.println("<<< " + sData);
  74. }
  75. public void onDataOut(final IRCParser tParser, final String sData, final boolean bFromParser) {
  76. System.out.println(">>> " + sData);
  77. }
  78. }