Assembla home | Assembla project page
 

root/trunk/Phergie/Plugin/Debug.php

Revision 217, 2.8 kB (checked in by Slynderdale, 8 months ago)

Some final clean up.

Line 
1 <?php
2
3 /**
4  * Provides commands relevant for debugging and profiling, such as measurement
5  * of memory consumption.
6  */
7 class Phergie_Plugin_Debug extends Phergie_Plugin_Abstract_Command
8 {
9     /**
10      * Flag indicating whether or not the plugin is an admin plugin or not
11      *
12      * @var bool
13      */
14     public $needsAdmin = true;
15
16     /**
17      * Responds to requests for statistics related to the bot's memory
18      * consumption.
19      *
20      * @return void
21      */
22     public function onDoMem()
23     {
24         if (function_exists('memory_get_usage')) {
25             $target = $this->event->getNick();
26             $text = 'Current : '.number_format(memory_get_usage() / 1024).'KB' .
27                     (function_exists('memory_get_peak_usage') ? ' / Peak : '.number_format(memory_get_peak_usage() / 1024).'KB' : '');
28             $this->doPrivmsg($this->event->getSource(), $target . ': ' . $text);
29         }
30     }
31
32     /**
33      * Returns the amount of time the bot has been up.
34      *
35      * @return void
36      */
37     public function onDoUptime()
38     {
39         $target = $this->event->getNick();
40
41         $this->doPrivmsg($this->event->getSource(), $target . ': Uptime: ' . $this->getCountdown(time() -$this->getStartTime()));
42     }
43
44     /**
45      * Returns a list of all the loaded extensions
46      *
47      * @return void
48      */
49     public function onDoExtensions()
50     {
51         $target = $this->event->getNick();
52
53         $extensions = get_loaded_extensions();
54         if (is_array($extensions)) {
55             $extensions = array_map('ucfirst', $extensions);
56             sort($extensions);
57         }
58         $this->doPrivmsg($this->event->getSource(), $target . ': Loaded Extensions: ' . (is_array($extensions) ? implode(', ', $extensions) : 'N/A'));
59         unset($extensions);
60     }
61
62     /**
63      * Returns the version for PHP or a loaded extension
64      *
65      * @return void
66      */
67     public function onDoGetversion($prog = null)
68     {
69         $target = $this->event->getNick();
70
71         $prog = (isset($prog) ? trim(strtolower($prog)) : null);
72         $extensions = get_loaded_extensions();
73         if (is_array($extensions)) {
74             $extensions = array_map('strtolower', $extensions);
75         }
76
77         if (empty($prog)) {
78             $message = 'Phergie Version: ' . PHERGIE_VERSION;
79         } else if ($prog == 'php') {
80             $message = 'PHP Version: ' . phpversion();
81         } else if (is_array($extensions) && in_array($prog, $extensions)) {
82             $version = phpversion($prog);
83             $message = ucfirst($prog) . ' Version: ' . ($version ? $version : 'N/A');
84         } else {
85             $message = 'Unknown Extension: ' . ucfirst($prog);
86         }
87         $this->doPrivmsg($this->event->getSource(), $target . ': ' . $message);
88         unset($prog, $extensions, $version, $message);
89     }
90 }
91
Note: See TracBrowser for help on using the browser.