]>
Commit | Line | Data |
---|---|---|
8d5a112f D |
1 | <?php |
2 | ||
3 | namespace UnrealIRCd; | |
4 | ||
5 | use Exception; | |
80bc3098 | 6 | use stdClass; |
8d5a112f | 7 | |
78796043 | 8 | class User |
8d5a112f D |
9 | { |
10 | ||
11 | public Connection $connection; | |
12 | ||
7c7017a2 | 13 | public function __construct(Connection $conn) |
8d5a112f | 14 | { |
7c7017a2 | 15 | $this->connection = $conn; |
8d5a112f D |
16 | } |
17 | ||
18 | /** | |
19 | * Return a list of all users. | |
8d5a112f | 20 | */ |
249f865d | 21 | public function getAll(int $object_detail_level=2): stdClass|array|bool |
8d5a112f | 22 | { |
249f865d BM |
23 | $response = $this->connection->query('user.list', [ |
24 | 'object_detail_level' => $object_detail_level, | |
25 | ]); | |
8d5a112f D |
26 | |
27 | if(!is_bool($response)) { | |
93f8a3ee | 28 | return $response->list; |
8d5a112f D |
29 | } |
30 | ||
31 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
32 | } | |
33 | ||
34 | /** | |
35 | * Return a user object | |
36 | * | |
93f8a3ee | 37 | * @return stdClass|array|bool |
8d5a112f | 38 | */ |
249f865d | 39 | public function get(string $nick, int $object_detail_level=4): stdClass|array|bool |
8d5a112f | 40 | { |
249f865d BM |
41 | $response = $this->connection->query('user.get', [ |
42 | 'nick' => $nick, | |
43 | 'object_detail_level' => $object_detail_level, | |
44 | ]); | |
8d5a112f D |
45 | |
46 | if (!is_bool($response)) { | |
13ae2ba6 | 47 | return $response->client; |
8d5a112f D |
48 | } |
49 | ||
2d5f74f2 | 50 | return false; // not found |
8d5a112f | 51 | } |
e25853aa BM |
52 | |
53 | /** | |
54 | * Set the nickname of a user (changes the nick) | |
55 | * | |
56 | * @return stdClass|array|bool | |
e25853aa BM |
57 | */ |
58 | public function set_nick(string $nick, string $newnick): stdClass|array|bool | |
59 | { | |
60 | return $this->connection->query('user.set_nick', [ | |
61 | 'nick' => $nick, | |
62 | 'newnick' => $newnick, | |
63 | ]); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Set the username/ident of a user | |
68 | * | |
69 | * @return stdClass|array|bool | |
e25853aa BM |
70 | */ |
71 | public function set_username(string $nick, string $username): stdClass|array|bool | |
72 | { | |
73 | return $this->connection->query('user.set_username', [ | |
74 | 'nick' => $nick, | |
75 | 'username' => $username, | |
76 | ]); | |
77 | } | |
78 | ||
79 | /** | |
80 | * Set the realname/gecos of a user | |
81 | * | |
82 | * @return stdClass|array|bool | |
e25853aa BM |
83 | */ |
84 | public function set_realname(string $nick, string $realname): stdClass|array|bool | |
85 | { | |
86 | return $this->connection->query('user.set_realname', [ | |
87 | 'nick' => $nick, | |
88 | 'realname' => $realname, | |
89 | ]); | |
90 | } | |
91 | ||
92 | /** | |
93 | * Set a virtual host (vhost) on the user | |
94 | * | |
95 | * @return stdClass|array|bool | |
e25853aa BM |
96 | */ |
97 | public function set_vhost(string $nick, string $vhost): stdClass|array|bool | |
98 | { | |
99 | return $this->connection->query('user.set_vhost', [ | |
100 | 'nick' => $nick, | |
101 | 'vhost' => $vhost, | |
102 | ]); | |
103 | } | |
104 | ||
105 | /** | |
106 | * Change the user modes of a user. | |
107 | * | |
108 | * @return stdClass|array|bool | |
e25853aa BM |
109 | */ |
110 | public function set_mode(string $nick, string $mode, bool $hidden = false): stdClass|array|bool | |
111 | { | |
112 | return $this->connection->query('user.set_mode', [ | |
113 | 'nick' => $nick, | |
114 | 'modes' => $mode, | |
115 | 'hidden' => $hidden, | |
116 | ]); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Change the snomask of a user (oper). | |
121 | * | |
122 | * @return stdClass|array|bool | |
e25853aa BM |
123 | */ |
124 | public function set_snomask(string $nick, string $snomask, bool $hidden = false): stdClass|array|bool | |
125 | { | |
126 | return $this->connection->query('user.set_snomask', [ | |
127 | 'nick' => $nick, | |
128 | 'snomask' => $snomask, | |
129 | 'hidden' => $hidden, | |
130 | ]); | |
131 | } | |
132 | ||
133 | /** | |
134 | * Make user an IRC Operator (oper). | |
135 | * | |
136 | * @return stdClass|array|bool | |
e25853aa BM |
137 | */ |
138 | public function set_oper(string $nick, string $oper_account, string $oper_class, | |
139 | string $class = null, string $modes = null, | |
140 | string $snomask = null, string $vhost = null): stdClass|array|bool | |
141 | { | |
142 | return $this->connection->query('user.set_oper', [ | |
143 | 'nick' => $nick, | |
144 | 'oper_account' => $oper_account, | |
145 | 'oper_class' => $oper_class, | |
146 | 'class' => $class, | |
147 | 'modes' => $modes, | |
148 | 'snomask' => $snomask, | |
149 | 'vhost' => $vhost, | |
150 | ]); | |
151 | } | |
152 | ||
153 | /** | |
154 | * Join a user to a channel. | |
155 | * | |
156 | * @return stdClass|array|bool | |
e25853aa BM |
157 | */ |
158 | public function join(string $nick, string $channel, | |
159 | string $key = null, bool $force = false): stdClass|array|bool | |
160 | { | |
161 | return $this->connection->query('user.join', [ | |
162 | 'nick' => $nick, | |
163 | 'channel' => $channel, | |
164 | 'key' => $key, | |
165 | 'force' => $force, | |
166 | ]); | |
167 | } | |
168 | ||
169 | /** | |
170 | * Part a user from a channel. | |
171 | * | |
172 | * @return stdClass|array|bool | |
e25853aa BM |
173 | */ |
174 | public function part(string $nick, string $channel, bool $force = false): stdClass|array|bool | |
175 | { | |
176 | return $this->connection->query('user.part', [ | |
177 | 'nick' => $nick, | |
178 | 'channel' => $channel, | |
179 | 'force' => $force, | |
180 | ]); | |
181 | } | |
182 | ||
183 | /** | |
184 | * Quit a user from IRC. Pretend it is a normal QUIT. | |
185 | * | |
186 | * @return stdClass|array|bool | |
e25853aa BM |
187 | */ |
188 | public function quit(string $nick, string $reason): stdClass|array|bool | |
189 | { | |
190 | return $this->connection->query('user.quit', [ | |
191 | 'nick' => $nick, | |
192 | 'reason' => $reason, | |
193 | ]); | |
194 | } | |
195 | ||
196 | /** | |
197 | * Kill a user from IRC. Show that the user is forcefully removed. | |
198 | * | |
199 | * @return stdClass|array|bool | |
e25853aa BM |
200 | */ |
201 | public function kill(string $nick, string $reason): stdClass|array|bool | |
202 | { | |
203 | return $this->connection->query('user.kill', [ | |
204 | 'nick' => $nick, | |
205 | 'reason' => $reason, | |
206 | ]); | |
207 | } | |
8d5a112f | 208 | } |