我有想法创建一个机器人,如果用户不在线,有人可以通过“告诉用户名:消息”为用户留言,然后当用户上线时,机器人会发送消息。
到目前为止,这是我的代码:
public HashMap<String, List<String>> tellUsers = new HashMap<String, List<String>>();
boolean userIsOnChannel = false;
if (messageIC.startsWith("!tell ")) {
String messagey = message.substring(6);
String[] messager = messagey.split(":");
String username = messager[0];
String messaged = messager[1];
User[] users = getUsers(channel);
for (final User user : getUsers(channel)) {
if (user.getNick().equalsIgnoreCase(username)) {
userIsOnChannel = true;
sendMessage(channel, username + " is online now!");
break;
}
else {
userIsOnChannel = false;
}
}
if (userIsOnChannel == false) {
tellUsery(username, messaged);
sendMessage(channel, "I'll pass that along.");
}
}
private void tellUsery(String username, String tell) {
List<String> tells = tellUsers.get(username);
if(tells == null) {
tells = new ArrayList<String>();
tellUsers.put(username, tells);
}
tells.add(tell);
}
但是我一直试图弄清楚如何不断检查用户是否在线,然后在网上出现时发送消息。我该怎么做呢?