public function run()
 {
     if ($this->eventType == ReceivedLineTypes::SERVERREPLYTHREEONEONE) {
         $workingLine = explode(" ", $this->runMessage, 8);
         $nick = $workingLine[3];
         $ident = $workingLine[4];
         $host = $workingLine[5];
         $realName = str_replace(":", "", $workingLine[7]);
         $realName = trim($realName);
         $user = new User();
         $user->nickname = $nick;
         $user->ident = $ident;
         $user->host = $host;
         $user->realName = $realName;
         UserManager::store($nick, $user);
     } else {
         if ($this->eventType == ReceivedLineTypes::SERVERREPLYTHREETHREEZERO || $this->eventType == ReceivedLineTypes::SERVERREPLYTHREEZEROSEVEN) {
             $workingLine = explode(" ", $this->runMessage);
             $nick = $workingLine[3];
             $user = UserManager::get($nick);
             $user->isIdentified = true;
             UserManager::store($nick, $user);
             $configUsers = Config::getRequiredValue("users");
             if ($configUsers[$nick]) {
                 $permissionLevel = $configUsers[$nick];
             } else {
                 $permissionLevel = 0;
             }
             $server = Server::getInstance();
             $server->notify($nick, "You have been successfully authorized via NickServ with the permission level " . $permissionLevel);
         }
     }
 }
Example #2
0
 /**
  * Execute the command through ModuleManager
  */
 public function execute()
 {
     $return = ModuleManager::runCommand($this->command, $this->fullMessage, $this->senderNick, $this->channel);
     if ($return !== true) {
         if ($return == 2) {
             $server = Server::getInstance();
             $server->notify($this->senderNick, "You do not have permission to use this command. Please identify via NickServ if you have privileges, then type " . Config::getRequiredValue("commandCharacter") . "identify");
         }
     }
 }
Example #3
0
 /**
  * Adds tracking for an online nick and stores
  * the given user object for them, if their nick is on the
  * privileged config list it also sends a WHOIS
  *
  * @param string online nickname
  * @param object User object
  */
 public static function store($nick, $userObject)
 {
     $configUsers = Config::getRequiredValue("users");
     foreach ($configUsers as $privilegedUser => $level) {
         if ($nick == $privilegedUser) {
             if (!static::$trackedUsers[$nick]) {
                 $server = Server::getInstance();
                 $server->whois($nick);
             }
         }
     }
     static::$trackedUsers[$nick] = $userObject;
 }
Example #4
0
 /**
  * Logs an 'error'
  * 
  * @param int bit error type, see the ErrorCategories constant class
  * @param string message
  */
 public static function log($type, $message)
 {
     $error = new Error($type, $message);
     if ((Config::getRequiredValue("verboseOutput") & $error->type) === $error->type) {
         echo "[" . date("d/m/y H:i:s", $error->epoch) . "] " . $error->message . "\n";
         if (!static::$fileHandle) {
             static::$fileHandle = fopen(__DIR__ . "/../../../logs/run-" . date("d-m-y") . ".log", "a");
         }
         fwrite(static::$fileHandle, "[" . date("d/m/y H:i:s", $error->epoch) . "] " . $error->message . "\n");
     }
     if ($error->type == ErrorCategories::FATAL) {
         echo "DYING " . $error->message;
         echo "\n";
         die;
         exit;
     }
 }
Example #5
0
 public function run()
 {
     $command = $this->parameters(1);
     if ($command) {
         $subcommand = $this->parameters(2);
         if ($subcommand != "") {
             $description = HelpManager::getDescription($command, $subcommand);
             $parameters = HelpManager::getParameters($command, $subcommand);
             $subcommandsString = false;
         } else {
             $description = HelpManager::getDescription($command);
             $parameters = HelpManager::getParameters($command);
             $subcommands = HelpManager::getSubcommands($command);
             foreach ($subcommands as $id => $subcommandOfCommand) {
                 if ($subcommandOfCommand != "BASE") {
                     $subcommandsString .= " " . $subcommandOfCommand;
                 }
             }
         }
         $server = Server::getInstance();
         $server->notify($this->senderNick, "************************************");
         $server->notify($this->senderNick, "Help for " . Config::getRequiredValue("commandCharacter") . $command . " " . $subcommand);
         $server->notify($this->senderNick, " ");
         $server->notify($this->senderNick, $description);
         $server->notify($this->senderNick, chr(2) . "Syntax: " . chr(2) . Config::getRequiredValue("commandCharacter") . $command . " " . $subcommand . " " . $parameters);
         if ($subcommandsString) {
             $server->notify($this->senderNick, chr(2) . "Subcommands:" . chr(2) . $subcommandsString);
         }
         $server->notify($this->senderNick, "************************************");
     } else {
         $commands = HelpManager::getCommandList();
         foreach ($commands as $id => $commandFromList) {
             $commandsString .= " " . $commandFromList;
         }
         $server = Server::getInstance();
         $server->notify($this->senderNick, "************************************");
         $server->notify($this->senderNick, "Welcome to AwesomeIRCBot Help");
         $server->notify($this->senderNick, "");
         $server->notify($this->senderNick, chr(2) . "Commands: " . chr(2) . $commandsString);
         $server->notify($this->senderNick, chr(2) . "Getting help with commands: " . chr(2) . Config::getRequiredValue("commandCharacter") . "help <command to get help for>");
         $server->notify($this->senderNick, "************************************");
     }
 }
 public function run()
 {
     $action = $this->parameters(1);
     $user = $this->parameters(2);
     $level = $this->parameters(3);
     $server = Server::getInstance();
     switch ($action) {
         case "add":
             $configUsers = Config::getRequiredValue("users");
             $configUsers[$user] = $level;
             Config::setValue("users", $configUsers);
             $server->notify($this->senderNick, $user . " added to privileged users list at level " . $level);
             break;
         case "del":
             $configUsers = Config::getRequiredValue("users");
             unset($configUsers[$user]);
             Config::setValue("users", $configUsers);
             $server->notify($this->senderNick, $user . " removed from privileged users list");
             break;
     }
     $server->whois($user);
 }
 /**
  * Runs the module associated with a trigger
  *
  * @param string full message the user sent
  * @param string nickname of the user who sent the command
  * @param string channel the message was sent on
  */
 public static function runTrigger($message, $senderNick, $channel)
 {
     foreach (static::$mappedTriggers as $regexString => $module) {
         if (preg_match($regexString, $message)) {
             if ($module::$requiredUserLevel) {
                 $user = UserManager::get($senderNick);
                 if (!$user->isIdentified) {
                     return 2;
                 } else {
                     $configUsers = Config::getRequiredValue("users");
                     if ($module::$requiredUserLevel > $configUsers[$senderNick]) {
                         return 2;
                     }
                 }
             }
             if (strpos("#", $channel) !== false) {
                 if ($module::$requiredChannelPrivilege) {
                     $channel = ChannelManager::get($channel);
                     if (!$channel->hasPrivilegeOrHigher($senderNick)) {
                         return 2;
                     }
                 }
             }
             $moduleInstance = new $module($message, $senderNick, $channel);
             $moduleInstance->run();
             return true;
         }
     }
 }
Example #8
0
 /**
  * Act, (/me) a message, same syntax as the message()
  * method
  */
 public function act($target, $message)
 {
     // Send it
     ErrorLog::log(ErrorCategories::DEBUG, "Messaging '" . $target . "' with message '" . $message . "' formatted as an ACTION (/me)");
     fwrite(static::$serverHandle, "PRIVMSG " . $target . " :" . chr(1) . "ACTION " . $message . chr(1) . "\n");
     // Log it (if chan)
     if (strpos($target, "#") !== false) {
         $db = Database::getInstance();
         $stmt = $db->prepare("INSERT INTO channel_actions (type, nickname, ident, channel_name, message, time) VALUES (?,?,?,?,?,?)");
         $stmt->execute(array(ReceivedLineTypes::CHANMSG, Config::getRequiredValue("nickname"), Config::getRequiredValue("username"), $target, "ACTION " . $message, time()));
     }
 }
 /**
  * Extracts the command from the line if
  * there is one
  *
  * @return string command
  */
 public function getCommand()
 {
     $splitMessage = explode(" ", $this->message);
     $command = str_replace(Config::getRequiredValue("commandCharacter"), "", $splitMessage[0]);
     return $command;
 }