View Javadoc

1   /*------------------------------------------------------------------------------
2    * The contents of this file are subject to the Mozilla Public License Version
3    * 1.1 (the "License"); you may not use this file except in compliance with
4    * the License. You may obtain a copy of the License at
5    * http://www.mozilla.org/MPL/
6    * Software distributed under the License is distributed on an "AS IS" basis,
7    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
8    * the specific language governing rights and limitations under the License.
9    *
10   * The Original Code is levelonelabs.com code.
11   * The Initial Developer of the Original Code is Level One Labs. Portions
12   * created by the Initial Developer are Copyright (C) 2001 the Initial
13   * Developer. All Rights Reserved.
14   *
15   *         Contributor(s):
16   *             Scott Oster      (ostersc@alum.rpi.edu)
17   *             Steve Zingelwicz (sez@po.cwru.edu)
18   *             William Gorman   (willgorman@hotmail.com)
19   *
20   * Alternatively, the contents of this file may be used under the terms of
21   * either the GNU General Public License Version 2 or later (the "GPL"), or
22   * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
23   * in which case the provisions of the GPL or the LGPL are applicable
24   * instead of those above. If you wish to allow use of your version of this
25   * file only under the terms of either the GPL or the LGPL, and not to allow
26   * others to use your version of this file under the terms of the NPL, indicate
27   * your decision by deleting the provisions above and replace them with the
28   * notice and other provisions required by the GPL or the LGPL. If you do not
29   * delete the provisions above, a recipient may use your version of this file
30   * under the terms of any one of the NPL, the GPL or the LGPL.
31   *----------------------------------------------------------------------------*/
32  
33  package com.levelonelabs.aimbot;
34  
35  import java.util.ArrayList;
36  import java.util.Iterator;
37  import java.util.List;
38  
39  import com.levelonelabs.aim.AIMBuddy;
40  import com.levelonelabs.aim.AIMListener;
41  
42  
43  /***
44   * All Modules that wish to provide services to AIMBot should implement this.
45   * This base class acts as a facade to allow a extending module to be pretty
46   * much self-contained and just call methods here without needing to know about
47   * the AIMSender.
48   * 
49   * @author Scott Oster
50   * @created January 20, 2002
51   */
52  public abstract class BotModule {
53      /*** A handle to the hosting AIMBot */
54      protected AIMBot bot;
55  
56  
57      /***
58       * Constructor for the BotModule object
59       * 
60       * @param bot
61       *            A handle to the hosting AIMBot
62       */
63      public BotModule(AIMBot bot) {
64          this.bot = bot;
65      }
66  
67  
68      /***
69       * Gets the canonical name of the BotModule
70       * 
71       * @return The name of the module
72       */
73      public abstract String getName();
74  
75  
76      /***
77       * Convience method to call aimsender's getBuddy
78       * 
79       * @param name
80       * @return The buddy value
81       */
82      public AIMBuddy getBuddy(String name) {
83          return this.bot.aim.getBuddy(name);
84      }
85  
86  
87      /***
88       * Convience method to call aimsender's getBuddyIterator
89       * 
90       * @return iterator
91       */
92      public Iterator getBuddyNames() {
93          return this.bot.aim.getBuddyNames();
94      }
95  
96  
97      /***
98       * Must implement this to return a list of Strings that represent the
99       * keywords the module wants to be called for
100      * 
101      * @return all list of strings that are the keywords the module wants to
102      *         hear about
103      */
104     public abstract ArrayList getServices();
105 
106 
107     /***
108      * Convience method to call aimsender's addBuddy
109      * 
110      * @param buddy
111      *            The feature to be added to the Buddy attribute
112      */
113     public void addBuddy(AIMBuddy buddy) {
114         this.bot.aim.addBuddy(buddy);
115     }
116 
117 
118     /***
119      * Convience method to call aimsender's addBuddies
120      * 
121      * @param aimbuddies
122      *            List of AIMBuddys
123      */
124     public void addBuddies(List aimbuddies) {
125         this.bot.aim.addBuddies(aimbuddies);
126     }
127 
128 
129     /***
130      * Convience method to call aimsender's removeBuddy
131      * 
132      * @param buddy
133      *            remove the specified buddy
134      */
135     public void removeBuddy(AIMBuddy buddy) {
136         this.bot.aim.removeBuddy(buddy);
137     }
138 
139 
140     /***
141      * Convience method to call aimsender's removeBuddies
142      * 
143      * @param aimbuddies
144      *            List of AIMBuddys
145      */
146     public void removeBuddies(List aimbuddies) {
147         this.bot.aim.removeBuddies(aimbuddies);
148     }
149 
150 
151     /***
152      * Deny a buddy
153      * 
154      * @param buddy
155      */
156     public void denyBuddy(AIMBuddy buddy) {
157         this.bot.aim.denyBuddy(buddy);
158     }
159 
160 
161     /***
162      * Permit a buddy
163      * 
164      * @param buddy
165      */
166     public void permitBuddy(AIMBuddy buddy) {
167         this.bot.aim.permitBuddy(buddy);
168     }
169 
170 
171     /***
172      * Sets the permit mode on the server. (Use constants from AIMSender)
173      * 
174      * @param mode
175      */
176     public void setPermitMode(int mode) {
177         this.bot.aim.setPermitMode(mode);
178     }
179 
180 
181     /***
182      * Gets the permit mode that is set on the server.
183      * 
184      * @return int representation (see constants) of current permit mode.
185      */
186     public int getPermitMode() {
187         return this.bot.aim.getPermitMode();
188     }
189 
190 
191     /***
192      * Convenience method to call aimsender's sendMessage
193      * 
194      * @param buddy
195      *            buddy to message
196      * @param text
197      *            text to send buddy
198      */
199     public void sendMessage(AIMBuddy buddy, String text) {
200         this.bot.aim.sendMessage(buddy, text);
201     }
202 
203 
204     /***
205      * Convenience method to call aimsender's sendWarning
206      * 
207      * @param buddy
208      *            buddy to warn
209      */
210     public void sendWarning(AIMBuddy buddy) {
211         this.bot.aim.sendWarning(buddy);
212     }
213 
214 
215     /***
216      * Clear unvailable message
217      */
218     public void setAvailable() {
219         this.bot.aim.setAvailable();
220     }
221 
222 
223     /***
224      * Set unvailable message
225      * 
226      * @param reason
227      */
228     public void setUnavailable(String reason) {
229         this.bot.aim.setUnavailable(reason);
230     }
231 
232 
233     /***
234      * Convenience method to call aimsender's addAIMListener
235      * 
236      * @param listener
237      *            The listener
238      */
239     public void addAIMListener(AIMListener listener) {
240         this.bot.aim.addAIMListener(listener);
241     }
242 
243 
244     /***
245      * A String to be presented to a client that descibes the services
246      * (keywords) this module provides. NOTE: a URL to documentation is
247      * acceptable.
248      * 
249      * @return the help text
250      */
251     public abstract String help();
252 
253 
254     /***
255      * This will be called when the AIMBot gets a string starting with a keyword
256      * that this module advertised as a service.
257      * 
258      * @param buddy
259      * @param query
260      */
261     public abstract void performService(AIMBuddy buddy, String query);
262 }