1: <?php
2:
3: namespace Budabot\Core\Modules;
4:
5: use Exception;
6:
7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19: class SettingsController {
20:
21: 22: 23: 24:
25: public $moduleName;
26:
27:
28: public $text;
29:
30:
31: public $db;
32:
33:
34: public $settingManager;
35:
36:
37: public $helpManager;
38:
39:
40: public $util;
41:
42:
43: public $commandManager;
44:
45: 46: 47: 48:
49: public function setup() {
50: $this->settingManager->upload();
51: }
52:
53: 54: 55: 56:
57: public function settingsCommand($message, $channel, $sender, $sendto, $args) {
58: $blob = '';
59: $blob .= "Changing any of these settings will take effect immediately. Please note that some of these settings are read-only and cannot be changed.\n\n";
60: $data = $this->db->query("SELECT * FROM settings_<myname> ORDER BY `module`");
61: $cur = '';
62: forEach ($data as $row) {
63: if ($row->module != $cur) {
64: $blob .= "\n<pagebreak><header2>".str_replace("_", " ", $row->module)."<end>\n";
65: $cur = $row->module;
66: }
67: $blob .= " *" . $row->description;
68:
69: if ($row->mode == "edit") {
70: $editLink = $this->text->makeChatcmd('Modify', "/tell <myname> settings change {$row->name}");
71: $blob .= " ($editLink)";
72: }
73:
74: $settingHandler = $this->settingManager->getSettingHandler($row);
75: $blob .= ": " . $settingHandler->displayValue() . "\n";
76: }
77:
78: $msg = $this->text->makeBlob("Bot Settings", $blob);
79: $sendto->reply($msg);
80: }
81:
82: 83: 84: 85:
86: public function changeCommand($message, $channel, $sender, $sendto, $args) {
87: $settingName = strtolower($args[1]);
88: $row = $this->db->queryRow("SELECT * FROM settings_<myname> WHERE `name` = ?", $settingName);
89: if ($row === null) {
90: $msg = "Could not find setting <highlight>{$settingName}<end>.";
91: } else {
92: $settingHandler = $this->settingManager->getSettingHandler($row);
93: $blob = "Name: <highlight>{$row->name}<end>\n";
94: $blob .= "Module: <highlight>{$row->module}<end>\n";
95: $blob .= "Descrption: <highlight>{$row->description}<end>\n";
96: $blob .= "Current Value: " . $settingHandler->displayValue() . "\n\n";
97: $blob .= $settingHandler->getDescription();
98: $blob .= $settingHandler->getOptions();
99:
100:
101: $help = $this->helpManager->find($settingName, $sender);
102: if ($help !== false) {
103: $blob .= "\n\n<header2>Help ($settingName)<end>\n\n" . $help;
104: }
105:
106: $msg = $this->text->makeBlob("Settings Info for {$settingName}", $blob);
107: }
108:
109: $sendto->reply($msg);
110: }
111:
112: 113: 114: 115:
116: public function saveCommand($message, $channel, $sender, $sendto, $args) {
117: $name = strtolower($args[1]);
118: $change_to_setting = $args[2];
119: $row = $this->db->queryRow("SELECT * FROM settings_<myname> WHERE `name` = ?", $name);
120: if ($row === null) {
121: $msg = "Could not find setting <highlight>{$name}<end>.";
122: } else {
123: $settingHandler = $this->settingManager->getSettingHandler($row);
124: try {
125: $new_setting = $settingHandler->save($change_to_setting);
126: if ($this->settingManager->save($name, $new_setting)) {
127: $msg = "Setting <highlight>$name<end> has been saved.";
128: } else {
129: $msg = "Error! Setting <highlight>$name<end> could not be saved.";
130: }
131: } catch (Exception $e) {
132: $msg = $e->getMessage();
133: }
134: }
135: $sendto->reply($msg);
136: }
137: }
138: