Skip to content

Commit

Permalink
adding event for server status
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Nov 17, 2012
1 parent b1e6924 commit 5b1b05d
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Core/ServerStatus/Lib/ServerStatusEvents.php
Expand Up @@ -24,5 +24,41 @@ public function onSetupRoutes(Event $Event) {
)
);
}

/**
* Return the server status for IRC bots
*
* @param Event $Event The event being run
* @param array $data the message data being parsed
*
* @return boolean
*/
public function onIrcMessage(Event $Event, $data = null) {
if($data['command'] != 'server') {
return;
}

$memoryUsage = memoryUsage(false);
$memoryUsage['load'] = implode(' ', serverLoad(false));
$data['message'] = explode(' ', $data['message'], 2);

$message = ':to: Memory: :current Load: :load';
if($data['args']) {
$message = ':to: Invalid option, try: !server [current|max|load]';
if($data['args'] == 'help') {
$message = ':to: !server [current|max|load]';
}
if(array_key_exists($data['args'], $memoryUsage)) {
$message = ':to: :' . $data['args'];
}
}

$Event->Handler->reply($data['channel'], $message, array_merge(
array('to' => $data['to']),
$memoryUsage
));

return true;
}

}
}

0 comments on commit 5b1b05d

Please sign in to comment.