Skip to content

Commit f3fc849

Browse files
authored
Merge pull request #4981 from HDInnovations/development
(Release) UNIT3D v9.1.7
2 parents d88d956 + b11d412 commit f3fc849

File tree

181 files changed

+3418
-1738
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+3418
-1738
lines changed

.cspell/dependency_terms.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
asciify
22
dontBackupDatabases
33
dontBackupFilesystem
4-
htmlify
54
lexify
6-
swal
5+
swal
6+
CURLOPT

.cspell/php_functions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ strcasecmp
3636
strpos
3737
strrchr
3838
strspn
39+
strstr
3940
strtolower
4041
strtotime
4142
strtoupper

app/Bots/NerdBot.php

Lines changed: 36 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -232,67 +232,45 @@ public function getKing(): string
232232
/**
233233
* Process Message.
234234
*/
235-
public function process(string $type, User $user, string $message = '', int $targeted = 0): true|\Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
235+
public function process(string $type, User $user, string $message): true|\Illuminate\Http\Response
236236
{
237237
$this->target = $user;
238238

239239
if ($type === 'message') {
240-
$x = 0;
241-
$y = 1;
240+
[$command,] = mb_split(' +', trim($message), 2) + [null, null];
242241
} else {
243-
$x = 1;
244-
$y = 2;
242+
[, $command,] = mb_split(' +', trim($message), 3) + [null, null, null];
245243
}
246244

247-
if ($message === '') {
248-
$log = '';
249-
} else {
250-
$log = 'All '.$this->bot->name.' commands must be a private message or begin with /'.$this->bot->command.' or !'.$this->bot->command.'. Need help? Type /'.$this->bot->command.' help and you shall be helped.';
251-
}
252-
253-
$command = @explode(' ', $message);
254-
255-
$params = $command[$y] ?? null;
256-
257-
if ($params) {
258-
$clone = $command;
259-
array_shift($clone);
260-
array_shift($clone);
261-
array_shift($clone);
262-
}
263-
264-
if (\array_key_exists($x, $command)) {
265-
$log = match($command[$x]) {
266-
'banker' => $this->getBanker(),
267-
'bans' => $this->getBans(),
268-
'unbans' => $this->getUnbans(),
269-
'doubleupload' => $this->getDoubleUpload(),
270-
'freeleech' => $this->getFreeleech(),
271-
'help' => $this->getHelp(),
272-
'king' => $this->getKing(),
273-
'logins' => $this->getLogins(),
274-
'peers' => $this->getPeers(),
275-
'registrations' => $this->getRegistrations(),
276-
'uploads' => $this->getUploads(),
277-
'warnings' => $this->getWarnings(),
278-
'seeded' => $this->getSeeded(),
279-
'leeched' => $this->getLeeched(),
280-
'snatched' => $this->getSnatched(),
281-
default => '',
282-
};
283-
}
245+
$this->log = match($command) {
246+
'banker' => $this->getBanker(),
247+
'bans' => $this->getBans(),
248+
'unbans' => $this->getUnbans(),
249+
'doubleupload' => $this->getDoubleUpload(),
250+
'freeleech' => $this->getFreeleech(),
251+
'help' => $this->getHelp(),
252+
'king' => $this->getKing(),
253+
'logins' => $this->getLogins(),
254+
'peers' => $this->getPeers(),
255+
'registrations' => $this->getRegistrations(),
256+
'uploads' => $this->getUploads(),
257+
'warnings' => $this->getWarnings(),
258+
'seeded' => $this->getSeeded(),
259+
'leeched' => $this->getLeeched(),
260+
'snatched' => $this->getSnatched(),
261+
default => 'All '.$this->bot->name.' commands must be a private message or begin with /'.$this->bot->command.' or !'.$this->bot->command.'. Need help? Type /'.$this->bot->command.' help and you shall be helped.',
262+
};
284263

285264
$this->type = $type;
286265
$this->message = $message;
287-
$this->log = $log;
288266

289267
return $this->pm();
290268
}
291269

292270
/**
293271
* Output Message.
294272
*/
295-
public function pm(): true|\Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
273+
public function pm(): true|\Illuminate\Http\Response
296274
{
297275
$type = $this->type;
298276
$target = $this->target;
@@ -304,16 +282,14 @@ public function pm(): true|\Illuminate\Http\Response|\Illuminate\Contracts\Routi
304282
$echoes = cache()->remember(
305283
'user-echoes'.$target->id,
306284
3600,
307-
fn () => UserEcho::with(['room', 'target', 'bot'])->where('user_id', '=', $target->id)->get()
285+
fn () => UserEcho::with(['user', 'room', 'target', 'bot'])->where('user_id', '=', $target->id)->get()
308286
);
309287

310288
if ($echoes->doesntContain(fn ($echo) => $echo->bot_id == $this->bot->id)) {
311-
UserEcho::create([
289+
$echoes->push(UserEcho::create([
312290
'user_id' => $target->id,
313291
'target_id' => $this->bot->id,
314-
]);
315-
316-
$echoes = UserEcho::with(['room', 'target', 'bot'])->where('user_id', '=', $target->id)->get();
292+
]));
317293

318294
cache()->put('user-echoes'.$target->id, $echoes, 3600);
319295

@@ -324,47 +300,39 @@ public function pm(): true|\Illuminate\Http\Response|\Illuminate\Contracts\Routi
324300
$audibles = cache()->remember(
325301
'user-audibles'.$target->id,
326302
3600,
327-
fn () => UserAudible::with(['room', 'target', 'bot'])->where('user_id', '=', $target->id)->get()
303+
fn () => UserAudible::with(['user', 'room', 'target', 'bot'])->where('user_id', '=', $target->id)->get()
328304
);
329305

330306
if ($audibles->doesntContain(fn ($audible) => $audible->bot_id == $this->bot->id)) {
331-
UserAudible::create([
307+
$audibles->push(UserAudible::create([
332308
'user_id' => $target->id,
333309
'target_id' => $this->bot->id,
334-
'status' => false,
335-
]);
336-
337-
$audibles = UserAudible::with(['room', 'target', 'bot'])->where('user_id', '=', $target->id)->get();
310+
'status' => 0,
311+
]));
338312

339313
cache()->put('user-audibles'.$target->id, $audibles, 3600);
340314

341315
Chatter::dispatch('audible', $target->id, UserAudibleResource::collection($audibles));
342316
}
343317

344318
// Create message
345-
if ($txt !== '') {
346-
$roomId = 0;
347-
$this->chatRepository->privateMessage($target->id, $roomId, $message, 1, $this->bot->id);
348-
$this->chatRepository->privateMessage(1, $roomId, $txt, $target->id, $this->bot->id);
349-
}
319+
$roomId = 0;
320+
$this->chatRepository->privateMessage($target->id, $roomId, $message, 1, $this->bot->id);
321+
$this->chatRepository->privateMessage(1, $roomId, $txt, $target->id, $this->bot->id);
350322

351323
return response('success');
352324
}
353325

354326
if ($type === 'echo') {
355-
if ($txt !== '') {
356-
$roomId = 0;
357-
$this->chatRepository->botMessage($this->bot->id, $roomId, $txt, $target->id);
358-
}
327+
$roomId = 0;
328+
$this->chatRepository->botMessage($this->bot->id, $roomId, $txt, $target->id);
359329

360330
return response('success');
361331
}
362332

363333
if ($type === 'public') {
364-
if ($txt !== '') {
365-
$this->chatRepository->message($target->id, $target->chatroom->id, $message, null, null);
366-
$this->chatRepository->message(1, $target->chatroom->id, $txt, null, $this->bot->id);
367-
}
334+
$this->chatRepository->message($target->id, $target->chatroom->id, $message, null, null);
335+
$this->chatRepository->message(1, $target->chatroom->id, $txt, null, $this->bot->id);
368336

369337
return response('success');
370338
}

app/Bots/SystemBot.php

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -122,54 +122,41 @@ public function putGift(string $receiver = '', float $amount = 0, array $note =
122122
/**
123123
* Process Message.
124124
*/
125-
public function process(string $type, User $user, string $message = ''): \Illuminate\Http\Response|bool|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory
125+
public function process(string $type, User $user, string $message): \Illuminate\Http\Response|bool
126126
{
127127
$this->target = $user;
128128

129-
if ($type === 'message') {
130-
$x = 0;
131-
$y = 1;
132-
$z = 2;
133-
} else {
134-
$x = 1;
135-
$y = 2;
136-
$z = 3;
129+
if ($type !== 'message') {
130+
$message = trim(strstr($message, ' ') ?: '');
137131
}
138132

139-
if ($message === '') {
140-
$log = '';
141-
} else {
142-
$log = 'All '.$this->bot->name.' commands must be a private message or begin with /'.$this->bot->command.' or !'.$this->bot->command.'. Need help? Type /'.$this->bot->command.' help and you shall be helped.';
143-
}
133+
$firstWord = strstr($message, ' ', true);
144134

145-
$command = @explode(' ', $message);
135+
switch ($firstWord) {
136+
case 'gift':
137+
[, $username, $amount, $message] = mb_split(' +', $message, 4) + [null, null, null, null];
146138

147-
if (\array_key_exists($x, $command)) {
148-
if ($command[$x] === 'gift' && \array_key_exists($y, $command) && \array_key_exists($z, $command) && \array_key_exists($z + 1, $command)) {
149-
$clone = $command;
150-
array_shift($clone);
151-
array_shift($clone);
152-
array_shift($clone);
153-
array_shift($clone);
154-
$log = $this->putGift($command[$y], (float) $command[$z], $clone);
155-
}
139+
$this->log = $this->putGift($username, $amount, $message);
156140

157-
if ($command[$x] === 'help') {
158-
$log = $this->getHelp();
159-
}
141+
break;
142+
case 'help':
143+
$this->log = $this->getHelp();
144+
145+
break;
146+
default:
147+
$this->log = 'All '.$this->bot->name.' commands must be a private message or begin with /'.$this->bot->command.' or !'.$this->bot->command.'. Need help? Type /'.$this->bot->command.' help and you shall be helped.';
160148
}
161149

162150
$this->type = $type;
163151
$this->message = $message;
164-
$this->log = $log;
165152

166153
return $this->pm();
167154
}
168155

169156
/**
170157
* Output Message.
171158
*/
172-
public function pm(): \Illuminate\Http\Response|bool|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory
159+
public function pm(): \Illuminate\Http\Response|true
173160
{
174161
$type = $this->type;
175162
$target = $this->target;
@@ -181,16 +168,14 @@ public function pm(): \Illuminate\Http\Response|bool|\Illuminate\Contracts\Found
181168
$echoes = cache()->remember(
182169
'user-echoes'.$target->id,
183170
3600,
184-
fn () => UserEcho::with(['room', 'target', 'bot'])->where('user_id', '=', $target->id)->get()
171+
fn () => UserEcho::with(['user', 'room', 'target', 'bot'])->where('user_id', '=', $target->id)->get()
185172
);
186173

187174
if ($echoes->doesntContain(fn ($echo) => $echo->bot_id == $this->bot->id)) {
188-
UserEcho::create([
175+
$echoes->push(UserEcho::create([
189176
'user_id' => $target->id,
190177
'target_id' => $this->bot->id,
191-
]);
192-
193-
$echoes = UserEcho::with(['room', 'target', 'bot'])->where('user_id', '=', $target->id)->get();
178+
]));
194179

195180
cache()->put('user-echoes'.$target->id, $echoes, 3600);
196181

@@ -201,47 +186,39 @@ public function pm(): \Illuminate\Http\Response|bool|\Illuminate\Contracts\Found
201186
$audibles = cache()->remember(
202187
'user-audibles'.$target->id,
203188
3600,
204-
fn () => UserAudible::with(['room', 'target', 'bot'])->where('user_id', '=', $target->id)->get()
189+
fn () => UserAudible::with(['user', 'room', 'target', 'bot'])->where('user_id', '=', $target->id)->get()
205190
);
206191

207192
if ($audibles->doesntContain(fn ($audible) => $audible->bot_id == $this->bot->id)) {
208-
UserAudible::create([
193+
$audibles->push(UserAudible::create([
209194
'user_id' => $target->id,
210195
'target_id' => $this->bot->id,
211-
'status' => false,
212-
]);
213-
214-
$audibles = UserAudible::with(['room', 'target', 'bot'])->where('user_id', '=', $target->id)->get();
196+
'status' => 0,
197+
]));
215198

216199
cache()->put('user-audibles'.$target->id, $audibles, 3600);
217200

218201
Chatter::dispatch('audible', $target->id, UserAudibleResource::collection($audibles));
219202
}
220203

221204
// Create message
222-
if ($txt !== '') {
223-
$roomId = 0;
224-
$this->chatRepository->privateMessage($target->id, $roomId, $message, 1, $this->bot->id);
225-
$this->chatRepository->privateMessage(1, $roomId, $txt, $target->id, $this->bot->id);
226-
}
205+
$roomId = 0;
206+
$this->chatRepository->privateMessage($target->id, $roomId, $message, 1, $this->bot->id);
207+
$this->chatRepository->privateMessage(1, $roomId, $txt, $target->id, $this->bot->id);
227208

228209
return response('success');
229210
}
230211

231212
if ($type === 'echo') {
232-
if ($txt !== '') {
233-
$roomId = 0;
234-
$this->chatRepository->botMessage($this->bot->id, $roomId, $txt, $target->id);
235-
}
213+
$roomId = 0;
214+
$this->chatRepository->botMessage($this->bot->id, $roomId, $txt, $target->id);
236215

237216
return response('success');
238217
}
239218

240219
if ($type === 'public') {
241-
if ($txt !== '') {
242-
$this->chatRepository->message($target->id, $target->chatroom->id, $message, null, null);
243-
$this->chatRepository->message(1, $target->chatroom->id, $txt, null, $this->bot->id);
244-
}
220+
$this->chatRepository->message($target->id, $target->chatroom->id, $message, null, null);
221+
$this->chatRepository->message(1, $target->chatroom->id, $txt, null, $this->bot->id);
245222

246223
return response('success');
247224
}

0 commit comments

Comments
 (0)