]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace UnrealIRCd; | |
4 | ||
5 | use Exception; | |
6 | use stdClass; | |
7 | ||
8 | class User | |
9 | { | |
10 | ||
11 | public Connection $connection; | |
12 | ||
13 | public function __construct(Connection $conn) | |
14 | { | |
15 | $this->connection = $conn; | |
16 | } | |
17 | ||
18 | /** | |
19 | * Return a list of all users. | |
20 | */ | |
21 | public function getAll(int $object_detail_level=2): stdClass|array|bool | |
22 | { | |
23 | $response = $this->connection->query('user.list', [ | |
24 | 'object_detail_level' => $object_detail_level, | |
25 | ]); | |
26 | ||
27 | if(!is_bool($response)) { | |
28 | return $response->list; | |
29 | } | |
30 | ||
31 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
32 | } | |
33 | ||
34 | /** | |
35 | * Return a user object | |
36 | * | |
37 | * @return stdClass|array|bool | |
38 | */ | |
39 | public function get(string $nick, int $object_detail_level=4): stdClass|array|bool | |
40 | { | |
41 | $response = $this->connection->query('user.get', [ | |
42 | 'nick' => $nick, | |
43 | 'object_detail_level' => $object_detail_level, | |
44 | ]); | |
45 | ||
46 | if (!is_bool($response)) { | |
47 | return $response->client; | |
48 | } | |
49 | ||
50 | return false; // not found | |
51 | } | |
52 | ||
53 | /** | |
54 | * Set the nickname of a user (changes the nick) | |
55 | * | |
56 | * @return stdClass|array|bool | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | } | |
208 | } |