Skip to content

Commit

Permalink
сlosing v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
aidsoul committed Oct 11, 2022
1 parent d66e5df commit 9f9ff91
Show file tree
Hide file tree
Showing 22 changed files with 276 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
* @author aidsoul <[email protected]>
* @license MIT
*/
class Post extends Database implements PostInterface
class PostModel extends Database implements PostInterface
{
/**
* @param string $tableName
* @param string $idPost
* @param string $groupId
*/
public function __construct(
private readonly string $tableName = 'post',
private readonly string $idPost = 'id_post',
private readonly string $groupId = 'group_id'
private string $tableName = 'post',
private string $idPost = 'id_post',
private string $groupId = 'group_id'
) {
parent::__construct();
}
Expand All @@ -47,7 +47,8 @@ public function create(int $postId, int $groupId): void
*
* @param integer $postId
* @param integer $groupId
* @return integer
*
* @return int|bool
*/
public function check(int $postId, int $groupId): int|bool
{
Expand All @@ -67,7 +68,8 @@ public function check(int $postId, int $groupId): int|bool
* Get last post
*
* @param integer $groupId
* @return void
*
* @return int
*/
public function getLastPost(string $groupName): int
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@
* @author aidsoul <[email protected]>
* @license MIT
*/
class Vkgroup extends Database implements VkgroupInterface
class VkgroupModel extends Database implements VkgroupInterface
{
/**
* @param string $tableName
* @param string $idGroup
* @param string $name
*/
public function __construct(
private readonly string $tableName = 'vkgroup',
private readonly string $idGroup = 'id_group',
private readonly string $name = 'name'
private string $tableName = 'vkgroup',
private string $idGroup = 'id_group',
private string $name = 'name'

) {
parent::__construct();
}

/**
* @param string $nameGroup
*
* @return void
*/
public function create(string $nameGroup): void
Expand All @@ -41,6 +42,7 @@ public function create(string $nameGroup): void

/**
* @param string $nameGroup
*
* @return integer|boolean
*/
public function check(string $nameGroup): int|bool
Expand All @@ -58,6 +60,7 @@ public function check(string $nameGroup): int|bool

/**
* @param integer|string $idGroup
*
* @return void
*/
public function remove(int|string $idGroup): void
Expand Down
10 changes: 5 additions & 5 deletions app/Settings/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Vktote\Config\Config;
use Vktote\Config\Vk;
use Vktote\DataBase\Models\Vkgroup;
use Vktote\DataBase\Models\VkgroupModel;
use Vktote\Settings\File\File;

/**
Expand All @@ -21,7 +21,7 @@ class Group
* @param string $pathIni
* @param string $pathPhp
*
* @return void
* @return array
*/
private function send(int $status, string $pathIni): array
{
Expand All @@ -40,7 +40,7 @@ private function send(int $status, string $pathIni): array
public function create(): string
{
$send = [];
$file = new File;
$file = new File();
$file->set($_POST['fileName']);

if (!is_dir($file->folder)) {
Expand Down Expand Up @@ -78,7 +78,7 @@ private function checkFileExist(string $file, int $status): void
*/
public function delete(string $dirName): string
{
$file = new File;
$file = new File();
$file->set($dirName);
$ret = [];
if (is_dir($file->folder)) {
Expand All @@ -87,7 +87,7 @@ public function delete(string $dirName): string
try {
// delete group from database
Config::set($file->iniFullPath);
$vk = new Vkgroup;
$vk = new VkgroupModel();
if ($idGroup = $vk->check(Vk::get()->idGroup)) {
$vk->remove($idGroup);
} else {
Expand Down
30 changes: 16 additions & 14 deletions app/Telegram/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Api implements ApiInterface
/**
* @var string
*/
private static string $link = '';
private string $link = '';

public function __construct(
private ClientInterface $client = new Client()
)
)
{
self::$link = 'https://api.telegram.org/bot' . T::get()->botApiKey;
$this->link = 'https://api.telegram.org/bot' . T::get()->botApiKey;
}

/**
Expand All @@ -34,12 +34,13 @@ public function __construct(
public function sendMessage(
string $text,
SendMessageInterface $message = new SendMessage()
): void {
): void
{
$this->client->get(
self::$link . '/sendMessage',
[
'query' => $message->send($text)
]
$this->link . '/sendMessage',
[
'query' => $message->send($text)
]
);
}

Expand All @@ -53,12 +54,13 @@ public function sendMediaGroup(
string $text,
array $media,
SendMediaGroupInterface $mediaGroup = new SendMediaGroup()
): void {
): void
{
$this->client->get(
self::$link . '/sendMediaGroup',
[
'query' => $mediaGroup->send($text, $media)
]
$this->link . '/sendMediaGroup',
[
'query' => $mediaGroup->send($text, $media)
]
);
}
}
}
6 changes: 3 additions & 3 deletions app/Telegram/Api/ApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function sendMediaGroup(
string $text,
array $media,
SendMediaGroupInterface $mediaGroup
): void;
): void;

/**
* @param string $text
Expand All @@ -32,5 +32,5 @@ public function sendMediaGroup(
public function sendMessage(
string $text,
SendMessageInterface $message
): void;
}
): void;
}
7 changes: 4 additions & 3 deletions app/Telegram/Api/SendMediaGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ class SendMediaGroup implements SendMediaGroupInterface
*/
public function send(string $text, array $media): array
{
$media[0]["caption"] = $text;
$media[0]['caption'] = $text;

return [
"chat_id" => T::get()->chatId,
"media" => json_encode($media)
'chat_id' => T::get()->chatId,
'media' => json_encode($media),
'disable_web_page_preview' => true
];
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/Telegram/Api/SendMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class SendMessage implements SendMessageInterface
public function send(string $text): array
{
return [
"chat_id" => T::get()->chatId,
"text" => $text,
"parse_mode" => "html",
"disable_web_page_preview" => true
'chat_id' => T::get()->chatId,
'text' => $text,
'parse_mode' => 'html',
'disable_web_page_preview' => true
];
}
}
18 changes: 9 additions & 9 deletions app/Telegram/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Vktote\Telegram;

use Vktote\DataBase\Models\Post;
use Vktote\DataBase\Models\Vkgroup;
use Vktote\DataBase\Models\PostModel;
use Vktote\DataBase\Models\VkgroupModel;

/**
* A class for checking the existence of data in a database
Expand All @@ -20,7 +20,7 @@ class Check
*/
private static function checkIfExistGroup(string|int $groupName): int
{
$vkGroup = new Vkgroup;
$vkGroup = new VkgroupModel();
$getVkGroup = $vkGroup->check($groupName);
if (!$getVkGroup) {
$vkGroup->create($groupName);
Expand All @@ -35,16 +35,16 @@ private static function checkIfExistGroup(string|int $groupName): int
*
* @return bool
*/
public static function checkIfExistPost(int $postId, string $groupName): bool
public static function checkIfExistPost(int $postId, string $groupId): bool
{
$status = false;
$groupId = self::checkIfExistGroup($groupName);
$post = new Post;
if (!$post->check($postId, $groupId)) {
$post->create($postId, $groupId);
$group = self::checkIfExistGroup($groupId);
$post = new PostModel();
if (!$post->check($postId, $group)) {
$post->create($postId, $group);
$status = true;
}

return $status;
}
}
}
8 changes: 7 additions & 1 deletion app/Telegram/Functions/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@

use Vktote\Telegram\Html\Link;

/**
* Class Author
*
* @author aidsoul [email protected]
* @license MIT
*/
class Author
{
/**
* @param integer $author
*
* @return string
*/
public static function change(int $author): string
public function change(int $author): string
{
$link = 'https://vk.com/id';

Expand Down
32 changes: 32 additions & 0 deletions app/Telegram/Functions/FunctionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Vktote\Telegram\Functions;

/**
* Class Function Factory
*
* @author aidsoul [email protected]
* @license MIT
*/
class FunctionFactory
{
public function video()
{
return new Video();
}

public function link()
{
return new link();
}

public function text()
{
return new Text();
}

public function author()
{
return new Author();
}
}
Loading

0 comments on commit 9f9ff91

Please sign in to comment.