1: <?php
2:
3: namespace Budabot\Core\Modules;
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: class HelpController {
21:
22: 23: 24: 25:
26: public $moduleName;
27:
28:
29: public $commandManager;
30:
31:
32: public $commandAlias;
33:
34:
35: public $helpManager;
36:
37:
38: public $text;
39:
40: 41: 42: 43:
44: public function setup() {
45: $this->helpManager->register($this->moduleName, "about", "about.txt", "all", "Info about the development of Budabot");
46:
47: $this->commandAlias->register($this->moduleName, "help about", "about");
48: }
49:
50: public function getAbout() {
51: global $version;
52: $data = file_get_contents("./core/HELP/about.txt");
53: $data = str_replace('<version>', $version, $data);
54: return $this->text->makeBlob("About Budabot $version", $data);
55: }
56:
57: 58: 59: 60:
61: public function helpListCommand($message, $channel, $sender, $sendto) {
62: global $version;
63:
64: $data = $this->helpManager->getAllHelpTopics($sender);
65:
66: if (count($data) == 0) {
67: $msg = "No help files found.";
68: } else {
69: $blob = '';
70: $current_module = '';
71: forEach ($data as $row) {
72: if ($current_module != $row->module) {
73: $blob .= "\n<pagebreak><header2>{$row->module}:<end>\n";
74: $current_module = $row->module;
75: }
76: $helpLink = $this->text->makeChatcmd($row->name, "/tell <myname> help $row->name");
77: $blob .= " {$helpLink}: {$row->description}\n";
78: }
79:
80: $msg = $this->text->makeBlob("Help (main)", $blob);
81: }
82:
83: $sendto->reply($msg);
84: }
85:
86: 87: 88: 89:
90: public function helpShowCommand($message, $channel, $sender, $sendto, $args) {
91: $helpcmd = strtolower($args[1]);
92:
93: if ($helpcmd == 'about') {
94: $msg = $this->getAbout();
95: $sendto->reply($msg);
96: return;
97: }
98:
99:
100: $row = $this->commandAlias->get($helpcmd);
101: if ($row !== null && $row->status == 1) {
102: $arr = explode(' ', $row->cmd);
103: $helpcmd = $arr[0];
104: }
105:
106: $blob = $this->helpManager->find($helpcmd, $sender);
107: if ($blob !== false) {
108: $helpcmd = ucfirst($helpcmd);
109: $msg = $this->text->makeBlob("Help ($helpcmd)", $blob);
110: $sendto->reply($msg);
111: } else {
112: $sendto->reply("No help found on this topic.");
113: }
114: }
115: }
116: