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
63a948dd
Commit
63a948dd
authored
Jan 05, 2017
by
Jack'lul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply suggestions from @noplanman
parent
4be04d4a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
45 deletions
+30
-45
cron.php
examples/cron.php
+2
-6
Telegram.php
src/Telegram.php
+28
-39
No files found.
examples/cron.php
View file @
63a948dd
...
...
@@ -23,9 +23,8 @@ $BOT_NAME = 'username_bot';
// 'database' => 'dbname',
//];
// Your command(s) to run, use associative array to pass arguments
$commands
=
[
'whoami'
,
'echo'
];
//$commands = ['echo' => 'I\'m a bot!'];
// Your command(s) to run, pass it just like in a message (arguments supported)
$commands
=
[
'/whoami'
,
'/echo I\'m a bot!'
];
try
{
// Create Telegram API object
...
...
@@ -63,9 +62,6 @@ try {
// Run user selected commands
$telegram
->
runCommands
(
$commands
);
// Run user selected commands and modify update array
//$telegram->runCommands($commands, ['message' => ['text' => 'Parameter']]);
}
catch
(
Longman\TelegramBot\Exception\TelegramException
$e
)
{
// Silence is golden!
//echo $e;
...
...
src/Telegram.php
View file @
63a948dd
...
...
@@ -835,13 +835,12 @@ class Telegram
* Run provided commands
*
* @param array $commands
* @param array $update
*
* @throws TelegramException
*/
public
function
runCommands
(
$commands
,
array
$update
=
[]
)
public
function
runCommands
(
$commands
)
{
if
(
!
is_array
(
$commands
))
{
if
(
!
is_array
(
$commands
)
||
empty
(
$commands
)
)
{
throw
new
TelegramException
(
'No command(s) provided!'
);
}
...
...
@@ -849,49 +848,39 @@ class Telegram
$result
=
Request
::
getMe
()
->
getResult
();
if
(
!
$result
)
{
throw
new
TelegramException
(
'Received invalid getMe result!'
);
if
(
!
$result
->
getId
()
)
{
throw
new
TelegramException
(
'Received
empty/
invalid getMe result!'
);
}
$bot_id
=
$result
->
getId
();
$bot_name
=
$result
->
getFirstName
();
$update_template
=
[
'update_id'
=>
0
,
'message'
=>
[
'message_id'
=>
0
,
'from'
=>
[
'id'
=>
$bot_id
,
'first_name'
=>
$bot_name
],
'date'
=>
time
(),
'chat'
=>
[
'id'
=>
$bot_id
,
'type'
=>
'private'
,
],
'text'
=>
''
]
];
$update
=
array_merge
(
$update_template
,
$update
);
$bot_id
=
$result
->
getId
();
$bot_name
=
$result
->
getFirstName
();
$bot_username
=
$result
->
getUsername
();
$this
->
enableAdmin
(
$bot_id
);
// Give bot access to admin commands
$this
->
getCommandsList
();
// Load full commands list
foreach
(
$commands
as
$command
=>
$parameter
)
{
if
(
is_numeric
(
$command
))
{
// if array/key is not associative $command will be integer and $parameter will be the actual command!
$command
=
$parameter
;
}
$temp_update
=
$update
;
if
(
$parameter
&&
$parameter
!=
$command
)
{
$temp_update
[
'message'
][
'text'
]
=
$parameter
;
}
$this
->
update
=
new
Update
(
$temp_update
);
// this prevents commands throwing exceptions about missing Update objects
foreach
(
$commands
as
$command
)
{
$this
->
update
=
new
Update
(
[
'update_id'
=>
0
,
'message'
=>
[
'message_id'
=>
0
,
'from'
=>
[
'id'
=>
$bot_id
,
'first_name'
=>
$bot_name
,
'username'
=>
$bot_username
],
'date'
=>
time
(),
'chat'
=>
[
'id'
=>
$bot_id
,
'type'
=>
'private'
,
],
'text'
=>
$command
]
]
);
$this
->
executeCommand
(
$
command
);
$this
->
executeCommand
(
$
this
->
update
->
getMessage
()
->
getCommand
()
);
}
}
}
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