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);
         }
     }
 }
 public function run()
 {
     Config::changeAllTimestampsToNow();
     DataManager::changeAllTimestampsToNow();
     $server = Server::getInstance();
     $server->notify($this->senderNick, "Database has reloaded all values from RAM");
 }
Ejemplo n.º 3
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");
         }
     }
 }
Ejemplo n.º 4
0
 public function run()
 {
     $channels = Config::getValue("channels");
     if (!in_array($this->parameters(1), $channels)) {
         $channels[] = $this->parameters(1);
     }
     Config::setValue("channels", $channels);
     $server = Server::getInstance();
     $server->join($this->parameters(1));
 }
Ejemplo n.º 5
0
 public function run()
 {
     $server = Server::getInstance();
     $userPasswords = Config::getValue("userPasswords");
     if (!$userPasswords) {
         $userPasswords = array();
     }
     $userPasswords[$this->senderNick] = md5($this->parameters(1));
     Config::setValue("userPasswords", $userPasswords);
     $server->notify($this->senderNick, "Password for " . $this->senderNick . " set to " . $this->parameters(1));
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
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;
     }
 }
Ejemplo n.º 8
0
 public function run()
 {
     if ($this->parameters(1)) {
         $channel = $this->parameters(1);
     } else {
         $channel = $this->channel;
     }
     $channels = Config::getValue("channels");
     foreach ($channels as $offset => $value) {
         if ($value == $channel) {
             unset($channels[$offset]);
         }
     }
     Config::setValue("channels", $channels);
     $server = Server::getInstance();
     $server->part($channel);
 }
Ejemplo n.º 9
0
 public function run()
 {
     $action = $this->parameters(1);
     $server = Server::getInstance();
     switch ($action) {
         case "set":
             Config::setValue($this->parameters(2), $this->parameters(3, true));
             $server->notify($this->senderNick, "Config key '" . $this->parameters(2) . "' set to '" . $this->parameters(3, true) . "'");
             break;
         case "get":
             $value = Config::getValue($this->parameters(2));
             if (!$value) {
                 $server->notify($this->senderNick, "Config key '" . $this->parameters(2) . "' is not set");
             }
             $server->notify($this->senderNick, $this->parameters(2) . " => " . $value);
             break;
     }
 }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 12
0
 /**
  * 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;
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * Updates the database with data from the script
  * arrays
  */
 public function updateDatabase()
 {
     // Channels
     $this->query("DELETE FROM channel_users");
     $this->query("DELETE FROM channels");
     foreach (ChannelManager::$connectedChannels as $channel) {
         $stmt = $this->pdo->prepare("INSERT INTO channels(name, topic) VALUES(?,?);");
         $stmt->execute(array($channel->channelName, $channel->topic));
         foreach ($channel->connectedNicks as $connectedNick) {
             if (isset($channel->privilegedNicks[$connectedNick])) {
                 $stmt = $this->pdo->prepare("INSERT INTO channel_users(nickname, channel_name, privilege) VALUES(?,?,?);");
                 $stmt->execute(array($connectedNick, $channel->channelName, $channel->privilegedNicks[$connectedNick]));
             } else {
                 $stmt = $this->pdo->prepare("INSERT INTO channel_users(nickname, channel_name) VALUES(?,?);");
                 $stmt->execute(array($connectedNick, $channel->channelName));
             }
         }
     }
     // Users
     $this->query("DELETE FROM users");
     foreach (UserManager::$trackedUsers as $user) {
         if ($user->nickname && $user->ident && $user->host && $user->realName) {
             $stmt = $this->prepare("INSERT INTO users(nickname, ident, host, real_name) VALUES(?,?,?,?);");
             $stmt->execute(array($user->nickname, $user->ident, $user->host, $user->realName));
         } else {
             if ($user->nickname && $user->ident && $user->host) {
                 $stmt = $this->prepare("INSERT INTO users(nickname, ident, host) VALUES(?,?,?);");
                 $stmt->execute(array($user->nickname, $user->ident, $user->host));
             } else {
                 if ($user->nickname) {
                     $stmt = $this->prepare("INSERT INTO users(nickname) VALUES(?);");
                     $stmt->execute(array($user->nickname));
                 }
             }
         }
     }
     // Module data
     // check if we need to update anything currently in the db
     $stmt = $this->prepare("SELECT * FROM module_data");
     $stmt->execute();
     $doneTitles = array();
     while ($row = $stmt->fetchObject()) {
         if (DataManager::checkIfDataExistsAndIsNewerThan($row->title, $row->module, $row->last_updated_time)) {
             $data = DataManager::retrieve($row->title, $row->module);
             $dbData = serialize($data);
             $time = DataManager::getLastUpdatedTime($row->title, $row->module);
             $stmt = $this->prepare("DELETE FROM module_data WHERE title=?;");
             $stmt->execute(array($row->title));
             $stmt = $this->prepare("INSERT INTO module_data(title, data, module, last_updated_time) VALUES(?,?,?,?);");
             $stmt->execute(array($row->title, $dbData, $row->module, $time));
         }
         $doneTitles[$row->title] = true;
     }
     // do everything else
     $allModules = DataManager::getAllData();
     foreach ($allModules as $module => $titles) {
         foreach ($titles as $title => $types) {
             if ($doneTitles[$title]) {
                 continue;
             }
             $dbData = serialize($types["data"]);
             $stmt = $this->prepare("DELETE FROM module_data WHERE title=?;");
             $stmt->execute(array($title));
             $stmt = $this->prepare("INSERT INTO module_data(title, data, module, last_updated_time) VALUES(?,?,?,?);");
             $stmt->execute(array($title, $dbData, $module, $types["lastUpdated"]));
         }
     }
     // Config
     // check if we need to update anything currently in the db
     $stmt = $this->prepare("SELECT * FROM config");
     $stmt->execute();
     $doneKeys = array();
     while ($row = $stmt->fetchObject()) {
         if (Config::checkIfValueExistsAndIsNewerThan($row->name, $row->last_updated_time)) {
             $data = Config::getValue($row->name);
             $dbData = serialize($data);
             $time = Config::getLastUpdatedTime($row->name);
             $stmt = $this->prepare("DELETE FROM config WHERE name=?;");
             $stmt->execute(array($row->name));
             $stmt = $this->prepare("INSERT INTO config(name, data, last_updated_time) VALUES(?,?,?);");
             $stmt->execute(array($row->name, $dbData, $time));
         }
         $doneKeys[$row->name] = true;
     }
     // do everything else
     $allKeys = Config::getAllValues();
     foreach ($allKeys as $name => $types) {
         if ($doneKeys[$name]) {
             continue;
         }
         $dbData = serialize($types["data"]);
         $stmt = $this->prepare("DELETE FROM config WHERE name=?;");
         $stmt->execute(array($name));
         $stmt = $this->prepare("INSERT INTO config (name, data, last_updated_time) VALUES (?,?,?);");
         $stmt->execute(array($name, $dbData, $types["lastUpdated"]));
     }
 }
Ejemplo n.º 14
0
while (true) {
    // Connect
    $server->connect();
    // Identify
    $server->identify();
    // If we send anything else too soon after identification it could be
    // lost, so sleep for 2 seconds
    sleep(2);
    // NickServ
    if (Config::getValue("nickservPassword")) {
        $server->identifyWithNickServ();
    }
    // Connect commands
    ModuleManager::runConnectCommands();
    // Loop through the channels in the config and join them
    $channels = Config::getValue("channels");
    foreach ($channels as $channel) {
        $server->join($channel);
    }
    // Loop-edy-loop
    while ($server->connected()) {
        $line = $server->getNextLine();
        $line = new ReceivedLine($line);
        $line->parse();
        if ($line->isMappedCommand()) {
            $command = new Command($line);
            $command->execute();
        }
        if ($line->isMappedEvent()) {
            $event = new Event($line);
            $event->execute();
Ejemplo n.º 15
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()));
     }
 }
Ejemplo n.º 16
0
 /**
  * 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;
 }