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 package com.levelonelabs.aim.example;
34
35 import java.util.ArrayList;
36 import java.util.Date;
37
38 import com.levelonelabs.aim.AIMAdapter;
39 import com.levelonelabs.aim.AIMBuddy;
40 import com.levelonelabs.aim.AIMClient;
41 import com.levelonelabs.aim.AIMSender;
42
43
44 /***
45 * Forward messages from one screename to anonther.
46 *
47 * @author Scott Oster
48 *
49 * @created July 23, 2002
50 */
51 public class AIMReceptionist {
52 /***
53 * The main program starts up a aimclient and signs it on. Then registers a
54 * listener that gets called when someone messages the bot. It simply
55 * responds and forwards the message on.
56 *
57 * @param args
58 * username password newusername
59 */
60 public static void main(String[] args) {
61 if (args.length != 3) {
62 System.err.println("USAGE: username password newusername");
63 System.exit(-1);
64 }
65
66 final String username = args[0];
67 final String pass = args[1];
68 final AIMBuddy newName = new AIMBuddy(args[2].toLowerCase());
69
70
71
72 final AIMSender aim = new AIMClient(username, pass, "AIM Receiptionist", true);
73 aim.addBuddy(newName);
74 aim.addAIMListener(new AIMAdapter() {
75
76 public void handleMessage(AIMBuddy buddy, String request) {
77 aim.sendMessage(buddy, "Sorry " + buddy.getName() + ", " + username
78 + " doesn't use this name anymore, but I'll forward the message.");
79 if (newName.isOnline()) {
80 aim.sendMessage(newName, buddy.getName() + " said: " + request);
81 } else {
82 newName.addMessage(buddy.getName() + " said \"" + request + "\" at " + new Date());
83 }
84 }
85
86
87
88 public void handleBuddySignOn(AIMBuddy buddy, String info) {
89 if (buddy.getName().equalsIgnoreCase(newName.getName()) && buddy.hasMessages()) {
90 ArrayList messages = buddy.getMessages();
91 String message = "";
92
93
94 for (int i = 0; i < messages.size(); i++) {
95 message += (messages.get(i) + "<BR>");
96 }
97
98
99 aim.sendMessage(buddy, message);
100 buddy.clearMessages();
101 }
102 }
103 });
104
105 aim.signOn();
106 }
107 }