Commit a604aa67 authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #456 from jacklul/no_default_commands

No default commands
parents 25d74af0 f284c84c
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
/**
* Callback query command
*/
class CallbackqueryCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'callbackquery';
/**
* @var string
*/
protected $description = 'Reply to callback query';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$update = $this->getUpdate();
$callback_query = $update->getCallbackQuery();
$callback_query_id = $callback_query->getId();
$callback_data = $callback_query->getData();
$data = [
'callback_query_id' => $callback_query_id,
'text' => 'Hello World!',
'show_alert' => $callback_data === 'thumb up',
'cache_time' => 5,
];
return Request::answerCallbackQuery($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Channel chat created command
*/
class ChannelchatcreatedCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Channelchatcreated';
/**
* @var string
*/
protected $description = 'Channel chat created';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$channel_chat_created = $message->getChannelChatCreated();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Channel post command
*/
class ChannelpostCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Channelpost';
/**
* @var string
*/
protected $description = 'Handle channel post';
/**
* @var string
*/
protected $version = '1.0.0';
/**
* Execute command
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$channel_post = $this->getUpdate()->getChannelPost();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Chosen inline result command
*/
class ChoseninlineresultCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'choseninlineresult';
/**
* @var string
*/
protected $description = 'Chosen result query';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//Information about chosen result is returned
//$update = $this->getUpdate();
//$inline_query = $update->getChosenInlineResult();
//$query = $inline_query->getQuery();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Delete chat photo command
*/
class DeletechatphotoCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Deletechatphoto';
/**
* @var string
*/
protected $description = 'Delete chat photo';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$delete_chat_photo = $message->getDeleteChatPhoto();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Edited channel post command
*/
class EditedchannelpostCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Editedchannelpost';
/**
* @var string
*/
protected $description = 'Handle edited channel post';
/**
* @var string
*/
protected $version = '1.0.0';
/**
* Execute command
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$edited_channel_post = $this->getUpdate()->getEditedChannelPost();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Edited message command
*/
class EditedmessageCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'editedmessage';
/**
* @var string
*/
protected $description = 'User edited message';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$update = $this->getUpdate();
//$edited_message = $update->getEditedMessage();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
/**
* Generic command
*/
class GenericCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Generic';
/**
* @var string
*/
protected $description = 'Handles generic commands or is executed by default when a command is not found';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
//You can use $command as param
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$command = $message->getCommand();
//If the user is and admin and the command is in the format "/whoisXYZ", call the /whois command
if (stripos($command, 'whois') === 0 && $this->telegram->isAdmin($user_id)) {
return $this->telegram->executeCommand('whois');
}
$data = [
'chat_id' => $chat_id,
'text' => 'Command /' . $command . ' not found.. :(',
];
return Request::sendMessage($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Generic message command
*/
class GenericmessageCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Genericmessage';
/**
* @var string
*/
protected $description = 'Handle generic message';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* @var bool
*/
protected $need_mysql = true;
/**
* Execution if MySQL is required but not available
*
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
public function executeNoDb()
{
//Do nothing
return Request::emptyResponse();
}
/**
* Execute command
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//If a conversation is busy, execute the conversation command after handling the message
$conversation = new Conversation(
$this->getMessage()->getFrom()->getId(),
$this->getMessage()->getChat()->getId()
);
//Fetch conversation command if it exists and execute it
if ($conversation->exists() && ($command = $conversation->getCommand())) {
return $this->telegram->executeCommand($command);
}
return Request::emptyResponse();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Group chat created command
*/
class GroupchatcreatedCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Groupchatcreated';
/**
* @var string
*/
protected $description = 'Group chat created';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$group_chat_created = $message->getGroupChatCreated();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResultArticle;
use Longman\TelegramBot\Entities\InputMessageContent\InputTextMessageContent;
use Longman\TelegramBot\Request;
/**
* Inline query command
*/
class InlinequeryCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'inlinequery';
/**
* @var string
*/
protected $description = 'Reply to inline query';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$update = $this->getUpdate();
$inline_query = $update->getInlineQuery();
$query = $inline_query->getQuery();
$data = ['inline_query_id' => $inline_query->getId()];
$results = [];
if ($query !== '') {
$articles = [
[
'id' => '001',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]),
],
[
'id' => '002',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]),
],
[
'id' => '003',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]),
],
];
foreach ($articles as $article) {
$results[] = new InlineQueryResultArticle($article);
}
}
$data['results'] = '[' . implode(',', $results) . ']';
return Request::answerInlineQuery($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Left chat member command
*/
class LeftchatmemberCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Leftchatmember';
/**
* @var string
*/
protected $description = 'Left Chat Member';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$member = $message->getLeftChatMember();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Migrate from chat id command
*/
class MigratefromchatidCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Migratefromchatid';
/**
* @var string
*/
protected $description = 'Migrate from chat id';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$migrate_from_chat_id = $message->getMigrateFromChatId();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Migrate to chat id command
*/
class MigratetochatidCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Migratetochatid';
/**
* @var string
*/
protected $description = 'Migrate to chat id';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$migrate_to_chat_id = $message->getMigrateToChatId();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
/**
* New chat member command
*/
class NewchatmemberCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Newchatmember';
/**
* @var string
*/
protected $description = 'New Chat Member';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$member = $message->getNewChatMember();
$text = 'Hi there!';
if (!$message->botAddedInChat()) {
$text = 'Hi ' . $member->tryMention() . '!';
}
$data = [
'chat_id' => $chat_id,
'text' => $text,
];
return Request::sendMessage($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* New chat photo command
*/
class NewchatphotoCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Newchatphoto';
/**
* @var string
*/
protected $description = 'New chat Photo';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$new_chat_photo = $message->getNewChatPhoto();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* New chat title command
*/
class NewchattitleCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Newchattitle';
/**
* @var string
*/
protected $description = 'New chat Title';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$new_chat_title = $message->getNewChatTitle();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Pinned message command
*/
class PinnedmessageCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Pinnedmessage';
/**
* @var string
*/
protected $description = 'Message was pinned';
/**
* @var string
*/
protected $version = '1.0.0';
/**
* Execute command
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$pinned_message = $message->getPinnedMessage();
return parent::execute();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
/**
* Start command
*/
class StartCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'start';
/**
* @var string
*/
protected $description = 'Start command';
/**
* @var string
*/
protected $usage = '/start';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = 'Hi there!' . PHP_EOL . 'Type /help to see all commands!';
$data = [
'chat_id' => $chat_id,
'text' => $text,
];
return Request::sendMessage($data);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Super group chat created command
*/
class SupergroupchatcreatedCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'Supergroupchatcreated';
/**
* @var string
*/
protected $description = 'Super group chat created';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
//$message = $this->getMessage();
//$supergroup_chat_created = $message->getSuperGroupChatCreated();
return parent::execute();
}
}
......@@ -42,7 +42,10 @@ try {
// Enable MySQL with table prefix
//$telegram->enableMySql($mysql_credentials, $BOT_NAME . '_');
// Add an additional commands path
// Uncomment this line to load example commands
//$telegram->addCommandsPath(BASE_PATH . '/../examples/Commands');
// Add commands path containing your commands
//$telegram->addCommandsPath($commands_path);
// Enable admin user(s)
......
......@@ -43,7 +43,10 @@ try {
// Enable MySQL with table prefix
//$telegram->enableMySql($mysql_credentials, $BOT_NAME . '_');
// Add an additional commands path
// Uncomment this line to load example commands
//$telegram->addCommandsPath(BASE_PATH . '/../examples/Commands');
// Add commands path containing your commands
//$telegram->addCommandsPath($commands_path);
// Enable admin user(s)
......
......@@ -42,7 +42,10 @@ try {
// Enable MySQL with table prefix
//$telegram->enableMySql($mysql_credentials, $BOT_NAME . '_');
// Add an additional commands path
// Uncomment this line to load example commands
//$telegram->addCommandsPath(BASE_PATH . '/../examples/Commands');
// Add commands path containing your commands
//$telegram->addCommandsPath($commands_path);
// Enable admin user(s)
......
......@@ -31,7 +31,7 @@ class CallbackqueryCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......@@ -41,18 +41,11 @@ class CallbackqueryCommand extends SystemCommand
*/
public function execute()
{
$update = $this->getUpdate();
$callback_query = $update->getCallbackQuery();
$callback_query_id = $callback_query->getId();
$callback_data = $callback_query->getData();
//$callback_query = $this->getUpdate()->getCallbackQuery();
//$user_id = $callback_query->getFrom()->getId();
//$query_id = $callback_query->getId();
//$query_data = $callback_query->getData();
$data = [
'callback_query_id' => $callback_query_id,
'text' => 'Hello World!',
'show_alert' => $callback_data === 'thumb up',
'cache_time' => 5,
];
return Request::answerCallbackQuery($data);
return Request::answerCallbackQuery(['callback_query_id' => $this->getUpdate()->getCallbackQuery()->getId()]);
}
}
......@@ -30,7 +30,7 @@ class ChannelchatcreatedCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -30,7 +30,7 @@ class ChoseninlineresultCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -30,7 +30,7 @@ class DeletechatphotoCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -30,7 +30,7 @@ class EditedmessageCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -31,7 +31,7 @@ class GenericCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......@@ -41,23 +41,12 @@ class GenericCommand extends SystemCommand
*/
public function execute()
{
$message = $this->getMessage();
//$message = $this->getMessage();
//$chat_id = $message->getChat()->getId();
//$user_id = $message->getFrom()->getId();
//$command = $message->getCommand();
//#text = trim($message->getText(true));
//You can use $command as param
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$command = $message->getCommand();
//If the user is and admin and the command is in the format "/whoisXYZ", call the /whois command
if (stripos($command, 'whois') === 0 && $this->telegram->isAdmin($user_id)) {
return $this->telegram->executeCommand('whois');
}
$data = [
'chat_id' => $chat_id,
'text' => 'Command /' . $command . ' not found.. :(',
];
return Request::sendMessage($data);
return parent::execute();
}
}
......@@ -63,6 +63,7 @@ class GenericmessageCommand extends SystemCommand
$this->getMessage()->getFrom()->getId(),
$this->getMessage()->getChat()->getId()
);
//Fetch conversation command if it exists and execute it
if ($conversation->exists() && ($command = $conversation->getCommand())) {
return $this->telegram->executeCommand($command);
......
......@@ -30,7 +30,7 @@ class GroupchatcreatedCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -33,7 +33,7 @@ class InlinequeryCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......@@ -43,42 +43,10 @@ class InlinequeryCommand extends SystemCommand
*/
public function execute()
{
$update = $this->getUpdate();
$inline_query = $update->getInlineQuery();
$query = $inline_query->getQuery();
//$inline_query = $this->getUpdate()->getInlineQuery();
//$user_id = $inline_query->getFrom()->getId();
//$query = $inline_query->getQuery();
$data = ['inline_query_id' => $inline_query->getId()];
$results = [];
if ($query !== '') {
$articles = [
[
'id' => '001',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]),
],
[
'id' => '002',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]),
],
[
'id' => '003',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]),
],
];
foreach ($articles as $article) {
$results[] = new InlineQueryResultArticle($article);
}
}
$data['results'] = '[' . implode(',', $results) . ']';
return Request::answerInlineQuery($data);
return Request::answerInlineQuery(['inline_query_id' => $this->getUpdate()->getInlineQuery()->getId()]);
}
}
......@@ -30,7 +30,7 @@ class LeftchatmemberCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -30,7 +30,7 @@ class MigratefromchatidCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -30,7 +30,7 @@ class MigratetochatidCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -31,7 +31,7 @@ class NewchatmemberCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -30,7 +30,7 @@ class NewchatphotoCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -30,7 +30,7 @@ class NewchattitleCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -36,7 +36,7 @@ class StartCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......@@ -46,16 +46,10 @@ class StartCommand extends SystemCommand
*/
public function execute()
{
$message = $this->getMessage();
//$message = $this->getMessage();
//$chat_id = $message->getChat()->getId();
//$user_id = $message->getFrom()->getId();
$chat_id = $message->getChat()->getId();
$text = 'Hi there!' . PHP_EOL . 'Type /help to see all commands!';
$data = [
'chat_id' => $chat_id,
'text' => $text,
];
return Request::sendMessage($data);
return parent::execute();
}
}
......@@ -30,7 +30,7 @@ class SupergroupchatcreatedCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.0.0';
/**
* Command execute method
......
......@@ -415,8 +415,6 @@ class Telegram
$this->addCommandsPath(BASE_COMMANDS_PATH . '/AdminCommands', false);
}
$this->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands', false);
$type = $message->getType();
if ($type === 'command') {
$command = $message->getCommand();
......
......@@ -38,7 +38,6 @@ class CommandTestCase extends TestCase
public function setUp()
{
$this->telegram = new Telegram(self::$dummy_api_key, 'testbot');
$this->telegram->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands');
// Add custom commands dedicated to do some tests.
$this->telegram->addCommandsPath(__DIR__ . '/CustomTestCommands');
......
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Tests\Unit\Commands\UserCommands;
use Longman\TelegramBot\Tests\Unit\Commands\CommandTestCase;
use Longman\TelegramBot\Tests\Unit\TestHelpers;
use Longman\TelegramBot\Commands\UserCommands\EchoCommand;
/**
* @package TelegramTest
* @author Avtandil Kikabidze <akalongman@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
class EchoCommandTest extends CommandTestCase
{
/**
* setUp
*/
public function setUp()
{
parent::setUp();
$this->command = new EchoCommand($this->telegram);
}
public function testEchoCommandProperties()
{
$this->assertAttributeEquals('echo', 'name', $this->command);
$this->assertAttributeEquals('Show text', 'description', $this->command);
$this->assertAttributeEquals('/echo <text>', 'usage', $this->command);
}
public function testEchoCommandExecuteWithoutParameter()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/echo'))
->execute()
->getResult()
->getText();
$this->assertEquals('Command usage: /echo <text>', $text);
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/echo '))
->execute()
->getResult()
->getText();
$this->assertEquals('Command usage: /echo <text>', $text);
}
public function testEchoCommandExecuteWithParameter()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/echo Message!'))
->execute()
->getResult()
->getText();
$this->assertEquals('Message!', $text);
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Tests\Unit\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommands\HelpCommand;
use Longman\TelegramBot\Tests\Unit\Commands\CommandTestCase;
use Longman\TelegramBot\Tests\Unit\TestHelpers;
/**
* @package TelegramTest
* @author Avtandil Kikabidze <akalongman@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
class HelpCommandTest extends CommandTestCase
{
/**
* setUp
*/
public function setUp()
{
parent::setUp();
$this->command = new HelpCommand($this->telegram);
}
public function testHelpCommandProperties()
{
$this->assertAttributeEquals('help', 'name', $this->command);
$this->assertAttributeEquals('Show bot commands help', 'description', $this->command);
$this->assertAttributeEquals('/help or /help <command>', 'usage', $this->command);
}
public function testHelpCommandExecuteWithoutParameter()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/help'))
->execute()
->getResult()
->getText();
$this->assertContains(
'testbot v. ' . $this->telegram->getVersion() . "\n\nCommands List:",
$text
);
}
public function testHelpCommandExecuteWithParameterInvalidCommand()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/help invalidcommand'))
->execute()
->getResult()
->getText();
$this->assertEquals('No help available: Command /invalidcommand not found', $text);
}
public function testHelpCommandExecuteWithParameterValidCommand()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/help echo'))
->execute()
->getResult()
->getText();
$this->assertContains("Description: Show text\nUsage: /echo <text>", $text);
}
public function testHelpCommandWithHiddenCommand()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/help'))
->execute()
->getResult()
->getText();
$this->assertContains('/visible', $text);
$this->assertNotContains('/hidden', $text);
}
}
......@@ -159,10 +159,4 @@ class TelegramTest extends TestCase
$this->assertInternalType('array', $commands);
$this->assertNotCount(0, $commands);
}
public function testGetHelpCommandObject()
{
$command = $this->telegram->getCommandObject('help');
$this->assertInstanceOf('Longman\TelegramBot\Commands\UserCommands\HelpCommand', $command);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment