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