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  
34  package com.levelonelabs.aimbot.modules;
35  
36  
37  import java.util.ArrayList;
38  import java.util.StringTokenizer;
39  
40  import com.levelonelabs.aim.AIMBuddy;
41  import com.levelonelabs.aimbot.AIMBot;
42  import com.levelonelabs.aimbot.BotModule;
43  
44  
45  /***
46   * Default module to give non AI responses to non-commands
47   *
48   * @author (matty501 AT yahoo.com)
49   */
50  public class DefaultModule extends BotModule {
51      private static ArrayList services;
52  
53      /***
54       * Initialize the service commands.
55       */
56      static {
57          //init the services
58          services=new ArrayList();
59          services.add("addTerm");
60      }
61  
62      /***
63       * Constructor for the Default module
64       *
65       * @param bot
66       */
67      public DefaultModule(AIMBot bot) {
68          super(bot);
69      }
70  
71      /***
72       * Gets the services
73       *
74       * @return The services
75       */
76      public ArrayList getServices() {
77          return services;
78      }
79  
80  
81      /***
82       * Gets the name of the module
83       *
84       * @return The name value
85       */
86      public String getName() {
87          return "Default Module";
88      }
89  
90  
91      /***
92       * Describes the usage of the module
93       *
94       * @return the usage of the module
95       */
96      public String help() {
97          StringBuffer sb=new StringBuffer();
98          sb.append("Default Module\nThis will output default text if the input \n");
99          sb.append("is not recognized\n");
100         sb.append("<B>addTerm <i>TEXT</i></B> "+
101             "(add possible lines for the module to output) *Admin only*");
102         return sb.toString();
103     }
104 
105 
106     /***
107      * Responds to an unknown command, or adds a term to respond with
108      *
109      * @param buddy requesting buddy
110      * @param query the message
111      */
112     public void performService(AIMBuddy buddy, String query) {
113         StringTokenizer st=new StringTokenizer(query);
114         String output="";
115 
116         //potential future function to add terms for the bot to reply with at random
117         if(query.toLowerCase().startsWith("addTerm")) {
118             if(!buddy.hasRole(AIMBot.ROLE_ADMINISTRATOR)) {
119                 super.sendMessage(buddy, "Sorry, only admins can add terms");
120                 return;
121             }
122             if(st.countTokens() < 2) {
123                 super.sendMessage(buddy, "ERROR:\n"+help());
124                 return;
125             }
126 
127             String imcommand=st.nextToken();
128             String term=st.nextToken();
129             while(st.hasMoreTokens()) {
130                 term=term+" "+st.nextToken();
131             }
132             super.sendMessage(buddy, "Sorry, this feature hasn't been implemented yet");
133             //addTerm(term);
134         } else {
135             output="Sorry, I don't understand that\n type \"help\" to see available commands";
136             super.sendMessage(buddy, output);
137         }
138     }
139 }