1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: use Budabot\Core\AutoInject;
6:
7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
21: class CacheController extends AutoInject {
22:
23: 24: 25: 26:
27: public $moduleName;
28:
29: 30: 31:
32: public function setup() {
33:
34: }
35:
36: 37: 38: 39:
40: public function cacheCommand($message, $channel, $sender, $sendto, $args) {
41: $blob = '';
42: forEach ($this->cacheManager->getGroups() as $group) {
43: $blob .= $this->text->makeChatcmd($group, "/tell <myname> cache browse $group") . "\n";
44: }
45: $msg = $this->text->makeBlob("Cache Groups", $blob);
46: $sendto->reply($msg);
47: }
48:
49: 50: 51: 52:
53: public function cacheBrowseCommand($message, $channel, $sender, $sendto, $args) {
54: $group = $args[1];
55:
56: $path = $this->chatBot->vars['cachefolder'] . $group;
57:
58: $blob = '';
59: forEach ($this->cacheManager->getFilesInGroup($group) as $file) {
60: $fileInfo = stat($path . "/" . $file);
61: $blob .= "<highlight>$file<end> " . $this->util->bytesConvert($fileInfo['size']) . " - Last modified " . $this->util->date($fileInfo['mtime']);
62: $blob .= " [" . $this->text->makeChatcmd("View", "/tell <myname> cache view $group $file") . "]";
63: $blob .= " [" . $this->text->makeChatcmd("Delete", "/tell <myname> cache rem $group $file") . "]\n";
64: }
65: $msg = $this->text->makeBlob("Cache Group: $group", $blob);
66: $sendto->reply($msg);
67: }
68:
69: 70: 71: 72:
73: public function cacheRemCommand($message, $channel, $sender, $sendto, $args) {
74: $group = $args[1];
75: $file = $args[2];
76:
77: if ($this->cacheManager->cacheExists($group, $file)) {
78: $contents = $this->cacheManager->remove($group, $file);
79: $msg = "Cache file <highlight>$file<end> in cache group <highlight>$group<end> has been deleted.";
80: } else {
81: $msg = "Could not find file <highlight>$file<end> in cache group <highlight>$group<end>.";
82: }
83: $sendto->reply($msg);
84: }
85:
86: 87: 88: 89:
90: public function cacheViewCommand($message, $channel, $sender, $sendto, $args) {
91: $group = $args[1];
92: $file = $args[2];
93:
94: if ($this->cacheManager->cacheExists($group, $file)) {
95: $contents = $this->cacheManager->retrieve($group, $file);
96: $msg = $this->text->makeBlob("Cache File: $group $file", htmlspecialchars ($contents));
97: } else {
98: $msg = "Could not find file <highlight>$file<end> in cache group <highlight>$group<end>.";
99: }
100: $sendto->reply($msg);
101: }
102: }
103: