// Channel commands
  public void onMessage(MessageEvent event) throws Exception {
    String message = event.getMessage();
    String[] seperated;
    if (event.getMessage().contains(" ")) seperated = event.getMessage().split(" ");
    else seperated = new String[] {event.getMessage()};

    // If it's a command, let's execute it!
    if (commandMap.containsKey(seperated[0])) {
      String commandString = seperated[0];
      Method method = commandMap.get(commandString);
      ChannelCommand command = method.getAnnotation(ChannelCommand.class);

      // Build args
      String[] args = buildArgs(seperated);

      // Execute command. (null represents object to invoke on, since method is static no object)
      // Check permissions
      if (hasPermission(command.permissionLevel(), event.getUser(), event.getChannel())) {
        if (args.length < command.minArgs()) {
          event.respond("Not enough arguements! Usage: " + command.usage());
        } else if (args.length > command.maxArgs()) {
          event.respond("Too many arguements! Usage: " + command.usage());
        } else {
          // Okay, everything's all good, lets run the command!
          method.invoke(null, event, args);
        }
      } else {
        event.respond("You do not have permission to execute this command!");
      }
    }
  }
 @Override
 public boolean execute(MessageEvent event) throws Exception {
   if (event.getUser() == null) {
     return false;
   }
   if (PermissionManager.hasExec(event.getUser().getNick())) {
     String[] args = event.getMessage().split(" ");
     if (args.length == 2 && args[1].length() == 1) {
       String oldtrigger = config.getTrigger();
       config.setTrigger(args[1]);
       if (config.useDatabase)
         Main.database
             .prepareStatement(
                 "UPDATE `Bot` SET `Bot_Trigger` = '"
                     + config.getTrigger()
                     + "' WHERE `Bot`.`Nick` = '"
                     + event.getBot().getUserBot().getNick()
                     + "';")
             .execute();
       MessageUtils.sendUserNotice(
           event, "Bot prefix was set to " + config.getTrigger() + " from " + oldtrigger);
       return true;
     } else {
       return false;
     }
   } else {
     event.respond("You need to be Exec to change prefix!");
   }
   return false;
 }
 public void onMessage(MessageEvent event) throws Exception {
   String messageString = event.getMessage();
   String user = event.getUser().getNick();
   Date time = new Date();
   switch (messageString.toLowerCase()) {
     case "!derp":
       event.respond("says derp");
       log.writeLog(user + " sent the \"derp\" command on " + time);
       break;
     case "!time":
       event.getBot().sendNotice(event.getUser(), "Current bot server time is: " + time);
       log.writeLog(user + " sent the \"time\" command on " + time);
       break;
     case "!owner":
       event.getBot().sendNotice(event.getUser(), "The Owner of this bot is MonsterTKE");
       log.writeLog(user + " sent the \"time\" command on " + time);
       break;
     case "!help": // This is the simple no argument help command...
       event
           .getBot()
           .sendNotice(
               event.getUser(),
               "Commands are !help, !derp, !time, !owner, !password and !twitter");
       event.getBot().sendNotice(event.getUser(), "Get further help with !help (command)");
       log.writeLog(user + " sent the \"help\" command on " + time);
       break;
     case "!twitter":
       event.getBot().sendNotice(event.getUser(), "somethin somethin");
       log.writeLog(user + " sent the \"twitter\" command on " + time);
       break;
     default:
       // ToDO
       break;
   }
 }
Exemple #4
0
 public void displayTrendingList(String[][] topWords, int count, MessageEvent<MyPircBotX> event) {
   String response = "Trending Words (24 Hours): ";
   // for (Entry<String, Integer> entry : topWords.entrySet()) {
   for (int i = 0; i < count; i++) {
     String block = (topWords[i][0] + ":" + topWords[i][1] + " ");
     response = response + block;
   }
   event.respond(response);
 }
Exemple #5
0
  public void onMessage(MessageEvent event) throws Exception {
    if (event.getMessage().split(" ").length > 1) {

      if (event.getMessage().equals(".join")) {
        event.respond("Please specify a channel to join.");
      }

      String channelarg = event.getMessage().split(" ")[1];
      if (event.getMessage().startsWith(".join ") && event.getMessage().contains(channelarg)) {

        String admin = "";
        for (int i = 0; i < Config.admins.length; i++) {
          admin += Config.admins[i];
        }

        if (admin.contains(event.getUser().getNick())) {
          CyBot.bot.sendRawLineNow("join" + " " + channelarg);

          event.respond("Attempted to join channel " + channelarg);
        }
      }
    }
  }