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 OrgHistoryController {
20:
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, "org_history");
41: }
42:
43: 44: 45: 46: 47:
48: public function orghistoryCommand($message, $channel, $sender, $sendto, $args) {
49: $pageSize = 40;
50: $page = 1;
51: if (count($args) == 2) {
52: $page = $args[1];
53: }
54:
55: $startingRecord = ($page - 1) * $pageSize;
56:
57: $blob = '';
58:
59: $sql = "SELECT actor, actee, action, organization, time FROM `org_history` ORDER BY time DESC LIMIT ?, ?";
60: $data = $this->db->query($sql, intval($startingRecord), intval($pageSize));
61: if (count($data) != 0) {
62: forEach ($data as $row) {
63: $blob .= $this->formatOrgAction($row);
64: }
65:
66: $msg = $this->text->makeBlob('Org History', $blob);
67: } else {
68: $msg = "No org history has been recorded.";
69: }
70:
71: $sendto->reply($msg);
72: }
73:
74: 75: 76: 77:
78: public function orghistoryPlayerCommand($message, $channel, $sender, $sendto, $args) {
79: $player = ucfirst(strtolower($args[1]));
80:
81: $blob = '';
82:
83: $sql = "SELECT actor, actee, action, organization, time FROM `org_history` WHERE actee LIKE ? ORDER BY time DESC";
84: $data = $this->db->query($sql, $player);
85: $count = count($data);
86: $blob .= "\n<header2>Actions on $player ($count)<end>\n";
87: forEach ($data as $row) {
88: $blob .= $this->formatOrgAction($row);
89: }
90:
91: $sql = "SELECT actor, actee, action, organization, time FROM `org_history` WHERE actor LIKE ? ORDER BY time DESC";
92: $data = $this->db->query($sql, $player);
93: $count = count($data);
94: $blob .= "\n<header2>Actions by $player ($count)<end>\n";
95: forEach ($data as $row) {
96: $blob .= $this->formatOrgAction($row);
97: }
98:
99: $msg = $this->text->makeBlob("Org History for $player", $blob);
100:
101: $sendto->reply($msg);
102: }
103:
104: public function formatOrgAction($row) {
105: switch ($row->action) {
106: case 'left':
107: return "<highlight>$row->actor<end> $row->action. [$row->organization] " . $this->util->date($row->time) . "\n";
108: default:
109: return"<highlight>$row->actor<end> $row->action <highlight>$row->actee<end>. [$row->organization] " . $this->util->date($row->time) . "\n";
110: }
111: }
112:
113: 114: 115: 116:
117: public function captureOrgMessagesEvent($eventObj) {
118: $message = $eventObj->message;
119: if (preg_match("/^(.+) just left your organization.$/", $message, $arr)) {
120: $actor = $arr[1];
121: $actee = "";
122: $action = "left";
123: $time = time();
124:
125: $sql = "INSERT INTO `org_history` (actor, actee, action, organization, time) VALUES (?, ?, ?, '<myguild>', ?) ";
126: $this->db->exec($sql, $actor, $actee, $action, $time);
127: } else if (preg_match("/^(.+) kicked (.+) from your organization.$/", $message, $arr)) {
128: $actor = $arr[1];
129: $actee = $arr[2];
130: $action = "kicked";
131: $time = time();
132:
133: $sql = "INSERT INTO `org_history` (actor, actee, action, organization, time) VALUES (?, ?, ?, '<myguild>', ?) ";
134: $this->db->exec($sql, $actor, $actee, $action, $time);
135: } else if (preg_match("/^(.+) invited (.+) to your organization.$/", $message, $arr)) {
136: $actor = $arr[1];
137: $actee = $arr[2];
138: $action = "invited";
139: $time = time();
140:
141: $sql = "INSERT INTO `org_history` (actor, actee, action, organization, time) VALUES (?, ?, ?, '<myguild>', ?) ";
142: $this->db->exec($sql, $actor, $actee, $action, $time);
143: } else if (preg_match("/^(.+) removed inactive character (.+) from your organization.$/", $message, $arr)) {
144: $actor = $arr[1];
145: $actee = $arr[2];
146: $action = "removed";
147: $time = time();
148:
149: $sql = "INSERT INTO `org_history` (actor, actee, action, organization, time) VALUES (?, ?, ?, '<myguild>', ?) ";
150: $this->db->exec($sql, $actor, $actee, $action, $time);
151: }
152: }
153: }
154:
155: