1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
21: class GuideController {
22:
23: 24: 25: 26:
27: public $moduleName;
28:
29:
30: public $text;
31:
32:
33: public $util;
34:
35:
36: public $commandAlias;
37:
38: private $path;
39: private $fileExt = ".txt";
40:
41: 42: 43: 44:
45: public function setup() {
46: $this->commandAlias->register($this->moduleName, "guides breed", "breed");
47: $this->commandAlias->register($this->moduleName, "guides healdelta", "healdelta");
48: $this->commandAlias->register($this->moduleName, "guides lag", "lag");
49: $this->commandAlias->register($this->moduleName, "guides nanodelta", "nanodelta");
50: $this->commandAlias->register($this->moduleName, "guides stats", "stats");
51: $this->commandAlias->register($this->moduleName, "aou 11", "title");
52: $this->commandAlias->register($this->moduleName, "guides doja", "doja");
53: $this->commandAlias->register($this->moduleName, "guides adminhelp", "adminhelp");
54: $this->commandAlias->register($this->moduleName, "guides light", "light");
55:
56: $this->path = getcwd() . "/modules/" . $this->moduleName . "/guides/";
57: }
58:
59: 60: 61: 62:
63: public function guidesListCommand($message, $channel, $sender, $sendto, $args) {
64: if ($handle = opendir($this->path)) {
65: $topicList = array();
66:
67:
68: while (false !== ($fileName = readdir($handle))) {
69:
70: if ($this->util->endsWith($fileName, $this->fileExt)) {
71: $topicList[] = str_replace($this->fileExt, '', $fileName);
72: }
73: }
74:
75: closedir($handle);
76:
77: sort($topicList);
78:
79: $linkContents = '';
80: forEach ($topicList as $topic) {
81: $linkContents .= $this->text->makeChatcmd($topic, "/tell <myname> guides $topic") . "\n";
82: }
83:
84: if ($linkContents) {
85: $msg = $this->text->makeBlob('Topics (' . count($topicList) . ')', $linkContents);
86: } else {
87: $msg = "No topics available.";
88: }
89: } else {
90: $msg = "Error reading topics.";
91: }
92: $sendto->reply($msg);
93: }
94:
95: 96: 97: 98:
99: public function guidesShowCommand($message, $channel, $sender, $sendto, $args) {
100:
101: $fileName = strtolower($args[1]);
102: $info = $this->getTopicContents($fileName);
103:
104: if (!$info) {
105: $msg = "No guide named <highlight>$fileName<end> was found.";
106: } else {
107: $msg = $this->text->makeLegacyBlob(ucfirst($fileName), $info);
108: }
109: $sendto->reply($msg);
110: }
111:
112: public function getTopicContents($fileName) {
113:
114: $file = $this->path . $fileName . $this->fileExt;
115: return file_get_contents($file);
116: }
117: }
118: