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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.common.MyInfo;
  24. import com.dmdirc.parser.interfaces.Parser;
  25. import com.dmdirc.parser.interfaces.callbacks.DataInListener;
  26. import com.dmdirc.parser.interfaces.callbacks.DataOutListener;
  27. import com.dmdirc.parser.interfaces.callbacks.DebugInfoListener;
  28. import com.dmdirc.parser.interfaces.callbacks.Post005Listener;
  29. import com.dmdirc.parser.irc.IRCParser;
  30. import com.dmdirc.parser.irc.ServerInfo;
  31. import java.util.Date;
  32. /**
  33. *
  34. * @author chris
  35. */
  36. public class CharlieBravo implements Runnable, Post005Listener,
  37. DebugInfoListener, DataInListener, DataOutListener {
  38. protected final Config config = new Config();
  39. protected final InputHandler handler = new InputHandler(config);
  40. protected final String[] servers = {"irc.quakenet.org","83.140.172.211"};
  41. public void run() {
  42. int server = 0;
  43. while (true) {
  44. final MyInfo myinfo = new MyInfo();
  45. myinfo.setNickname("CharlieBravo");
  46. myinfo.setRealname("Charlie Bravo");
  47. myinfo.setUsername("charliebravo");
  48. final IRCParser parser = new IRCParser(myinfo, new ServerInfo(servers[server], 6667, ""));
  49. handler.setParser(parser);
  50. parser.getCallbackManager().addCallback(Post005Listener.class, this);
  51. parser.getCallbackManager().addCallback(DebugInfoListener.class, this);
  52. parser.getCallbackManager().addCallback(DataInListener.class, this);
  53. parser.getCallbackManager().addCallback(DataOutListener.class, this);
  54. parser.run();
  55. server = ++server % servers.length;
  56. try {
  57. Thread.sleep(5000);
  58. } catch (InterruptedException ex) {
  59. // Don't care!
  60. }
  61. }
  62. }
  63. @Override
  64. public void onPost005(final Parser tParser, final Date date) {
  65. tParser.joinChannel("#MD87");
  66. tParser.joinChannel("#DMDirc");
  67. tParser.joinChannel("#DMDirc.dev");
  68. tParser.joinChannel("#MDbot");
  69. }
  70. @Override
  71. public void onDebugInfo(final Parser tParser, final Date date, final int nLevel, final String sData) {
  72. System.out.println(nLevel + ": " + sData);
  73. }
  74. public static void main(final String ... args) throws Exception {
  75. new Thread(new CharlieBravo()).start();
  76. }
  77. @Override
  78. public void onDataIn(final Parser tParser, final Date date, final String sData) {
  79. System.out.println("<<< " + sData);
  80. }
  81. @Override
  82. public void onDataOut(final Parser tParser, final Date date, final String sData, final boolean bFromParser) {
  83. System.out.println(">>> " + sData);
  84. }
  85. }