Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
98f13b08
Commit
98f13b08
authored
Jul 05, 2016
by
Marco Boretto
Committed by
GitHub
Jul 05, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #240 from noplanman/230-flexible-methods
Add flexible methods
parents
7d75d16c
2f242074
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
16 deletions
+119
-16
Telegram.php
src/Telegram.php
+47
-16
TelegramTest.php
tests/Unit/TelegramTest.php
+72
-0
No files found.
src/Telegram.php
View file @
98f13b08
...
...
@@ -459,20 +459,34 @@ class Telegram
}
/**
* Enable
Admin A
ccount
* Enable
a single Admin a
ccount
*
* @param
array $admins_list List of admins
* @param
integer $admin_id Single admin id
*
* @return
string
* @return
Telegram
*/
public
function
enableAdmin
s
(
array
$admins_list
)
public
function
enableAdmin
(
$admin_id
)
{
foreach
(
$admins_list
as
$admin
)
{
if
(
$admin
>
0
)
{
$this
->
admins_list
[]
=
$admin
;
if
(
is_int
(
$admin_id
)
&&
$admin_id
>
0
&&
!
in_array
(
$admin_id
,
$this
->
admins_list
))
{
$this
->
admins_list
[]
=
$admin_id
;
}
else
{
throw
new
TelegramException
(
'Invalid value "'
.
$admin
.
'" for admin!
'
);
TelegramLog
::
error
(
'Invalid value "'
.
$admin_id
.
'" for admin.
'
);
}
return
$this
;
}
/**
* Enable a list of Admin Accounts
*
* @param array $admin_ids List of admin ids
*
* @return Telegram
*/
public
function
enableAdmins
(
array
$admin_ids
)
{
foreach
(
$admin_ids
as
$admin_id
)
{
$this
->
enableAdmin
(
$admin_id
);
}
return
$this
;
...
...
@@ -531,25 +545,42 @@ class Telegram
}
/**
* Add custom commands path
* Add
a single
custom commands path
*
* @param string $path Custom commands path
* @param string $path Custom commands path
to add
* @param bool $before If the path should be prepended or appended to the list
*
* @return
\Longman\TelegramBot\
Telegram
* @return Telegram
*/
public
function
addCommandsPath
(
$path
,
$before
=
true
)
{
if
(
!
is_dir
(
$path
))
{
throw
new
TelegramException
(
'Commands path "'
.
$path
.
'" does not exist!'
);
}
if
(
!
in_array
(
$path
,
$this
->
commands_paths
))
{
TelegramLog
::
error
(
'Commands path "'
.
$path
.
'" does not exist.'
);
}
elseif
(
!
in_array
(
$path
,
$this
->
commands_paths
))
{
if
(
$before
)
{
array_unshift
(
$this
->
commands_paths
,
$path
);
}
else
{
array_push
(
$this
->
commands_paths
,
$path
);
}
}
return
$this
;
}
/**
* Add multiple custom commands paths
*
* @param array $paths Custom commands paths to add
* @param bool $before If the paths should be prepended or appended to the list
*
* @return Telegram
*/
public
function
addCommandsPaths
(
array
$paths
,
$before
=
true
)
{
foreach
(
$paths
as
$path
)
{
$this
->
addCommandsPath
(
$path
);
}
return
$this
;
}
...
...
tests/Unit/TelegramTest.php
View file @
98f13b08
...
...
@@ -26,12 +26,37 @@ class TelegramTest extends TestCase
*/
private
$telegram
;
/**
* @var array
*/
private
$custom_commands_paths
=
[
'/tmp/php-telegram-bot-custom-commands-1'
,
'/tmp/php-telegram-bot-custom-commands-2'
,
'/tmp/php-telegram-bot-custom-commands-3'
,
];
/**
* setUp
*/
protected
function
setUp
()
{
$this
->
telegram
=
new
Telegram
(
'testapikey'
,
'testbotname'
);
// Create a few custom commands paths.
foreach
(
$this
->
custom_commands_paths
as
$custom_path
)
{
mkdir
(
$custom_path
);
}
}
/**
* tearDown
*/
protected
function
tearDown
()
{
// Clean up the custom commands paths.
foreach
(
$this
->
custom_commands_paths
as
$custom_path
)
{
rmdir
(
$custom_path
);
}
}
/**
...
...
@@ -68,6 +93,53 @@ class TelegramTest extends TestCase
$this
->
assertEquals
(
'testbotname'
,
$this
->
telegram
->
getBotName
());
}
/**
* @test
*/
public
function
enableAdmins
()
{
$tg
=
&
$this
->
telegram
;
$this
->
assertEmpty
(
$tg
->
getAdminList
());
$tg
->
enableAdmin
(
1
);
$this
->
assertCount
(
1
,
$tg
->
getAdminList
());
$tg
->
enableAdmins
([
2
,
3
]);
$this
->
assertCount
(
3
,
$tg
->
getAdminList
());
$tg
->
enableAdmin
(
2
);
$this
->
assertCount
(
3
,
$tg
->
getAdminList
());
$tg
->
enableAdmin
(
'a string?'
);
$this
->
assertCount
(
3
,
$tg
->
getAdminList
());
}
/**
* @test
*/
public
function
addCustomCommandsPaths
()
{
$tg
=
&
$this
->
telegram
;
$this
->
assertAttributeCount
(
1
,
'commands_paths'
,
$tg
);
$tg
->
addCommandsPath
(
$this
->
custom_commands_paths
[
0
]);
$this
->
assertAttributeCount
(
2
,
'commands_paths'
,
$tg
);
$tg
->
addCommandsPath
(
'/invalid/path'
);
$this
->
assertAttributeCount
(
2
,
'commands_paths'
,
$tg
);
$tg
->
addCommandsPaths
([
$this
->
custom_commands_paths
[
1
],
$this
->
custom_commands_paths
[
2
],
]);
$this
->
assertAttributeCount
(
4
,
'commands_paths'
,
$tg
);
$tg
->
addCommandsPath
(
$this
->
custom_commands_paths
[
0
]);
$this
->
assertAttributeCount
(
4
,
'commands_paths'
,
$tg
);
}
/**
* @test
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment