Skip to content

Commit bb712d0

Browse files
authored
Merge pull request #10 from Hopex-Development/dev
Dev
2 parents e3f024b + ec42cb1 commit bb712d0

File tree

8 files changed

+130
-31
lines changed

8 files changed

+130
-31
lines changed

src/.root/lang/ru/vk-sdk.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,5 @@
178178
'Invalid SourceQuery packet' => 'Недопустимый пакет SourceQuery',
179179
'Unknown server' => 'Неизвестный сервер',
180180
'Undefined server response' => 'Неопределенный ответ сервера',
181+
'Invalid input data type' => 'Недопустимый тип входных данных',
181182
];
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Hopex\VkSdk\Exceptions\Formatters;
4+
5+
use Hopex\VkSdk\Exceptions\SdkException;
6+
7+
class InvalidInputDataTypeException extends SdkException
8+
{
9+
public $message = 'Invalid input data type';
10+
}

src/Formatters/ClearInputMessageFormatter.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ class ClearInputMessageFormatter implements CanFormatContract
1212
{
1313
/**
1414
* @param $data
15-
* @return string
15+
* @return array
1616
*/
17-
public function format($data): string
17+
public function format($data): array
1818
{
19-
return explode(' ', preg_replace("~((^\[.*\])?\s*\!*)|(^\s*\!*)~", '', $data))[0];
19+
$input = explode(' ', preg_replace("~((^\[.*\])?\s*\!*)|(^\s*\!*)~", '$1', $data));
20+
return array_merge([
21+
$input[0]
22+
], [
23+
implode(' ', array_slice($input, 1, count($input)))
24+
]);
2025
}
2126
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Hopex\VkSdk\Formatters;
4+
5+
use Hopex\VkSdk\Contracts\CanFormatContract;
6+
use Hopex\VkSdk\Exceptions\Formatters\InvalidInputDataTypeException;
7+
8+
/**
9+
* Class ClearMentionsFormatter
10+
* @package Hopex\VkSdk\Formatters
11+
*/
12+
class ClearMentionsFormatter implements CanFormatContract
13+
{
14+
/**
15+
* @param $data
16+
* @return string
17+
* @throws InvalidInputDataTypeException
18+
*/
19+
public function format($data): string
20+
{
21+
if (!is_string($data)) {
22+
throw new InvalidInputDataTypeException();
23+
}
24+
25+
return preg_replace("~^(\[.*]\s)|(!)|(.*)~", '$3', $data);
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Hopex\VkSdk\Formatters;
4+
5+
use Hopex\VkSdk\Contracts\CanFormatContract;
6+
use Hopex\VkSdk\Exceptions\Formatters\InvalidInputDataTypeException;
7+
8+
/**
9+
* Class ClearSpacesFormatter
10+
* @package Hopex\VkSdk\Formatters
11+
*/
12+
class ClearSpacesFormatter implements CanFormatContract
13+
{
14+
/**
15+
* @param $data
16+
* @return string
17+
* @throws InvalidInputDataTypeException
18+
*/
19+
public function format($data): string
20+
{
21+
if (!is_string($data)) {
22+
throw new InvalidInputDataTypeException();
23+
}
24+
25+
return trim(preg_replace('~\s{2,}~', ' ', $data));
26+
}
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Hopex\VkSdk\Formatters;
4+
5+
use Hopex\VkSdk\Contracts\CanFormatContract;
6+
use Hopex\VkSdk\Exceptions\Formatters\InvalidInputDataTypeException;
7+
8+
/**
9+
* Class SliceInputMessageFormatter
10+
* @package Hopex\VkSdk\Formatters
11+
*/
12+
class SliceInputMessageFormatter implements CanFormatContract
13+
{
14+
/**
15+
* @param $data
16+
* @return string
17+
* @throws InvalidInputDataTypeException
18+
*/
19+
public function format($data): array
20+
{
21+
if (!is_string($data)) {
22+
throw new InvalidInputDataTypeException();
23+
}
24+
25+
$exploded = explode(' ', $data);
26+
return [
27+
'command' => $exploded[0],
28+
'payload' => implode(' ', array_slice($exploded, 1, count($exploded)))
29+
];
30+
}
31+
}

src/Foundation/Core/Entities/Messages/MessageFields.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Carbon\Carbon;
66
use Hopex\VkSdk\Exceptions\Api\ApiException;
7+
use Hopex\VkSdk\Facades\VkApi;
78
use Hopex\VkSdk\Foundation\Core\Entities\Users\UserProfileFields;
89
use Hopex\VkSdk\Foundation\Core\Entities\Users\UserRequestFields;
910
use Illuminate\Support\Collection;
@@ -52,21 +53,19 @@ public function getDate(): Carbon
5253

5354
/**
5455
* @param string $token
56+
* @param UserRequestFields $userRequestFields
5557
* @param array $userProfileFields
5658
* @return UserProfileFields
5759
* @throws ApiException
5860
* @throws Throwable
5961
*/
60-
public function getSender(string $token, UserRequestFields $userRequestFields): UserProfileFields
62+
public function getSender(string $token, UserRequestFields $userRequestFields, array $userProfileFields = []): UserProfileFields
6163
{
62-
return new UserProfileFields([]);
63-
// return new UserProfileFields(collect(VkApi::user($token)
64-
// ->get((new UserRequestFields())
65-
// ->setUserIds([
66-
// $this->getSenderId()
67-
// ])
68-
// ->setProfileFields($userRequestFields->)
69-
// )->first()));
64+
return new UserProfileFields(
65+
collect(VkApi::user($token)
66+
->get($userRequestFields->setProfileFields($userProfileFields))
67+
->first())
68+
);
7069
}
7170

7271
/**

src/Foundation/Core/Server/EventsHandler.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Hopex\VkSdk\Foundation\Core\Server;
44

55
use Hopex\VkSdk\Contracts\ServerEventsContract;
6+
use Hopex\VkSdk\Exceptions\Api\ApiException;
67
use Hopex\VkSdk\Exceptions\SourceQuery\AuthenticationSourceQueryException;
78
use Hopex\VkSdk\Exceptions\SourceQuery\InvalidArgumentSourceQueryException;
89
use Hopex\VkSdk\Exceptions\SourceQuery\InvalidPacketSourceQueryException;
@@ -46,7 +47,10 @@ public function __construct()
4647
}
4748

4849
/**
49-
* @inheritDoc
50+
* @param Message $message
51+
* @return void
52+
* @throws ApiException
53+
* @throws Throwable
5054
*/
5155
public function server_message_new(Message $message): void
5256
{
@@ -60,7 +64,10 @@ public function server_message_new(Message $message): void
6064
}
6165

6266
/**
63-
* @inheritDoc
67+
* @param Mute $mute
68+
* @return void
69+
* @throws ApiException
70+
* @throws Throwable
6471
*/
6572
public function server_mute_new(Mute $mute): void
6673
{
@@ -78,7 +85,10 @@ public function server_mute_new(Mute $mute): void
7885
}
7986

8087
/**
81-
* @inheritDoc
88+
* @param Ban $ban
89+
* @return void
90+
* @throws ApiException
91+
* @throws Throwable
8292
*/
8393
public function server_ban_new(Ban $ban): void
8494
{
@@ -140,26 +150,15 @@ public function requestStatistics(int $groupId): void
140150
public function messageSendToServer(int $groupId, int $peerId, string $name, string $text): void
141151
{
142152
$this->logger->info("ServerMessage \"$text\" from \"$name\" has been send to server by group $groupId");
143-
// $this->sourceQueryCall($groupId, 'sm_chat_say "' . $name . '" "' . $text . '"');
144153
$this->sourceQueryCall($groupId, "sm_chat_say \"$name\" \"$text\"");
145-
146-
VkApi::message(Session::get('group_token'))
147-
->send((new MessageRequestFields())
148-
->setPeerId($peerId)
149-
->setDisableMentions(true)
150-
->setDontParseLinks(true)
151-
->setMessage(str_replace([
152-
'%PLAYER%',
153-
'%MESSAGE%'
154-
], [
155-
$name,
156-
$text
157-
], Note::get('server.messages.to-server')))
158-
);
159154
}
160155

161156
/**
162-
* @inheritDoc
157+
* @param ServerEvent $event
158+
* @param string $message
159+
* @return void
160+
* @throws Throwable
161+
* @throws ApiException
163162
*/
164163
public function messageSendToVk(ServerEvent $event, string $message): void
165164
{

0 commit comments

Comments
 (0)