├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.xml ├── docs ├── allclasses-frame.html ├── allclasses-noframe.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-all.html ├── index.html ├── org.ublab.bot │ ├── Colors.html │ ├── DccChat.html │ ├── DccFileTransfer.html │ ├── DccManager.html │ ├── IdentServer.html │ ├── InputThread.html │ ├── IrcException.html │ ├── NickAlreadyInUseException.html │ ├── OutputThread.html │ ├── Queue.html │ ├── ReplyConstants.html │ ├── UblabBot.html │ ├── User.html │ ├── class-use │ │ ├── Colors.html │ │ ├── DccChat.html │ │ ├── DccFileTransfer.html │ │ ├── DccManager.html │ │ ├── IdentServer.html │ │ ├── InputThread.html │ │ ├── IrcException.html │ │ ├── NickAlreadyInUseException.html │ │ ├── OutputThread.html │ │ ├── Queue.html │ │ ├── ReplyConstants.html │ │ ├── UblabBot.html │ │ └── User.html │ ├── package-frame.html │ ├── package-summary.html │ ├── package-tree.html │ └── package-use.html ├── overview-tree.html ├── package-list ├── packages.html ├── pircbot-style.css ├── resources │ └── inherit.gif ├── serialized-form.html └── stylesheet.css ├── pom.xml └── src ├── main └── java │ └── org │ └── ublab │ └── bot │ ├── App.java │ ├── Colors.java │ ├── DccChat.java │ ├── DccFileTransfer.java │ ├── DccManager.java │ ├── IdentServer.java │ ├── InputThread.java │ ├── IrcException.java │ ├── NickAlreadyInUseException.java │ ├── OutputThread.java │ ├── Queue.java │ ├── ReplyConstants.java │ ├── UblabBot.java │ └── User.java └── test └── java └── org └── ublab └── bot └── AppTest.java /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | # Known text file extensions 4 | *.as text 5 | *.bat text 6 | *.cnf text 7 | *.conf text 8 | *.css text 9 | *.csv text 10 | *.dtd text 11 | *.erb text 12 | *.ftl text 13 | *.gitattributes text 14 | *.gitignore text 15 | *.gitkeep text 16 | *.gitmodules text 17 | *.groovy text 18 | *.gsp text 19 | *.htaccess text 20 | *.htm text 21 | *.html text 22 | *.java text 23 | *.js text 24 | *.js.withjstl text 25 | *.json text 26 | *.jsp text 27 | *.list text 28 | *.lock text 29 | *.log text 30 | *.markdown text 31 | *.md text 32 | *.nsh text 33 | *.nsi text 34 | *.opts text 35 | *.php text 36 | *.pl text 37 | *.policy text 38 | *.pp text 39 | *.project text 40 | *.properties text 41 | *.rb text 42 | *.rdf text 43 | *.scss text 44 | *.sh text 45 | *.sql text 46 | *.story text 47 | *.svg text 48 | *.tag text 49 | *.tld text 50 | *.txt text 51 | *.vm text 52 | *.xml text 53 | *.xsl text 54 | *.xslt text 55 | *.yaml text 56 | *.yml text 57 | 58 | # Known binary file extensions 59 | *.bmp binary 60 | *.chls binary 61 | *.class binary 62 | *.db binary 63 | *.eot binary 64 | *.exe binary 65 | *.gif binary 66 | *.gzip binary 67 | *.ico binary 68 | *.jar binary 69 | *.jpeg binary 70 | *.jpg binary 71 | *.omod binary 72 | *.png binary 73 | *.ttf binary 74 | *.woff binary 75 | *.zip binary 76 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Copied from https://github.com/github/gitignore 2 | 3 | ### IntelliJ Idea ### 4 | *.iml 5 | *.ipr 6 | *.iws 7 | .idea/ 8 | 9 | ### Maven ### 10 | target/ 11 | pom.xml.versionsBackup 12 | ############# 13 | 14 | ### Eclipse ### 15 | *.pydevproject 16 | .project 17 | .metadata 18 | bin/** 19 | tmp/** 20 | tmp/**/* 21 | *.tmp 22 | *.bak 23 | *.swp 24 | *~.nib 25 | local.properties 26 | .classpath 27 | .settings/ 28 | .loadpath 29 | 30 | # External tool builders 31 | .externalToolBuilders/ 32 | 33 | # Locally stored "Eclipse launch configurations" 34 | *.launch 35 | 36 | # CDT-specific 37 | .cproject 38 | 39 | # PDT-specific 40 | .buildpath 41 | ############### 42 | 43 | ### Java ### 44 | *.class 45 | 46 | # Java Package Files # 47 | *.jar 48 | *.war 49 | *.ear 50 | ############ 51 | 52 | ### Netbeans ### 53 | nbproject/private/ 54 | build/ 55 | bin/ 56 | nbbuild/ 57 | dist/ 58 | nbdist/ 59 | nbactions.xml 60 | nb-configuration.xml 61 | ################ 62 | 63 | ### Linux ### 64 | .* 65 | !.gitignore 66 | !.gitattributes 67 | *~ 68 | ############# 69 | 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ublab-bot 2 | IRC bot for #ublab on freenode 3 | 4 | 5 | ## Instructions 6 | 7 | This document will describe how to contribute to this project 8 | 9 | ### Step 1. Star && Fork the Repo and build a simple bot 10 | 11 | Clone the ublab-bot repo and build it. 12 | 13 | ```` 14 | $ git https://github.com/EliteProgrammersClub/ublab-bot.git 15 | $ cd ublab-bot 16 | $ mvn clean install 17 | 18 | 19 | This command generates a jar file for the bot 20 | ```` 21 | 22 | ### Step 2. Contribute Code 23 | 24 | I.) Write Unit tests for each capability or functionality added. 25 | 26 | II.) Run the tests 27 | 28 | III.) Make a Pull Request 29 | 30 | 31 | 32 | ## RoadMap 33 | 34 | We have alot of ideas we would love our bot to perform, but we can only do as much. Here are some basic enhancement ideas we have in mind. 35 | 36 | 1.) Logging, logging in different ways to achieve useful results, such as remembering when people were last active, logging URLs, running blogs and recapping on conversations. 37 | 38 | 2.) Search and Query, Make ublab-bot to search Google and lookup words on FOLDOC. Web Services can be used to make bots that search for books on Amazon, check the weather, translate languages or convert currencies. 39 | 40 | 3.) Community and Fun, Make ublab-bot perform fun applications such as generating social network diagrams of a community, passing messages on to other users; fun bots that create comic strips, calculate mathematical expressions and even act as a quizmaster. 41 | 42 | 4.) Announcements, With the growing popularity of RSS, We can make ublab-bot read news into a channel from RSS feeds. Announce items posted on Google+, Facebook, twitter, mailing lists or even other tech events in town! 43 | 44 | 5.) Channel management, IRC is accessible by anybody, you occasionally find the odd user who is intent on causing trouble. The primary target of such abuse is usually our channel, where messages may be spammed or topics changed. Enable ublab-bot take care of such troublemakers and thwart their evil intentions. 45 | 46 | 47 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ublab-bot (JAR) with Ant build script 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /docs/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | All Classes 19 |
20 | 21 | 22 | 23 | 50 | 51 |
Colors 24 |
25 | DccChat 26 |
27 | DccFileTransfer 28 |
29 | DccManager 30 |
31 | IdentServer 32 |
33 | InputThread 34 |
35 | IrcException 36 |
37 | NickAlreadyInUseException 38 |
39 | OutputThread 40 |
41 | UblabBot 42 |
43 | Queue 44 |
45 | ReplyConstants 46 |
47 | User 48 |
49 |
52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /docs/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | All Classes 19 |
20 | 21 | 22 | 23 | 50 | 51 |
Colors 24 |
25 | DccChat 26 |
27 | DccFileTransfer 28 |
29 | DccManager 30 |
31 | IdentServer 32 |
33 | InputThread 34 |
35 | IrcException 36 |
37 | NickAlreadyInUseException 38 |
39 | OutputThread 40 |
41 | UblabBot 42 |
43 | Queue 44 |
45 | ReplyConstants 46 |
47 | User 48 |
49 |
52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /docs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Deprecated List (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Deprecated API

77 |
78 | 79 | 80 | 81 | 83 | 84 | 85 | 88 | 89 | 90 | 93 | 94 | 95 | 98 | 99 | 100 | 103 | 104 | 105 | 108 | 109 |
82 | Deprecated Methods
org.ublab.bot.UblabBot.dccAcceptChatRequest(String, long, int) 86 |
87 |           As of UblabBot 1.2.0, use UblabBot.onIncomingChatRequest(DccChat) 
org.ublab.bot.UblabBot.dccReceiveFile(File, long, int, int) 91 |
92 |           As of UblabBot 1.2.0, use UblabBot.onIncomingFileTransfer(DccFileTransfer) 
org.ublab.bot.UblabBot.onDccChatRequest(String, String, String, long, int) 96 |
97 |           As of UblabBot 1.2.0, use UblabBot.onIncomingChatRequest(DccChat) 
org.ublab.bot.UblabBot.onDccSendRequest(String, String, String, String, long, int, int) 101 |
102 |           As of UblabBot 1.2.0, use UblabBot.onIncomingFileTransfer(DccFileTransfer) 
org.ublab.bot.UblabBot.onTopic(String, String) 106 |
107 |           As of 1.2.0, replaced by UblabBot.onTopic(String,String,String,long,boolean) 
110 |   111 |

112 |


113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 134 | 137 | 138 | 139 | 140 | 143 | 158 | 159 |
135 | UblabBot Java IRC Bot 136 |
160 | 161 | 162 | 163 |
164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /docs/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | API Help (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | How This API Document Is Organized

77 |
78 | This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

79 | Package

80 |
81 | 82 |

83 | Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

85 |
86 |

87 | Class/Interface

88 |
89 | 90 |

91 | Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

97 | Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
98 |

99 | Use

100 |
101 | Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
102 |

103 | Tree (Class Hierarchy)

104 |
105 | There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object. 107 |
108 |

109 | Deprecated API

110 |
111 | The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
112 |

113 | Index

114 |
115 | The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
116 |

117 | Prev/Next

118 | These links take you to the next or previous class, interface, package, or related page.

119 | Frames/No Frames

120 | These links show and hide the HTML frames. All pages are available with or without frames. 121 |

122 |

123 | Serialized Form

124 | Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. 125 |

126 | 127 | 128 | This help file applies to API documentation generated using the standard doclet. 129 | 130 |
131 |


132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 153 | 156 | 157 | 158 | 159 | 162 | 177 | 178 |
154 | UblabBot Java IRC Bot 155 |
179 | 180 | 181 | 182 |
183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ublab Bot 1.0 - Java IRC API Bot Framework 8 | 9 | 10 | 11 | 12 | 13 | 14 | <H2> 15 | Frame Alert</H2> 16 | 17 | <P> 18 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. 19 | <BR> 20 | Link to<A HREF="org.ublab.bot/UblabBot.html">Non-frame version.</A> 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/Colors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.Colors (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.Colors

77 |
78 | No usage of org.ublab.bot.Colors 79 |

80 |


81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 102 | 105 | 106 | 107 | 108 | 111 | 126 | 127 |
103 | UblabBot Java IRC Bot 104 |
128 | 129 | 130 | 131 |
132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/DccChat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.DccChat (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.DccChat

77 |
78 | 79 | 80 | 81 | 83 | 84 |
82 | Uses of DccChat in org.ublab.bot
85 |   86 |

87 | 88 | 89 | 90 | 91 | 92 | 93 | 95 | 100 | 101 | 102 | 104 | 110 | 111 |
Methods in org.ublab.bot that return DccChat
94 |  DccChatUblabBot.dccSendChatRequest(String nick, 96 | int timeout) 97 | 98 |
99 |           Attempts to establish a DCC CHAT session with a client.
103 | protected  DccChatUblabBot.dccAcceptChatRequest(String sourceNick, 105 | long address, 106 | int port) 107 | 108 |
109 |           Deprecated. As of UblabBot 1.2.0, use UblabBot.onIncomingChatRequest(DccChat)
112 |   113 |

114 | 115 | 116 | 117 | 118 | 119 | 120 | 122 | 126 | 127 |
Methods in org.ublab.bot with parameters of type DccChat
121 | protected  voidUblabBot.onIncomingChatRequest(DccChat chat) 123 | 124 |
125 |           This method will be called whenever a DCC Chat request is received.
128 |   129 |

130 |


131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 152 | 155 | 156 | 157 | 158 | 161 | 176 | 177 |
153 | UblabBot Java IRC Bot 154 |
178 | 179 | 180 | 181 |
182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/DccFileTransfer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.DccFileTransfer (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.DccFileTransfer

77 |
78 | 79 | 80 | 81 | 83 | 84 |
82 | Uses of DccFileTransfer in org.ublab.bot
85 |   86 |

87 | 88 | 89 | 90 | 91 | 92 | 93 | 95 | 101 | 102 |
Methods in org.ublab.bot that return DccFileTransfer
94 |  DccFileTransferUblabBot.dccSendFile(File file, 96 | String nick, 97 | int timeout) 98 | 99 |
100 |           Sends a file to another user.
103 |   104 |

105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 117 | 118 | 119 | 121 | 126 | 127 |
Methods in org.ublab.bot with parameters of type DccFileTransfer
112 | protected  voidUblabBot.onIncomingFileTransfer(DccFileTransfer transfer) 114 | 115 |
116 |           This method is called whenever a DCC SEND request is sent to the UblabBot.
120 | protected  voidUblabBot.onFileTransferFinished(DccFileTransfer transfer, 122 | Exception e) 123 | 124 |
125 |           This method gets called when a DccFileTransfer has finished.
128 |   129 |

130 |


131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 152 | 155 | 156 | 157 | 158 | 161 | 176 | 177 |
153 | UblabBot Java IRC Bot 154 |
178 | 179 | 180 | 181 |
182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/DccManager.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.DccManager (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.DccManager

77 |
78 | No usage of org.ublab.bot.DccManager 79 |

80 |


81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 102 | 105 | 106 | 107 | 108 | 111 | 126 | 127 |
103 | UblabBot Java IRC Bot 104 |
128 | 129 | 130 | 131 |
132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/IdentServer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.IdentServer (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.IdentServer

77 |
78 | No usage of org.ublab.bot.IdentServer 79 |

80 |


81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 102 | 105 | 106 | 107 | 108 | 111 | 126 | 127 |
103 | UblabBot Java IRC Bot 104 |
128 | 129 | 130 | 131 |
132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/InputThread.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.InputThread (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.InputThread

77 |
78 | No usage of org.ublab.bot.InputThread 79 |

80 |


81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 102 | 105 | 106 | 107 | 108 | 111 | 126 | 127 |
103 | UblabBot Java IRC Bot 104 |
128 | 129 | 130 | 131 |
132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/NickAlreadyInUseException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.NickAlreadyInUseException (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.NickAlreadyInUseException

77 |
78 | 79 | 80 | 81 | 83 | 84 |
82 | Uses of NickAlreadyInUseException in org.ublab.bot
85 |   86 |

87 | 88 | 89 | 90 | 91 | 92 | 93 | 95 | 99 | 100 | 101 | 103 | 108 | 109 | 110 | 112 | 119 | 120 | 121 | 123 | 127 | 128 |
Methods in org.ublab.bot that throw NickAlreadyInUseException
94 |  voidUblabBot.connect(String hostname) 96 | 97 |
98 |           Attempt to connect to the specified IRC server.
102 |  voidUblabBot.connect(String hostname, 104 | int port) 105 | 106 |
107 |           Attempt to connect to the specified IRC server and port number.
111 |  voidUblabBot.connect(String hostname, 113 | int port, 114 | String password) 115 | 116 |
117 |           Attempt to connect to the specified IRC server using the supplied 118 | password.
122 |  voidUblabBot.reconnect() 124 | 125 |
126 |           Reconnects to the IRC server that we were previously connected to.
129 |   130 |

131 |


132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 153 | 156 | 157 | 158 | 159 | 162 | 177 | 178 |
154 | UblabBot Java IRC Bot 155 |
179 | 180 | 181 | 182 |
183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/OutputThread.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.OutputThread (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.OutputThread

77 |
78 | No usage of org.ublab.bot.OutputThread 79 |

80 |


81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 102 | 105 | 106 | 107 | 108 | 111 | 126 | 127 |
103 | UblabBot Java IRC Bot 104 |
128 | 129 | 130 | 131 |
132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/Queue.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.Queue (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.Queue

77 |
78 | No usage of org.ublab.bot.Queue 79 |

80 |


81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 102 | 105 | 106 | 107 | 108 | 111 | 126 | 127 |
103 | UblabBot Java IRC Bot 104 |
128 | 129 | 130 | 131 |
132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/ReplyConstants.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Interface org.ublab.bot.ReplyConstants (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Interface
org.ublab.bot.ReplyConstants

77 |
78 | 79 | 80 | 81 | 83 | 84 |
82 | Uses of ReplyConstants in org.ublab.bot
85 |   86 |

87 | 88 | 89 | 90 | 91 | 92 | 93 | 95 | 99 | 100 |
Classes in org.ublab.bot that implement ReplyConstants
94 |  classUblabBot 96 | 97 |
98 |           UblabBot is a Java framework for writing IRC bots quickly and easily.
101 |   102 |

103 |


104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 125 | 128 | 129 | 130 | 131 | 134 | 149 | 150 |
126 | UblabBot Java IRC Bot 127 |
151 | 152 | 153 | 154 |
155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/UblabBot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.UblabBot (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.UblabBot

77 |
78 | No usage of org.ublab.bot.UblabBot 79 |

80 |


81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 102 | 105 | 106 | 107 | 108 | 111 | 126 | 127 |
103 | UblabBot Java IRC Bot 104 |
128 | 129 | 130 | 131 |
132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/class-use/User.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class org.ublab.bot.User (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Class
org.ublab.bot.User

77 |
78 | 79 | 80 | 81 | 83 | 84 |
82 | Uses of User in org.ublab.bot
85 |   86 |

87 | 88 | 89 | 90 | 91 | 92 | 93 | 95 | 99 | 100 |
Methods in org.ublab.bot that return User
94 |  User[]UblabBot.getUsers(String channel) 96 | 97 |
98 |           Returns an array of all users in the specified channel.
101 |   102 |

103 | 104 | 105 | 106 | 107 | 108 | 109 | 111 | 117 | 118 |
Methods in org.ublab.bot with parameters of type User
110 | protected  voidUblabBot.onUserList(String channel, 112 | User[] users) 113 | 114 |
115 |           This method is called when we receive a user list from the server 116 | after joining a channel.
119 |   120 |

121 |


122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 143 | 146 | 147 | 148 | 149 | 152 | 167 | 168 |
144 | UblabBot Java IRC Bot 145 |
169 | 170 | 171 | 172 |
173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | org.ublab.bot (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | org.ublab.bot 20 | 21 | 22 | 27 | 28 |
23 | Interfaces  24 | 25 |
26 | ReplyConstants
29 | 30 | 31 | 32 | 33 | 56 | 57 |
34 | Classes  35 | 36 |
37 | Colors 38 |
39 | DccChat 40 |
41 | DccFileTransfer 42 |
43 | DccManager 44 |
45 | IdentServer 46 |
47 | InputThread 48 |
49 | OutputThread 50 |
51 | UblabBot 52 |
53 | Queue 54 |
55 | User
58 | 59 | 60 | 61 | 62 | 69 | 70 |
63 | Exceptions  64 | 65 |
66 | IrcException 67 |
68 | NickAlreadyInUseException
71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | org.ublab.bot Class Hierarchy (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Hierarchy For Package org.ublab.bot 77 |

78 |
79 |

80 | Class Hierarchy 81 |

82 | 97 |

98 | Interface Hierarchy 99 |

100 | 102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 124 | 127 | 128 | 129 | 130 | 133 | 148 | 149 |
125 | UblabBot Java IRC Bot 126 |
150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /docs/org.ublab.bot/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Package org.ublab.bot (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Uses of Package
org.ublab.bot

77 |
78 | 79 | 80 | 81 | 83 | 84 | 85 | 89 | 90 | 91 | 95 | 96 | 97 | 101 | 102 | 103 | 107 | 108 | 109 | 114 | 115 | 116 | 120 | 121 |
82 | Classes in org.ublab.bot used by org.ublab.bot
DccChat 86 | 87 |
88 |           This class is used to allow the bot to interact with a DCC Chat session.
DccFileTransfer 92 | 93 |
94 |           This class is used to administer a DCC file transfer.
IrcException 98 | 99 |
100 |           An IrcException class.
NickAlreadyInUseException 104 | 105 |
106 |           A NickAlreadyInUseException class.
ReplyConstants 110 | 111 |
112 |           This interface contains the values of all numeric replies specified 113 | in section 6 of RFC 1459.
User 117 | 118 |
119 |           This class is used to represent a user on an IRC server.
122 |   123 |

124 |


125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 146 | 149 | 150 | 151 | 152 | 155 | 170 | 171 |
147 | UblabBot Java IRC Bot 148 |
172 | 173 | 174 | 175 |
176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /docs/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Class Hierarchy (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Hierarchy For All Packages

77 |
78 |
79 |
Package Hierarchies:
org.ublab.bot
80 |
81 |

82 | Class Hierarchy 83 |

84 | 99 |

100 | Interface Hierarchy 101 |

102 | 104 |
105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 126 | 129 | 130 | 131 | 132 | 135 | 150 | 151 |
127 | UblabBot Java IRC Bot 128 |
152 | 153 | 154 | 155 |
156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /docs/package-list: -------------------------------------------------------------------------------- 1 | org.ublab.bot 2 | -------------------------------------------------------------------------------- /docs/packages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 |
27 | 28 |
29 |
30 | The front page has been relocated.Please see: 31 |
32 |           Frame version 33 |
34 |           Non-frame version.
35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /docs/pircbot-style.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | 3 | /* 4 | $Id: pircbot-style.css,v 1.3 2003/06/20 09:29:03 pjm2 Exp $ 5 | $Author: pjm2 $ 6 | */ 7 | 8 | /* Define colors, fonts and other style attributes here to override the defaults */ 9 | 10 | /* Page background color */ 11 | body { background-color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px;} 12 | 13 | td { 14 | font-size: 13px; 15 | } 16 | 17 | code { 18 | font-family: Courier New, Courier, mono, monospace; 19 | font-size: 13px; 20 | color: #000066; 21 | } 22 | 23 | pre { 24 | font-size: 12px; 25 | color: #000066; 26 | padding: 5px; 27 | border: 1px solid #666699; 28 | border-left: 4px solid #666699; 29 | background: #ffeedd; 30 | } 31 | 32 | /* Table colors */ 33 | .TableHeadingColor { background: #CCCCFF } /* Dark mauve */ 34 | .TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ 35 | .TableRowColor { background: #FFFFFF } /* White */ 36 | 37 | /* Font used in left-hand frame lists */ 38 | .FrameTitleFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif } 39 | .FrameHeadingFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif } 40 | .FrameItemFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif } 41 | 42 | /* Example of smaller, sans-serif font in frames */ 43 | /* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */ 44 | 45 | /* Navigation bar fonts and colors */ 46 | .NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */ 47 | .NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */ 48 | .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} 49 | .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} 50 | 51 | .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 52 | .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 53 | 54 | -------------------------------------------------------------------------------- /docs/resources/inherit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EliteProgrammersClub/ublab-bot/b7f965839882135025b770de1ec477b8f71ad442/docs/resources/inherit.gif -------------------------------------------------------------------------------- /docs/serialized-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Serialized Form (ublab Bot 1.0 - Java IRC API Bot Framework) 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | UblabBot Java IRC Bot 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | Serialized Form

77 |
78 |
79 | 80 | 81 | 82 | 84 | 85 |
83 | Package org.ublab.bot
86 | 87 |

88 | 89 | 90 | 91 | 93 | 94 |
92 | Class org.ublab.bot.IrcException extends Exception implements Serializable
95 | 96 |

97 | 98 |

99 | 100 | 101 | 102 | 104 | 105 |
103 | Class org.ublab.bot.NickAlreadyInUseException extends IrcException implements Serializable
106 | 107 |

108 | 109 |

110 |


111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 132 | 135 | 136 | 137 | 138 | 141 | 156 | 157 |
133 | UblabBot Java IRC Bot 134 |
158 | 159 | 160 | 161 |
162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | 3 | /* Define colors, fonts and other style attributes here to override the defaults */ 4 | 5 | /* Page background color */ 6 | body { background-color: #FFFFFF } 7 | 8 | /* Headings */ 9 | h1 { font-size: 145% } 10 | 11 | /* Table colors */ 12 | .TableHeadingColor { background: #CCCCFF } /* Dark mauve */ 13 | .TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ 14 | .TableRowColor { background: #FFFFFF } /* White */ 15 | 16 | /* Font used in left-hand frame lists */ 17 | .FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif } 18 | .FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif } 19 | .FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif } 20 | 21 | /* Navigation bar fonts and colors */ 22 | .NavBarCell1 { background-color:#EEEEFF;} /* Light mauve */ 23 | .NavBarCell1Rev { background-color:#00008B;} /* Dark Blue */ 24 | .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} 25 | .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} 26 | 27 | .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 28 | .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 29 | 30 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.ublab.bot 5 | ublab-bot 6 | 1.0 7 | jar 8 | ublab bot 9 | IRC bot for #ublab 10 | https://github.com/EliteProgrammersClub/ublab-bot 11 | 12 | 13 | 14 | Black Hackers 15 | https://github.com/EliteProgrammersClub 16 | 17 | 18 | 19 | 20 | 21 | Nyah Check 22 | 23 | 24 | 25 | 26 | scm:git:git@github.com:EliteProgrammersClub/ublab-bot.git 27 | scm:git:git@github.com:EliteProgrammersClub/ublab-bot.git 28 | https://github.com/EliteProgrammersClub/ublab-bot 29 | 30 | 31 | 32 | 33 | UTF-8 34 | 35 | 36 | 37 | 38 | junit 39 | junit 40 | 4.13.1 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.apache.maven.plugins 51 | maven-jar-plugin 52 | 2.4 53 | 54 | 55 | 56 | true 57 | target 58 | org.ublab.bot.App 59 | 60 | 61 | 62 | 63 | 64 | org.apache.maven.plugins 65 | maven-antrun-plugin 66 | 1.1 67 | 68 | 69 | id.validate 70 | validate 71 | 72 | run 73 | 74 | 75 | 76 | validate phase 77 | 78 | 79 | 80 | 81 | id.compile 82 | compile 83 | 84 | run 85 | 86 | 87 | 88 | compile phase 89 | 90 | 91 | 92 | 93 | id.test 94 | test 95 | 96 | run 97 | 98 | 99 | 100 | test phase 101 | 102 | 103 | 104 | 105 | id.package 106 | package 107 | 108 | run 109 | 110 | 111 | 112 | package phase 113 | 114 | 115 | 116 | 117 | id.deploy 118 | deploy 119 | 120 | run 121 | 122 | 123 | 124 | deploy phase 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/App.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | import org.ublab.bot.*; 23 | import java.util.logging.Logger; 24 | 25 | /** 26 | * #ublab IRC bot 27 | * 28 | */ 29 | public class App extends UblabBot { 30 | 31 | private static final String IRC_NETWORK = "irc.freenode.net"; 32 | private static final String IRC_CHANNEL = "#ublab"; 33 | 34 | public App() { 35 | this.setName("ublab-bot"); 36 | } 37 | 38 | public static void main( String[] args ) { 39 | 40 | Logger logger = Logger.getLogger(App.class.getName()); 41 | // Starts ublab-bot 42 | App bot = new App(); 43 | 44 | try { 45 | //Enables debugging output. 46 | bot.connect(IRC_NETWORK); 47 | logger.info("Connected to " + IRC_NETWORK); 48 | //Join #ublab channel. 49 | bot.joinChannel(IRC_CHANNEL); 50 | logger.info("Joined " + IRC_CHANNEL); 51 | 52 | } catch (Exception ex) { 53 | logger.warning("Caught exception. Closing..."); 54 | ex.printStackTrace(); 55 | System.exit(1); 56 | } 57 | 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/Colors.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | /** 23 | * The Colors class provides several static fields and methods that you may 24 | * find useful when writing an IRC Bot. 25 | *

26 | * This class contains constants that are useful for formatting lines 27 | * sent to IRC servers. These constants allow you to apply various 28 | * formatting to the lines, such as colours, boldness, underlining 29 | * and reverse text. 30 | *

31 | * The class contains static methods to remove colours and formatting 32 | * from lines of IRC text. 33 | *

34 | * Here are some examples of how to use the contants from within a 35 | * class that extends UblabBot and imports org.jibble.pircbot.*; 36 | * 37 | *

 sendMessage("#cs", Colors.BOLD + "A bold hello!");
 38 |  *     A bold hello!
 39 |  * sendMessage("#cs", Colors.RED + "Red" + Colors.NORMAL + " text");
 40 |  *     Red text
 41 |  * sendMessage("#cs", Colors.BOLD + Colors.RED + "Bold and red");
 42 |  *     Bold and red
43 | * 44 | * Please note that some IRC channels may be configured to reject any 45 | * messages that use colours. Also note that older IRC clients may be 46 | * unable to correctly display lines that contain colours and other 47 | * control characters. 48 | *

49 | * Note that this class name has been spelt in the American style in 50 | * order to remain consistent with the rest of the Java API. 51 | * 52 | * 53 | */ 54 | public class Colors { 55 | 56 | 57 | /** 58 | * Removes all previously applied color and formatting attributes. 59 | */ 60 | public static final String NORMAL = "\u000f"; 61 | 62 | 63 | /** 64 | * Bold text. 65 | */ 66 | public static final String BOLD = "\u0002"; 67 | 68 | 69 | /** 70 | * Underlined text. 71 | */ 72 | public static final String UNDERLINE = "\u001f"; 73 | 74 | 75 | /** 76 | * Reversed text (may be rendered as italic text in some clients). 77 | */ 78 | public static final String REVERSE = "\u0016"; 79 | 80 | 81 | /** 82 | * White coloured text. 83 | */ 84 | public static final String WHITE = "\u000300"; 85 | 86 | 87 | /** 88 | * Black coloured text. 89 | */ 90 | public static final String BLACK = "\u000301"; 91 | 92 | 93 | /** 94 | * Dark blue coloured text. 95 | */ 96 | public static final String DARK_BLUE = "\u000302"; 97 | 98 | 99 | /** 100 | * Dark green coloured text. 101 | */ 102 | public static final String DARK_GREEN = "\u000303"; 103 | 104 | 105 | /** 106 | * Red coloured text. 107 | */ 108 | public static final String RED = "\u000304"; 109 | 110 | 111 | /** 112 | * Brown coloured text. 113 | */ 114 | public static final String BROWN = "\u000305"; 115 | 116 | 117 | /** 118 | * Purple coloured text. 119 | */ 120 | public static final String PURPLE = "\u000306"; 121 | 122 | 123 | /** 124 | * Olive coloured text. 125 | */ 126 | public static final String OLIVE = "\u000307"; 127 | 128 | 129 | /** 130 | * Yellow coloured text. 131 | */ 132 | public static final String YELLOW = "\u000308"; 133 | 134 | 135 | /** 136 | * Green coloured text. 137 | */ 138 | public static final String GREEN = "\u000309"; 139 | 140 | 141 | /** 142 | * Teal coloured text. 143 | */ 144 | public static final String TEAL = "\u000310"; 145 | 146 | 147 | /** 148 | * Cyan coloured text. 149 | */ 150 | public static final String CYAN = "\u000311"; 151 | 152 | 153 | /** 154 | * Blue coloured text. 155 | */ 156 | public static final String BLUE = "\u000312"; 157 | 158 | 159 | /** 160 | * Magenta coloured text. 161 | */ 162 | public static final String MAGENTA = "\u000313"; 163 | 164 | 165 | /** 166 | * Dark gray coloured text. 167 | */ 168 | public static final String DARK_GRAY = "\u000314"; 169 | 170 | 171 | /** 172 | * Light gray coloured text. 173 | */ 174 | public static final String LIGHT_GRAY = "\u000315"; 175 | 176 | 177 | /** 178 | * This class should not be constructed. 179 | */ 180 | private Colors() { 181 | 182 | } 183 | 184 | 185 | /** 186 | * Removes all colours from a line of IRC text. 187 | * 188 | * @since UblabBot 1.0 189 | * 190 | * @param line the input text. 191 | * 192 | * @return the same text, but with all colours removed. 193 | */ 194 | public static String removeColors(String line) { 195 | int length = line.length(); 196 | StringBuffer buffer = new StringBuffer(); 197 | int i = 0; 198 | while (i < length) { 199 | char ch = line.charAt(i); 200 | if (ch == '\u0003') { 201 | i++; 202 | // Skip "x" or "xy" (foreground color). 203 | if (i < length) { 204 | ch = line.charAt(i); 205 | if (Character.isDigit(ch)) { 206 | i++; 207 | if (i < length) { 208 | ch = line.charAt(i); 209 | if (Character.isDigit(ch)) { 210 | i++; 211 | } 212 | } 213 | // Now skip ",x" or ",xy" (background color). 214 | if (i < length) { 215 | ch = line.charAt(i); 216 | if (ch == ',') { 217 | i++; 218 | if (i < length) { 219 | ch = line.charAt(i); 220 | if (Character.isDigit(ch)) { 221 | i++; 222 | if (i < length) { 223 | ch = line.charAt(i); 224 | if (Character.isDigit(ch)) { 225 | i++; 226 | } 227 | } 228 | } 229 | else { 230 | // Keep the comma. 231 | i--; 232 | } 233 | } 234 | else { 235 | // Keep the comma. 236 | i--; 237 | } 238 | } 239 | } 240 | } 241 | } 242 | } 243 | else if (ch == '\u000f') { 244 | i++; 245 | } 246 | else { 247 | buffer.append(ch); 248 | i++; 249 | } 250 | } 251 | return buffer.toString(); 252 | } 253 | 254 | 255 | /** 256 | * Remove formatting from a line of IRC text. 257 | * 258 | * @since UblabBot 1.0 259 | * 260 | * @param line the input text. 261 | * 262 | * @return the same text, but without any bold, underlining, reverse, etc. 263 | */ 264 | public static String removeFormatting(String line) { 265 | int length = line.length(); 266 | StringBuffer buffer = new StringBuffer(); 267 | for (int i = 0; i < length; i++) { 268 | char ch = line.charAt(i); 269 | if (ch == '\u000f' || ch == '\u0002' || ch == '\u001f' || ch == '\u0016') { 270 | // Don't add this character. 271 | } 272 | else { 273 | buffer.append(ch); 274 | } 275 | } 276 | return buffer.toString(); 277 | } 278 | 279 | 280 | /** 281 | * Removes all formatting and colours from a line of IRC text. 282 | * 283 | * @since UblabBot 1.0 284 | * 285 | * @param line the input text. 286 | * 287 | * @return the same text, but without formatting and colour characters. 288 | * 289 | */ 290 | public static String removeFormattingAndColors(String line) { 291 | return removeFormatting(removeColors(line)); 292 | } 293 | 294 | } 295 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/DccChat.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | import java.net.*; 23 | import java.io.*; 24 | 25 | /** 26 | * This class is used to allow the bot to interact with a DCC Chat session. 27 | * 28 | */ 29 | public class DccChat { 30 | 31 | 32 | /** 33 | * This constructor is used when we are accepting a DCC CHAT request 34 | * from somebody. It attempts to connect to the client that issued the 35 | * request. 36 | * 37 | * @param bot An instance of the underlying UblabBot. 38 | * @param sourceNick The nick of the sender. 39 | * @param address The address to connect to. 40 | * @param port The port number to connect to. 41 | * 42 | * @throws IOException If the connection cannot be made. 43 | */ 44 | DccChat(UblabBot bot, String nick, String login, String hostname, long address, int port) { 45 | _bot = bot; 46 | _address = address; 47 | _port = port; 48 | _nick = nick; 49 | _login = login; 50 | _hostname = hostname; 51 | _acceptable = true; 52 | } 53 | 54 | 55 | /** 56 | * This constructor is used after we have issued a DCC CHAT request to 57 | * somebody. If the client accepts the chat request, then the socket we 58 | * obtain is passed to this constructor. 59 | * 60 | * @param bot An instance of the underlying UblabBot. 61 | * @param sourceNick The nick of the user we are sending the request to. 62 | * @param socket The socket which will be used for the DCC CHAT session. 63 | * 64 | * @throws IOException If the socket cannot be read from. 65 | */ 66 | DccChat(UblabBot bot, String nick, Socket socket) throws IOException { 67 | _bot = bot; 68 | _nick = nick; 69 | _socket = socket; 70 | _reader = new BufferedReader(new InputStreamReader(_socket.getInputStream())); 71 | _writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream())); 72 | _acceptable = false; 73 | } 74 | 75 | 76 | /** 77 | * Accept this DccChat connection. 78 | * 79 | * @since 1.2.0 80 | * 81 | */ 82 | public synchronized void accept() throws IOException { 83 | if (_acceptable) { 84 | _acceptable = false; 85 | int[] ip = _bot.longToIp(_address); 86 | String ipStr = ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3]; 87 | _socket = new Socket(ipStr, _port); 88 | _reader = new BufferedReader(new InputStreamReader(_socket.getInputStream())); 89 | _writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream())); 90 | } 91 | } 92 | 93 | 94 | /** 95 | * Reads the next line of text from the client at the other end of our DCC Chat 96 | * connection. This method blocks until something can be returned. 97 | * If the connection has closed, null is returned. 98 | * 99 | * @return The next line of text from the client. Returns null if the 100 | * connection has closed normally. 101 | * 102 | * @throws IOException If an I/O error occurs. 103 | */ 104 | public String readLine() throws IOException { 105 | if (_acceptable) { 106 | throw new IOException("You must call the accept() method of the DccChat request before you can use it."); 107 | } 108 | return _reader.readLine(); 109 | } 110 | 111 | 112 | /** 113 | * Sends a line of text to the client at the other end of our DCC Chat 114 | * connection. 115 | * 116 | * @param line The line of text to be sent. This should not include 117 | * linefeed characters. 118 | * 119 | * @throws IOException If an I/O error occurs. 120 | */ 121 | public void sendLine(String line) throws IOException { 122 | if (_acceptable) { 123 | throw new IOException("You must call the accept() method of the DccChat request before you can use it."); 124 | } 125 | // No need for synchronization here really... 126 | _writer.write(line + "\r\n"); 127 | _writer.flush(); 128 | } 129 | 130 | 131 | /** 132 | * Closes the DCC Chat connection. 133 | * 134 | * @throws IOException If an I/O error occurs. 135 | */ 136 | public void close() throws IOException { 137 | if (_acceptable) { 138 | throw new IOException("You must call the accept() method of the DccChat request before you can use it."); 139 | } 140 | _socket.close(); 141 | } 142 | 143 | 144 | /** 145 | * Returns the nick of the other user taking part in this file transfer. 146 | * 147 | * @return the nick of the other user. 148 | * 149 | */ 150 | public String getNick() { 151 | return _nick; 152 | } 153 | 154 | 155 | /** 156 | * Returns the login of the DCC Chat initiator. 157 | * 158 | * @return the login of the DCC Chat initiator. null if we sent it. 159 | * 160 | */ 161 | public String getLogin() { 162 | return _login; 163 | } 164 | 165 | 166 | /** 167 | * Returns the hostname of the DCC Chat initiator. 168 | * 169 | * @return the hostname of the DCC Chat initiator. null if we sent it. 170 | * 171 | */ 172 | public String getHostname() { 173 | return _hostname; 174 | } 175 | 176 | 177 | /** 178 | * Returns the BufferedReader used by this DCC Chat. 179 | * 180 | * @return the BufferedReader used by this DCC Chat. 181 | */ 182 | public BufferedReader getBufferedReader() { 183 | return _reader; 184 | } 185 | 186 | 187 | /** 188 | * Returns the BufferedReader used by this DCC Chat. 189 | * 190 | * @return the BufferedReader used by this DCC Chat. 191 | */ 192 | public BufferedWriter getBufferedWriter() { 193 | return _writer; 194 | } 195 | 196 | 197 | /** 198 | * Returns the raw Socket used by this DCC Chat. 199 | * 200 | * @return the raw Socket used by this DCC Chat. 201 | */ 202 | public Socket getSocket() { 203 | return _socket; 204 | } 205 | 206 | 207 | /** 208 | * Returns the address of the sender as a long. 209 | * 210 | * @return the address of the sender as a long. 211 | */ 212 | public long getNumericalAddress() { 213 | return _address; 214 | } 215 | 216 | 217 | private UblabBot _bot; 218 | private String _nick; 219 | private String _login = null; 220 | private String _hostname = null; 221 | private BufferedReader _reader; 222 | private BufferedWriter _writer; 223 | private Socket _socket; 224 | private boolean _acceptable; 225 | private long _address = 0; 226 | private int _port = 0; 227 | 228 | } 229 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/DccManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | import java.util.*; 23 | 24 | /** 25 | * This class is used to process DCC events from the server. 26 | * 27 | */ 28 | public class DccManager { 29 | 30 | 31 | /** 32 | * Constructs a DccManager to look after all DCC SEND and CHAT events. 33 | * 34 | * @param bot The UblabBot whose DCC events this class will handle. 35 | */ 36 | DccManager(UblabBot bot) { 37 | _bot = bot; 38 | } 39 | 40 | 41 | /** 42 | * Processes a DCC request. 43 | * 44 | * @return True if the type of request was handled successfully. 45 | */ 46 | boolean processRequest(String nick, String login, String hostname, String request) { 47 | StringTokenizer tokenizer = new StringTokenizer(request); 48 | tokenizer.nextToken(); 49 | String type = tokenizer.nextToken(); 50 | String filename = tokenizer.nextToken(); 51 | 52 | if (type.equals("SEND")) { 53 | long address = Long.parseLong(tokenizer.nextToken()); 54 | int port = Integer.parseInt(tokenizer.nextToken()); 55 | long size = -1; 56 | try { 57 | size = Long.parseLong(tokenizer.nextToken()); 58 | } 59 | catch (Exception e) { 60 | // Stick with the old value. 61 | } 62 | 63 | DccFileTransfer transfer = new DccFileTransfer(_bot, this, nick, login, hostname, type, filename, address, port, size); 64 | _bot.onIncomingFileTransfer(transfer); 65 | 66 | } 67 | else if (type.equals("RESUME")) { 68 | int port = Integer.parseInt(tokenizer.nextToken()); 69 | long progress = Long.parseLong(tokenizer.nextToken()); 70 | 71 | DccFileTransfer transfer = null; 72 | synchronized (_awaitingResume) { 73 | for (int i = 0; i < _awaitingResume.size(); i++) { 74 | transfer = (DccFileTransfer) _awaitingResume.elementAt(i); 75 | if (transfer.getNick().equals(nick) && transfer.getPort() == port) { 76 | _awaitingResume.removeElementAt(i); 77 | break; 78 | } 79 | } 80 | } 81 | 82 | if (transfer != null) { 83 | transfer.setProgress(progress); 84 | _bot.sendCTCPCommand(nick, "DCC ACCEPT file.ext " + port + " " + progress); 85 | } 86 | 87 | } 88 | else if (type.equals("ACCEPT")) { 89 | int port = Integer.parseInt(tokenizer.nextToken()); 90 | long progress = Long.parseLong(tokenizer.nextToken()); 91 | 92 | DccFileTransfer transfer = null; 93 | synchronized (_awaitingResume) { 94 | for (int i = 0; i < _awaitingResume.size(); i++) { 95 | transfer = (DccFileTransfer) _awaitingResume.elementAt(i); 96 | if (transfer.getNick().equals(nick) && transfer.getPort() == port) { 97 | _awaitingResume.removeElementAt(i); 98 | break; 99 | } 100 | } 101 | } 102 | 103 | if (transfer != null) { 104 | transfer.doReceive(transfer.getFile(), true); 105 | } 106 | 107 | } 108 | else if (type.equals("CHAT")) { 109 | long address = Long.parseLong(tokenizer.nextToken()); 110 | int port = Integer.parseInt(tokenizer.nextToken()); 111 | 112 | final DccChat chat = new DccChat(_bot, nick, login, hostname, address, port); 113 | 114 | new Thread() { 115 | public void run() { 116 | _bot.onIncomingChatRequest(chat); 117 | } 118 | }.start(); 119 | } 120 | else { 121 | return false; 122 | } 123 | 124 | return true; 125 | } 126 | 127 | 128 | /** 129 | * Add this DccFileTransfer to the list of those awaiting possible 130 | * resuming. 131 | * 132 | * @param transfer the DccFileTransfer that may be resumed. 133 | */ 134 | void addAwaitingResume(DccFileTransfer transfer) { 135 | synchronized (_awaitingResume) { 136 | _awaitingResume.addElement(transfer); 137 | } 138 | } 139 | 140 | 141 | /** 142 | * Remove this transfer from the list of those awaiting resuming. 143 | */ 144 | void removeAwaitingResume(DccFileTransfer transfer) { 145 | _awaitingResume.removeElement(transfer); 146 | } 147 | 148 | 149 | private UblabBot _bot; 150 | private Vector _awaitingResume = new Vector(); 151 | 152 | } 153 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/IdentServer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | import java.net.*; 23 | import java.io.*; 24 | 25 | /** 26 | * A simple IdentServer (also know as "The Identification Protocol"). 27 | * An ident server provides a means to determine the identity of a 28 | * user of a particular TCP connection. 29 | *

30 | * Most IRC servers attempt to contact the ident server on connecting 31 | * hosts in order to determine the user's identity. A few IRC servers 32 | * will not allow you to connect unless this information is provided. 33 | *

34 | * So when a UblabBot is run on a machine that does not run an ident server, 35 | * it may be necessary to provide a "faked" response by starting up its 36 | * own ident server and sending out apparently correct responses. 37 | *

38 | * An instance of this class can be used to start up an ident server 39 | * only if it is possible to do so. Reasons for not being able to do 40 | * so are if there is already an ident server running on port 113, or 41 | * if you are running as an unprivileged user who is unable to create 42 | * a server socket on that port number. 43 | * 44 | */ 45 | public class IdentServer extends Thread { 46 | 47 | /** 48 | * Constructs and starts an instance of an IdentServer that will 49 | * respond to a client with the provided login. Rather than calling 50 | * this constructor explicitly from your code, it is recommended that 51 | * you use the startIdentServer method in the UblabBot class. 52 | *

53 | * The ident server will wait for up to 60 seconds before shutting 54 | * down. Otherwise, it will shut down as soon as it has responded 55 | * to an ident request. 56 | * 57 | * @param bot The UblabBot instance that will be used to log to. 58 | * @param login The login that the ident server will respond with. 59 | */ 60 | IdentServer(UblabBot bot, String login) { 61 | _bot = bot; 62 | _login = login; 63 | 64 | try { 65 | _ss = new ServerSocket(113); 66 | _ss.setSoTimeout(60000); 67 | } 68 | catch (Exception e) { 69 | _bot.log("*** Could not start the ident server on port 113."); 70 | return; 71 | } 72 | 73 | _bot.log("*** Ident server running on port 113 for the next 60 seconds..."); 74 | this.setName(this.getClass() + "-Thread"); 75 | this.start(); 76 | } 77 | 78 | 79 | /** 80 | * Waits for a client to connect to the ident server before making an 81 | * appropriate response. Note that this method is started by the class 82 | * constructor. 83 | */ 84 | public void run() { 85 | try { 86 | Socket socket = _ss.accept(); 87 | socket.setSoTimeout(60000); 88 | 89 | BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); 90 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); 91 | 92 | String line = reader.readLine(); 93 | if (line != null) { 94 | _bot.log("*** Ident request received: " + line); 95 | line = line + " : USERID : UNIX : " + _login; 96 | writer.write(line + "\r\n"); 97 | writer.flush(); 98 | _bot.log("*** Ident reply sent: " + line); 99 | writer.close(); 100 | } 101 | } 102 | catch (Exception e) { 103 | // We're not really concerned with what went wrong, are we? 104 | } 105 | 106 | try { 107 | _ss.close(); 108 | } 109 | catch (Exception e) { 110 | // Doesn't really matter... 111 | } 112 | 113 | _bot.log("*** The Ident server has been shut down."); 114 | } 115 | 116 | private UblabBot _bot; 117 | private String _login; 118 | private ServerSocket _ss = null; 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/InputThread.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | import java.io.*; 23 | import java.net.*; 24 | import java.util.*; 25 | 26 | /** 27 | * A Thread which reads lines from the IRC server. It then 28 | * passes these lines to the UblabBot without changing them. 29 | * This running Thread also detects disconnection from the server 30 | * and is thus used by the OutputThread to send lines to the server. 31 | * 32 | */ 33 | public class InputThread extends Thread { 34 | 35 | /** 36 | * The InputThread reads lines from the IRC server and allows the 37 | * UblabBot to handle them. 38 | * 39 | * @param bot An instance of the underlying UblabBot. 40 | * @param breader The BufferedReader that reads lines from the server. 41 | * @param bwriter The BufferedWriter that sends lines to the server. 42 | */ 43 | InputThread(UblabBot bot, Socket socket, BufferedReader breader, BufferedWriter bwriter) { 44 | _bot = bot; 45 | _socket = socket; 46 | _breader = breader; 47 | _bwriter = bwriter; 48 | this.setName(this.getClass() + "-Thread"); 49 | } 50 | 51 | 52 | /** 53 | * Sends a raw line to the IRC server as soon as possible, bypassing the 54 | * outgoing message queue. 55 | * 56 | * @param line The raw line to send to the IRC server. 57 | */ 58 | void sendRawLine(String line) { 59 | OutputThread.sendRawLine(_bot, _bwriter, line); 60 | } 61 | 62 | 63 | /** 64 | * Returns true if this InputThread is connected to an IRC server. 65 | * The result of this method should only act as a rough guide, 66 | * as the result may not be valid by the time you act upon it. 67 | * 68 | * @return True if still connected. 69 | */ 70 | boolean isConnected() { 71 | return _isConnected; 72 | } 73 | 74 | 75 | /** 76 | * Called to start this Thread reading lines from the IRC server. 77 | * When a line is read, this method calls the handleLine method 78 | * in the UblabBot, which may subsequently call an 'onXxx' method 79 | * in the UblabBot subclass. If any subclass of Throwable (i.e. 80 | * any Exception or Error) is thrown by your method, then this 81 | * method will print the stack trace to the standard output. It 82 | * is probable that the UblabBot may still be functioning normally 83 | * after such a problem, but the existance of any uncaught exceptions 84 | * in your code is something you should really fix. 85 | */ 86 | public void run() { 87 | try { 88 | boolean running = true; 89 | while (running) { 90 | try { 91 | String line = null; 92 | while ((line = _breader.readLine()) != null) { 93 | try { 94 | _bot.handleLine(line); 95 | } 96 | catch (Throwable t) { 97 | // Stick the whole stack trace into a String so we can output it nicely. 98 | StringWriter sw = new StringWriter(); 99 | PrintWriter pw = new PrintWriter(sw); 100 | t.printStackTrace(pw); 101 | pw.flush(); 102 | StringTokenizer tokenizer = new StringTokenizer(sw.toString(), "\r\n"); 103 | synchronized (_bot) { 104 | _bot.log("### Your implementation of UblabBot is faulty and you have"); 105 | _bot.log("### allowed an uncaught Exception or Error to propagate in your"); 106 | _bot.log("### code. It may be possible for UblabBot to continue operating"); 107 | _bot.log("### normally. Here is the stack trace that was produced: -"); 108 | _bot.log("### "); 109 | while (tokenizer.hasMoreTokens()) { 110 | _bot.log("### " + tokenizer.nextToken()); 111 | } 112 | } 113 | } 114 | } 115 | if (line == null) { 116 | // The server must have disconnected us. 117 | running = false; 118 | } 119 | } 120 | catch (InterruptedIOException iioe) { 121 | // This will happen if we haven't received anything from the server for a while. 122 | // So we shall send it a ping to check that we are still connected. 123 | this.sendRawLine("PING " + (System.currentTimeMillis() / 1000)); 124 | // Now we go back to listening for stuff from the server... 125 | } 126 | } 127 | } 128 | catch (Exception e) { 129 | // Do nothing. 130 | } 131 | 132 | // If we reach this point, then we must have disconnected. 133 | try { 134 | _socket.close(); 135 | } 136 | catch (Exception e) { 137 | // Just assume the socket was already closed. 138 | } 139 | 140 | if (!_disposed) { 141 | _bot.log("*** Disconnected."); 142 | _isConnected = false; 143 | _bot.onDisconnect(); 144 | } 145 | 146 | } 147 | 148 | 149 | /** 150 | * Closes the socket without onDisconnect being called subsequently. 151 | */ 152 | public void dispose () { 153 | try { 154 | _disposed = true; 155 | _socket.close(); 156 | } 157 | catch (Exception e) { 158 | // Do nothing. 159 | } 160 | } 161 | 162 | private UblabBot _bot = null; 163 | private Socket _socket = null; 164 | private BufferedReader _breader = null; 165 | private BufferedWriter _bwriter = null; 166 | private boolean _isConnected = true; 167 | private boolean _disposed = false; 168 | 169 | public static final int MAX_LINE_LENGTH = 512; 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/IrcException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | /** 23 | * An IrcException class. 24 | * 25 | */ 26 | public class IrcException extends Exception { 27 | 28 | /** 29 | * Constructs a new IrcException. 30 | * 31 | * @param e The error message to report. 32 | */ 33 | public IrcException(String e) { 34 | super(e); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/NickAlreadyInUseException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | /** 23 | * A NickAlreadyInUseException class. This exception is 24 | * thrown when the UblabBot attempts to join an IRC server 25 | * with a user name that is already in use. 26 | * 27 | */ 28 | public class NickAlreadyInUseException extends IrcException { 29 | 30 | /** 31 | * Constructs a new IrcException. 32 | * 33 | * @param e The error message to report. 34 | */ 35 | public NickAlreadyInUseException(String e) { 36 | super(e); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/OutputThread.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | import java.io.*; 23 | import java.net.*; 24 | 25 | /** 26 | * A Thread which is responsible for sending messages to the IRC server. 27 | * Messages are obtained from the outgoing message queue and sent 28 | * immediately if possible. If there is a flood of messages, then to 29 | * avoid getting kicked from a channel, we put a small delay between 30 | * each one. 31 | * 32 | */ 33 | public class OutputThread extends Thread { 34 | 35 | 36 | /** 37 | * Constructs an OutputThread for the underlying UblabBot. All messages 38 | * sent to the IRC server are sent by this OutputThread to avoid hammering 39 | * the server. Messages are sent immediately if possible. If there are 40 | * multiple messages queued, then there is a delay imposed. 41 | * 42 | * @param bot The underlying UblabBot instance. 43 | * @param outQueue The Queue from which we will obtain our messages. 44 | */ 45 | OutputThread(UblabBot bot, Queue outQueue) { 46 | _bot = bot; 47 | _outQueue = outQueue; 48 | this.setName(this.getClass() + "-Thread"); 49 | } 50 | 51 | 52 | /** 53 | * A static method to write a line to a BufferedOutputStream and then pass 54 | * the line to the log method of the supplied UblabBot instance. 55 | * 56 | * @param bot The underlying UblabBot instance. 57 | * @param out The BufferedOutputStream to write to. 58 | * @param line The line to be written. "\r\n" is appended to the end. 59 | * @param encoding The charset to use when encoing this string into a 60 | * byte array. 61 | */ 62 | static void sendRawLine(UblabBot bot, BufferedWriter bwriter, String line) { 63 | if (line.length() > bot.getMaxLineLength() - 2) { 64 | line = line.substring(0, bot.getMaxLineLength() - 2); 65 | } 66 | synchronized(bwriter) { 67 | try { 68 | bwriter.write(line + "\r\n"); 69 | bwriter.flush(); 70 | bot.log(">>>" + line); 71 | } 72 | catch (Exception e) { 73 | // Silent response - just lose the line. 74 | } 75 | } 76 | } 77 | 78 | 79 | /** 80 | * This method starts the Thread consuming from the outgoing message 81 | * Queue and sending lines to the server. 82 | */ 83 | public void run() { 84 | try { 85 | boolean running = true; 86 | while (running) { 87 | // Small delay to prevent spamming of the channel 88 | Thread.sleep(_bot.getMessageDelay()); 89 | 90 | String line = (String) _outQueue.next(); 91 | if (line != null) { 92 | _bot.sendRawLine(line); 93 | } 94 | else { 95 | running = false; 96 | } 97 | } 98 | } 99 | catch (InterruptedException e) { 100 | // Just let the method return naturally... 101 | } 102 | } 103 | 104 | private UblabBot _bot = null; 105 | private Queue _outQueue = null; 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/Queue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | import java.util.Vector; 23 | 24 | /** 25 | * Queue is a definition of a data structure that may 26 | * act as a queue - that is, data can be added to one end of the 27 | * queue and data can be requested from the head end of the queue. 28 | * This class is thread safe for multiple producers and a single 29 | * consumer. The next() method will block until there is data in 30 | * the queue. 31 | * 32 | * This has now been modified so that it is compatible with 33 | * the earlier JDK1.1 in order to be suitable for running on 34 | * mobile appliances. This means replacing the LinkedList with 35 | * a Vector, which is hardly ideal, but this Queue is typically 36 | * only polled every second before dispatching messages. 37 | * 38 | */ 39 | public class Queue { 40 | 41 | 42 | /** 43 | * Constructs a Queue object of unlimited size. 44 | */ 45 | public Queue() { 46 | 47 | } 48 | 49 | 50 | /** 51 | * Adds an Object to the end of the Queue. 52 | * 53 | * @param o The Object to be added to the Queue. 54 | */ 55 | public void add(Object o) { 56 | synchronized(_queue) { 57 | _queue.addElement(o); 58 | _queue.notify(); 59 | } 60 | } 61 | 62 | 63 | /** 64 | * Adds an Object to the front of the Queue. 65 | * 66 | * @param o The Object to be added to the Queue. 67 | */ 68 | public void addFront(Object o) { 69 | synchronized(_queue) { 70 | _queue.insertElementAt(o, 0); 71 | _queue.notify(); 72 | } 73 | } 74 | 75 | 76 | /** 77 | * Returns the Object at the front of the Queue. This 78 | * Object is then removed from the Queue. If the Queue 79 | * is empty, then this method shall block until there 80 | * is an Object in the Queue to return. 81 | * 82 | * @return The next item from the front of the queue. 83 | */ 84 | public Object next() { 85 | 86 | Object o = null; 87 | 88 | // Block if the Queue is empty. 89 | synchronized(_queue) { 90 | if (_queue.size() == 0) { 91 | try { 92 | _queue.wait(); 93 | } 94 | catch (InterruptedException e) { 95 | return null; 96 | } 97 | } 98 | 99 | // Return the Object. 100 | try { 101 | o = _queue.firstElement(); 102 | _queue.removeElementAt(0); 103 | } 104 | catch (ArrayIndexOutOfBoundsException e) { 105 | throw new InternalError("Race hazard in Queue object."); 106 | } 107 | } 108 | 109 | return o; 110 | } 111 | 112 | 113 | /** 114 | * Returns true if the Queue is not empty. If another 115 | * Thread empties the Queue before next() is 116 | * called, then the call to next() shall block 117 | * until the Queue has been populated again. 118 | * 119 | * @return True only if the Queue not empty. 120 | */ 121 | public boolean hasNext() { 122 | return (this.size() != 0); 123 | } 124 | 125 | 126 | /** 127 | * Clears the contents of the Queue. 128 | */ 129 | public void clear() { 130 | synchronized(_queue) { 131 | _queue.removeAllElements(); 132 | } 133 | } 134 | 135 | 136 | /** 137 | * Returns the size of the Queue. 138 | * 139 | * @return The current size of the queue. 140 | */ 141 | public int size() { 142 | return _queue.size(); 143 | } 144 | 145 | 146 | private Vector _queue = new Vector(); 147 | 148 | } 149 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/ReplyConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | 23 | /** 24 | * This interface contains the values of all numeric replies specified 25 | * in section 6 of RFC 1459. Refer to RFC 1459 for further information. 26 | *

27 | * If you override the onServerResponse method in the UblabBot class, 28 | * you may find these constants useful when comparing the numeric 29 | * value of a given code. 30 | * 31 | */ 32 | public interface ReplyConstants { 33 | 34 | 35 | // Error Replies. 36 | public static final int ERR_NOSUCHNICK = 401; 37 | public static final int ERR_NOSUCHSERVER = 402; 38 | public static final int ERR_NOSUCHCHANNEL = 403; 39 | public static final int ERR_CANNOTSENDTOCHAN = 404; 40 | public static final int ERR_TOOMANYCHANNELS = 405; 41 | public static final int ERR_WASNOSUCHNICK = 406; 42 | public static final int ERR_TOOMANYTARGETS = 407; 43 | public static final int ERR_NOORIGIN = 409; 44 | public static final int ERR_NORECIPIENT = 411; 45 | public static final int ERR_NOTEXTTOSEND = 412; 46 | public static final int ERR_NOTOPLEVEL = 413; 47 | public static final int ERR_WILDTOPLEVEL = 414; 48 | public static final int ERR_UNKNOWNCOMMAND = 421; 49 | public static final int ERR_NOMOTD = 422; 50 | public static final int ERR_NOADMININFO = 423; 51 | public static final int ERR_FILEERROR = 424; 52 | public static final int ERR_NONICKNAMEGIVEN = 431; 53 | public static final int ERR_ERRONEUSNICKNAME = 432; 54 | public static final int ERR_NICKNAMEINUSE = 433; 55 | public static final int ERR_NICKCOLLISION = 436; 56 | public static final int ERR_USERNOTINCHANNEL = 441; 57 | public static final int ERR_NOTONCHANNEL = 442; 58 | public static final int ERR_USERONCHANNEL = 443; 59 | public static final int ERR_NOLOGIN = 444; 60 | public static final int ERR_SUMMONDISABLED = 445; 61 | public static final int ERR_USERSDISABLED = 446; 62 | public static final int ERR_NOTREGISTERED = 451; 63 | public static final int ERR_NEEDMOREPARAMS = 461; 64 | public static final int ERR_ALREADYREGISTRED = 462; 65 | public static final int ERR_NOPERMFORHOST = 463; 66 | public static final int ERR_PASSWDMISMATCH = 464; 67 | public static final int ERR_YOUREBANNEDCREEP = 465; 68 | public static final int ERR_KEYSET = 467; 69 | public static final int ERR_CHANNELISFULL = 471; 70 | public static final int ERR_UNKNOWNMODE = 472; 71 | public static final int ERR_INVITEONLYCHAN = 473; 72 | public static final int ERR_BANNEDFROMCHAN = 474; 73 | public static final int ERR_BADCHANNELKEY = 475; 74 | public static final int ERR_NOPRIVILEGES = 481; 75 | public static final int ERR_CHANOPRIVSNEEDED = 482; 76 | public static final int ERR_CANTKILLSERVER = 483; 77 | public static final int ERR_NOOPERHOST = 491; 78 | public static final int ERR_UMODEUNKNOWNFLAG = 501; 79 | public static final int ERR_USERSDONTMATCH = 502; 80 | 81 | 82 | // Command Responses. 83 | public static final int RPL_TRACELINK = 200; 84 | public static final int RPL_TRACECONNECTING = 201; 85 | public static final int RPL_TRACEHANDSHAKE = 202; 86 | public static final int RPL_TRACEUNKNOWN = 203; 87 | public static final int RPL_TRACEOPERATOR = 204; 88 | public static final int RPL_TRACEUSER = 205; 89 | public static final int RPL_TRACESERVER = 206; 90 | public static final int RPL_TRACENEWTYPE = 208; 91 | public static final int RPL_STATSLINKINFO = 211; 92 | public static final int RPL_STATSCOMMANDS = 212; 93 | public static final int RPL_STATSCLINE = 213; 94 | public static final int RPL_STATSNLINE = 214; 95 | public static final int RPL_STATSILINE = 215; 96 | public static final int RPL_STATSKLINE = 216; 97 | public static final int RPL_STATSYLINE = 218; 98 | public static final int RPL_ENDOFSTATS = 219; 99 | public static final int RPL_UMODEIS = 221; 100 | public static final int RPL_STATSLLINE = 241; 101 | public static final int RPL_STATSUPTIME = 242; 102 | public static final int RPL_STATSOLINE = 243; 103 | public static final int RPL_STATSHLINE = 244; 104 | public static final int RPL_LUSERCLIENT = 251; 105 | public static final int RPL_LUSEROP = 252; 106 | public static final int RPL_LUSERUNKNOWN = 253; 107 | public static final int RPL_LUSERCHANNELS = 254; 108 | public static final int RPL_LUSERME = 255; 109 | public static final int RPL_ADMINME = 256; 110 | public static final int RPL_ADMINLOC1 = 257; 111 | public static final int RPL_ADMINLOC2 = 258; 112 | public static final int RPL_ADMINEMAIL = 259; 113 | public static final int RPL_TRACELOG = 261; 114 | public static final int RPL_NONE = 300; 115 | public static final int RPL_AWAY = 301; 116 | public static final int RPL_USERHOST = 302; 117 | public static final int RPL_ISON = 303; 118 | public static final int RPL_UNAWAY = 305; 119 | public static final int RPL_NOWAWAY = 306; 120 | public static final int RPL_WHOISUSER = 311; 121 | public static final int RPL_WHOISSERVER = 312; 122 | public static final int RPL_WHOISOPERATOR = 313; 123 | public static final int RPL_WHOWASUSER = 314; 124 | public static final int RPL_ENDOFWHO = 315; 125 | public static final int RPL_WHOISIDLE = 317; 126 | public static final int RPL_ENDOFWHOIS = 318; 127 | public static final int RPL_WHOISCHANNELS = 319; 128 | public static final int RPL_LISTSTART = 321; 129 | public static final int RPL_LIST = 322; 130 | public static final int RPL_LISTEND = 323; 131 | public static final int RPL_CHANNELMODEIS = 324; 132 | public static final int RPL_NOTOPIC = 331; 133 | public static final int RPL_TOPIC = 332; 134 | public static final int RPL_TOPICINFO = 333; 135 | public static final int RPL_INVITING = 341; 136 | public static final int RPL_SUMMONING = 342; 137 | public static final int RPL_VERSION = 351; 138 | public static final int RPL_WHOREPLY = 352; 139 | public static final int RPL_NAMREPLY = 353; 140 | public static final int RPL_LINKS = 364; 141 | public static final int RPL_ENDOFLINKS = 365; 142 | public static final int RPL_ENDOFNAMES = 366; 143 | public static final int RPL_BANLIST = 367; 144 | public static final int RPL_ENDOFBANLIST = 368; 145 | public static final int RPL_ENDOFWHOWAS = 369; 146 | public static final int RPL_INFO = 371; 147 | public static final int RPL_MOTD = 372; 148 | public static final int RPL_ENDOFINFO = 374; 149 | public static final int RPL_MOTDSTART = 375; 150 | public static final int RPL_ENDOFMOTD = 376; 151 | public static final int RPL_YOUREOPER = 381; 152 | public static final int RPL_REHASHING = 382; 153 | public static final int RPL_TIME = 391; 154 | public static final int RPL_USERSSTART = 392; 155 | public static final int RPL_USERS = 393; 156 | public static final int RPL_ENDOFUSERS = 394; 157 | public static final int RPL_NOUSERS = 395; 158 | 159 | 160 | // Reserved Numerics. 161 | public static final int RPL_TRACECLASS = 209; 162 | public static final int RPL_STATSQLINE = 217; 163 | public static final int RPL_SERVICEINFO = 231; 164 | public static final int RPL_ENDOFSERVICES = 232; 165 | public static final int RPL_SERVICE = 233; 166 | public static final int RPL_SERVLIST = 234; 167 | public static final int RPL_SERVLISTEND = 235; 168 | public static final int RPL_WHOISCHANOP = 316; 169 | public static final int RPL_KILLDONE = 361; 170 | public static final int RPL_CLOSING = 362; 171 | public static final int RPL_CLOSEEND = 363; 172 | public static final int RPL_INFOSTART = 373; 173 | public static final int RPL_MYPORTIS = 384; 174 | public static final int ERR_YOUWILLBEBANNED = 466; 175 | public static final int ERR_BADCHANMASK = 476; 176 | public static final int ERR_NOSERVICEHOST = 492; 177 | 178 | } 179 | -------------------------------------------------------------------------------- /src/main/java/org/ublab/bot/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | /** 23 | * This class is used to represent a user on an IRC server. 24 | * Instances of this class are returned by the getUsers method 25 | * in the UblabBot class. 26 | *

27 | * Note that this class no longer implements the Comparable interface 28 | * for Java 1.1 compatibility reasons. 29 | * 30 | */ 31 | public class User { 32 | 33 | 34 | /** 35 | * Constructs a User object with a known prefix and nick. 36 | * 37 | * @param prefix The status of the user, for example, "@". 38 | * @param nick The nick of the user. 39 | */ 40 | User(String prefix, String nick) { 41 | _prefix = prefix; 42 | _nick = nick; 43 | _lowerNick = nick.toLowerCase(); 44 | } 45 | 46 | 47 | /** 48 | * Returns the prefix of the user. If the User object has been obtained 49 | * from a list of users in a channel, then this will reflect the user's 50 | * status in that channel. 51 | * 52 | * @return The prefix of the user. If there is no prefix, then an empty 53 | * String is returned. 54 | */ 55 | public String getPrefix() { 56 | return _prefix; 57 | } 58 | 59 | 60 | /** 61 | * Returns whether or not the user represented by this object is an 62 | * operator. If the User object has been obtained from a list of users 63 | * in a channel, then this will reflect the user's operator status in 64 | * that channel. 65 | * 66 | * @return true if the user is an operator in the channel. 67 | */ 68 | public boolean isOp() { 69 | return _prefix.indexOf('@') >= 0; 70 | } 71 | 72 | 73 | /** 74 | * Returns whether or not the user represented by this object has 75 | * voice. If the User object has been obtained from a list of users 76 | * in a channel, then this will reflect the user's voice status in 77 | * that channel. 78 | * 79 | * @return true if the user has voice in the channel. 80 | */ 81 | public boolean hasVoice() { 82 | return _prefix.indexOf('+') >= 0; 83 | } 84 | 85 | 86 | /** 87 | * Returns the nick of the user. 88 | * 89 | * @return The user's nick. 90 | */ 91 | public String getNick() { 92 | return _nick; 93 | } 94 | 95 | 96 | /** 97 | * Returns the nick of the user complete with their prefix if they 98 | * have one, e.g. "@Dave". 99 | * 100 | * @return The user's prefix and nick. 101 | */ 102 | public String toString() { 103 | return this.getPrefix() + this.getNick(); 104 | } 105 | 106 | 107 | /** 108 | * Returns true if the nick represented by this User object is the same 109 | * as the argument. A case insensitive comparison is made. 110 | * 111 | * @return true if the nicks are identical (case insensitive). 112 | */ 113 | public boolean equals(String nick) { 114 | return nick.toLowerCase().equals(_lowerNick); 115 | } 116 | 117 | 118 | /** 119 | * Returns true if the nick represented by this User object is the same 120 | * as the nick of the User object given as an argument. 121 | * A case insensitive comparison is made. 122 | * 123 | * @return true if o is a User object with a matching lowercase nick. 124 | */ 125 | public boolean equals(Object o) { 126 | if (o instanceof User) { 127 | User other = (User) o; 128 | return other._lowerNick.equals(_lowerNick); 129 | } 130 | return false; 131 | } 132 | 133 | 134 | /** 135 | * Returns the hash code of this User object. 136 | * 137 | * @return the hash code of the User object. 138 | */ 139 | public int hashCode() { 140 | return _lowerNick.hashCode(); 141 | } 142 | 143 | 144 | /** 145 | * Returns the result of calling the compareTo method on lowercased 146 | * nicks. This is useful for sorting lists of User objects. 147 | * 148 | * @return the result of calling compareTo on lowercased nicks. 149 | */ 150 | public int compareTo(Object o) { 151 | if (o instanceof User) { 152 | User other = (User) o; 153 | return other._lowerNick.compareTo(_lowerNick); 154 | } 155 | return -1; 156 | } 157 | 158 | 159 | private String _prefix; 160 | private String _nick; 161 | private String _lowerNick; 162 | 163 | } 164 | -------------------------------------------------------------------------------- /src/test/java/org/ublab/bot/AppTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the ublab-bot 3 | * Copyright (C) 2015 Black Hackers(Elite Programmers Club, University of Buea) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | */ 20 | package org.ublab.bot; 21 | 22 | import junit.framework.Test; 23 | import junit.framework.TestCase; 24 | import junit.framework.TestSuite; 25 | /** 26 | * Unit test for simple App. 27 | */ 28 | public class AppTest 29 | extends TestCase 30 | { 31 | /** 32 | * Create the test case 33 | * 34 | * @param testName name of the test case 35 | */ 36 | public AppTest( String testName ) 37 | { 38 | super( testName ); 39 | } 40 | 41 | /** 42 | * @return the suite of tests being tested 43 | */ 44 | public static Test suite() 45 | { 46 | return new TestSuite( AppTest.class ); 47 | } 48 | 49 | /** 50 | * Rigourous Test :-) 51 | */ 52 | public void testApp() 53 | { 54 | assertTrue( true ); 55 | } 56 | } 57 | --------------------------------------------------------------------------------