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 WhitelistController {
21: 22: 23: 24:
25: public $moduleName;
26:
27:
28: public $db;
29:
30:
31: public $text;
32:
33:
34: public $util;
35:
36: 37: 38:
39: public function setup() {
40: $this->db->loadSQLFile($this->moduleName, 'whitelist');
41: }
42:
43: 44: 45: 46:
47: public function whitelistCommand($message, $channel, $sender, $sendto, $args) {
48: $list = $this->all();
49: if (count($list) == 0) {
50: $sendto->reply("No entries in whitelist");
51: } else {
52: $blob = '';
53: forEach ($list as $entry) {
54: $remove = $this->text->makeChatcmd('Remove', "/tell <myname> whitelist remove $entry->name");
55: $date = $this->util->date($entry->added_dt);
56: $blob .= "<highlight>{$entry->name}<end> [added by {$entry->added_by}] {$date} {$remove}\n";
57: }
58: $msg = $this->text->makeBlob("Whitelist", $blob);
59: $sendto->reply($msg);
60: }
61: }
62:
63: 64: 65: 66:
67: public function whitelistAddCommand($message, $channel, $sender, $sendto, $args) {
68: $sendto->reply($this->add($args[1], $sender));
69: }
70:
71: 72: 73: 74:
75: public function whitelistRemoveCommand($message, $channel, $sender, $sendto, $args) {
76: $sendto->reply($this->remove($args[2]));
77: }
78:
79: public function add($user, $sender) {
80: $user = ucfirst(strtolower($user));
81: $sender = ucfirst(strtolower($sender));
82:
83: if ($user == '' || $sender == '') {
84: return "User or sender is blank";
85: }
86:
87: $data = $this->db->query("SELECT * FROM whitelist WHERE name = ?", $user);
88: if (count($data) != 0) {
89: return "Error! $user already added to the whitelist.";
90: } else {
91: $this->db->exec("INSERT INTO whitelist (name, added_by, added_dt) VALUES (?, ?, ?)", $user, $sender, time());
92: return "$user has been added to the whitelist.";
93: }
94: }
95:
96: public function remove($user) {
97: $user = ucfirst(strtolower($user));
98:
99: if ($user == '') {
100: return "User is blank";
101: }
102:
103: $data = $this->db->query("SELECT * FROM whitelist WHERE name = ?", $user);
104: if (count($data) == 0) {
105: return "Error! $user is not on the whitelist.";
106: } else {
107: $this->db->exec("DELETE FROM whitelist WHERE name = ?", $user);
108: return "$user has been removed from the whitelist.";
109: }
110: }
111:
112: public function check($user) {
113: $user = ucfirst(strtolower($user));
114:
115: $row = $this->db->queryRow("SELECT * FROM whitelist WHERE name = ? LIMIT 1", $user);
116: if ($row === null) {
117: return false;
118: } else {
119: return true;
120: }
121: }
122:
123: public function all() {
124: return $this->db->query("SELECT * FROM whitelist ORDER BY name ASC");
125: }
126: }
127: