Creating a 'voicemail' system using Pircbot

35 views Asked by At

I have the idea to create a bot where someone can leave a message for a user via "tell username: message" if the user is not online, and then when the user comes online, the bot sends the message.

This is my code so far:

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);
  }

But I'm stuck trying to figure out how to constantly check if a user is online and then send the message when they appear online. How would I go about doing this?

0

There are 0 answers