Add SetChatPermissions method to TgBotLib
This commit is contained in:
parent
db3500d46e
commit
307521debc
2 changed files with 54 additions and 1 deletions
|
@ -38,6 +38,7 @@
|
||||||
use TgBotLib\Methods\SendVideoNote;
|
use TgBotLib\Methods\SendVideoNote;
|
||||||
use TgBotLib\Methods\SendVoice;
|
use TgBotLib\Methods\SendVoice;
|
||||||
use TgBotLib\Methods\SetChatAdministratorCustomTitle;
|
use TgBotLib\Methods\SetChatAdministratorCustomTitle;
|
||||||
|
use TgBotLib\Methods\SetChatPermissions;
|
||||||
use TgBotLib\Methods\SetMessageReaction;
|
use TgBotLib\Methods\SetMessageReaction;
|
||||||
use TgBotLib\Methods\SetWebhook;
|
use TgBotLib\Methods\SetWebhook;
|
||||||
use TgBotLib\Methods\UnbanChatMember;
|
use TgBotLib\Methods\UnbanChatMember;
|
||||||
|
@ -82,6 +83,7 @@
|
||||||
case SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE = 'setChatAdministratorCustomTitle';
|
case SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE = 'setChatAdministratorCustomTitle';
|
||||||
case BAN_CHAT_SENDER_CHAT = 'banChatSenderChat';
|
case BAN_CHAT_SENDER_CHAT = 'banChatSenderChat';
|
||||||
case UNBAN_CHAT_SENDER_CHAT = 'unbanChatSenderChat';
|
case UNBAN_CHAT_SENDER_CHAT = 'unbanChatSenderChat';
|
||||||
|
case SET_CHAT_PERMISSIONS = 'setChatPermissions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a command on the provided bot with the given parameters.
|
* Executes a command on the provided bot with the given parameters.
|
||||||
|
@ -131,7 +133,8 @@
|
||||||
self::PROMOTE_CHAT_MEMBER => PromoteChatMember::execute($bot, $parameters),
|
self::PROMOTE_CHAT_MEMBER => PromoteChatMember::execute($bot, $parameters),
|
||||||
self::SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE => SetChatAdministratorCustomTitle::execute($bot, $parameters),
|
self::SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE => SetChatAdministratorCustomTitle::execute($bot, $parameters),
|
||||||
self::BAN_CHAT_SENDER_CHAT => BanChatSenderChat::execute($bot, $parameters),
|
self::BAN_CHAT_SENDER_CHAT => BanChatSenderChat::execute($bot, $parameters),
|
||||||
self::UNBAN_CHAT_SENDER_CHAT => UnbanChatSenderChat::execute($bot, $parameters)
|
self::UNBAN_CHAT_SENDER_CHAT => UnbanChatSenderChat::execute($bot, $parameters),
|
||||||
|
self::SET_CHAT_PERMISSIONS => SetChatPermissions::execute($bot, $parameters),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
50
src/TgBotLib/Methods/SetChatPermissions.php
Normal file
50
src/TgBotLib/Methods/SetChatPermissions.php
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TgBotLib\Methods;
|
||||||
|
|
||||||
|
use TgBotLib\Abstracts\Method;
|
||||||
|
use TgBotLib\Bot;
|
||||||
|
use TgBotLib\Enums\Methods;
|
||||||
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
|
|
||||||
|
class SetChatPermissions extends Method
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(Bot $bot, array $parameters = []): true
|
||||||
|
{
|
||||||
|
if($parameters['permissions'] instanceof ObjectTypeInterface)
|
||||||
|
{
|
||||||
|
$parameters['permissions'] = json_encode($parameters['permissions']->toArray());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$parameters['permissions'] = json_encode($parameters['permissions']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (bool)$bot->sendRequest(Methods::SET_CHAT_PERMISSIONS->value, $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function getRequiredParameters(): ?array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'chat_id',
|
||||||
|
'permissions'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function getOptionalParameters(): ?array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'use_independent_chat_permissions'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue