1
2
3
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 package com.levelonelabs.aimbot.modules;
35
36
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.Iterator;
40 import java.util.StringTokenizer;
41
42 import com.levelonelabs.aim.AIMBuddy;
43 import com.levelonelabs.aimbot.AIMBot;
44 import com.levelonelabs.aimbot.BotModule;
45
46
47 /***
48 * Handles requests to store and retrieve preferences
49 *
50 * @author Will Gorman
51 *
52 * @created January 31, 2002
53 */
54 public class PreferenceModule extends BotModule {
55 private static ArrayList services;
56
57 /***
58 * Initialize the service commands.
59 */
60 static {
61 services=new ArrayList();
62 services.add("listprefs");
63 services.add("setpref");
64 }
65
66 /***
67 * Constructor for the PreferenceModule object
68 *
69 * @param bot
70 */
71 public PreferenceModule(AIMBot bot) {
72 super(bot);
73 }
74
75 /***
76 * Gets the services attribute of the PreferenceModule object
77 *
78 * @return The services value
79 */
80 public ArrayList getServices() {
81 return services;
82 }
83
84
85 /***
86 * Gets the name attribute of the PreferenceModule object
87 *
88 * @return The name value
89 */
90 public String getName() {
91 return "Preference Module";
92 }
93
94
95 /***
96 * Describes the usage of the module
97 *
98 * @return the usage of the module
99 */
100 public String help() {
101 StringBuffer sb=new StringBuffer();
102 sb.append("<B>listprefs</B> (displays current preferences)\n");
103 sb.append("<B>setpref <i>PREFERENCE</i> <i>VALUE</i></B> (sets a preference for the user)\n");
104 sb.append("\n<b>EXAMPLE: setpref zipcode 12345</b>\n");
105 return sb.toString();
106 }
107
108
109 /***
110 * Handle a preference query
111 *
112 * @param buddy
113 * @param query
114 */
115 public void performService(AIMBuddy buddy, String query) {
116 if(query.toLowerCase().startsWith("listprefs")) {
117
118 HashMap prefs=buddy.getPreferences();
119 Iterator iter=prefs.keySet().iterator();
120 StringBuffer sb=new StringBuffer();
121 sb.append("Preferences:\n");
122 while(iter.hasNext()) {
123 String key=(String) iter.next();
124 sb.append(key).append(" = ").append(prefs.get(key)).append("\n");
125 }
126 super.sendMessage(buddy, sb.toString());
127 } else if(query.toLowerCase().startsWith("setpref")) {
128
129 StringTokenizer st=new StringTokenizer(query, " ");
130 if(st.countTokens() < 3) {
131 super.sendMessage(buddy, "ERROR:\n"+help());
132 } else {
133 String imcommand=st.nextToken();
134 String preference=st.nextToken();
135 String value=st.nextToken();
136 while(st.hasMoreTokens()) {
137 value+=(" "+st.nextToken());
138 }
139 buddy.setPreference(preference, value);
140 super.sendMessage(buddy, "Preference ("+preference+" = "+value+") added.");
141 }
142 }
143 }
144 }