1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19: class NotesController {
20:
21: 22: 23: 24:
25: public $moduleName;
26:
27:
28: public $db;
29:
30:
31: public $text;
32:
33:
34: public $altsController;
35:
36: 37: 38:
39: public function setup() {
40: $this->db->loadSQLFile($this->moduleName, "notes");
41: }
42:
43: 44: 45: 46:
47: public function notesListCommand($message, $channel, $sender, $sendto, $args) {
48: $altInfo = $this->altsController->getAltInfo($sender);
49: $main = $altInfo->getValidatedMain($sender);
50:
51: if ($main != $sender) {
52:
53: $sql = "UPDATE notes SET owner = ? WHERE owner = ?";
54: $this->db->exec($sql, $main, $sender);
55: }
56:
57: $sql = "SELECT * FROM notes WHERE owner = ? ORDER BY added_by ASC, dt DESC";
58: $data = $this->db->query($sql, $main);
59:
60: if (count($data) == 0) {
61: $msg = "No notes for $sender.";
62: } else {
63: $blob = '';
64: $current = '';
65: $count = count($data);
66: forEach ($data as $row) {
67: if ($row->added_by != $current) {
68: $blob .= "\n<header2>$row->added_by<end>\n\n";
69: $current = $row->added_by;
70: }
71: $remove = $this->text->makeChatcmd('Remove', "/tell <myname> notes rem $row->id");
72: $blob .= "$remove $row->note\n\n";
73: }
74: $msg = $this->text->makeBlob("Notes for $sender ($count)", $blob);
75: }
76:
77: $sendto->reply($msg);
78: }
79:
80: 81: 82: 83:
84: public function notesAddCommand($message, $channel, $sender, $sendto, $args) {
85: $note = $args[1];
86:
87: $altInfo = $this->altsController->getAltInfo($sender);
88: $main = $altInfo->getValidatedMain($sender);
89:
90: $this->db->exec("INSERT INTO notes (owner, added_by, note, dt) VALUES (?, ?, ?, ?)", $main, $sender, $note, time());
91: $msg = "Note added successfully.";
92:
93: $sendto->reply($msg);
94: }
95:
96: 97: 98: 99:
100: public function notesRemoveCommand($message, $channel, $sender, $sendto, $args) {
101: $id = $args[1];
102:
103: $altInfo = $this->altsController->getAltInfo($sender);
104: $main = $altInfo->getValidatedMain($sender);
105:
106: $numRows = $this->db->exec("DELETE FROM notes WHERE id = ? AND owner = ?", $id, $main);
107: if ($numRows == 0) {
108: $msg = "Note could not be found or note does not belong to you.";
109: } else {
110: $msg = "Note deleted successfully.";
111: }
112:
113: $sendto->reply($msg);
114: }
115: }
116: