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
3a579eab
Commit
3a579eab
authored
Jul 03, 2015
by
LONGMAN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes
parent
e7c9e56f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
5 deletions
+61
-5
Command.php
src/Command.php
+25
-2
HelpCommand.php
src/Commands/HelpCommand.php
+2
-0
Telegram.php
src/Telegram.php
+34
-3
.gitkeep
tests/.gitkeep
+0
-0
No files found.
src/Command.php
View file @
3a579eab
...
...
@@ -13,14 +13,22 @@ use Longman\TelegramBot\Entities\Update;
abstract
class
Command
{
protected
$telegram
;
protected
$update
;
protected
$message
;
protected
$command
;
public
function
__construct
(
Update
$update
)
{
protected
$usage
=
'Command help text'
;
protected
$version
=
'1.0.0'
;
public
function
__construct
(
Telegram
$telegram
)
{
$this
->
telegram
=
$telegram
;
}
public
function
setUpdate
(
Update
$update
)
{
$this
->
update
=
$update
;
$this
->
message
=
$this
->
update
->
getMessage
();
return
$this
;
}
...
...
@@ -35,11 +43,26 @@ abstract class Command
return
$this
->
message
;
}
public
function
getTelegram
()
{
return
$this
->
telegram
;
}
public
function
setCommand
(
$command
)
{
$this
->
command
=
$command
;
return
$this
;
}
public
function
getUsage
()
{
return
$this
->
usage
;
}
public
function
getVersion
()
{
return
$this
->
version
;
}
public
function
getHelp
()
{
return
$this
->
getUsage
()
.
"
\n
"
.
$this
->
getVersion
();
}
}
src/Commands/HelpCommand.php
View file @
3a579eab
...
...
@@ -15,6 +15,8 @@ use Longman\TelegramBot\Entities\Update;
class
HelpCommand
extends
Command
{
protected
$usage
=
'Usage: /help <command>'
;
protected
$version
=
'1.0.0'
;
public
function
execute
()
{
$update
=
$this
->
getUpdate
();
...
...
src/Telegram.php
View file @
3a579eab
...
...
@@ -128,6 +128,29 @@ class Telegram
return
$this
->
update
;
}
/**
* Get commands list
*
* @return string $update
*/
public
function
getCommandsList
()
{
// iterate files
// getCommandClass
return
$this
->
update
;
}
/**
* Set log requests
*
...
...
@@ -229,7 +252,7 @@ class Telegram
*
* @return object
*/
protected
function
getCommandClass
(
$command
,
Update
$update
)
{
protected
function
getCommandClass
(
$command
,
Update
$update
=
null
)
{
$this
->
commands_dir
=
array_unique
(
$this
->
commands_dir
);
$this
->
commands_dir
=
array_reverse
(
$this
->
commands_dir
);
$class_name
=
ucfirst
(
$command
)
.
'Command'
;
...
...
@@ -237,13 +260,21 @@ class Telegram
foreach
(
$this
->
commands_dir
as
$dir
)
{
if
(
is_file
(
$dir
.
'/'
.
$class_name
.
'.php'
))
{
require_once
(
$dir
.
'/'
.
$class_name
.
'.php'
);
$class
=
new
$class_name
(
$update
);
$class
=
new
$class_name
(
$this
);
if
(
!
empty
(
$update
))
{
$class
->
setUpdate
(
$update
);
}
return
$class
;
}
}
$class_name
=
__NAMESPACE__
.
'\\Commands\\'
.
$class_name
;
$class
=
new
$class_name
(
$update
);
$class
=
new
$class_name
(
$this
);
if
(
!
empty
(
$update
))
{
$class
->
setUpdate
(
$update
);
}
if
(
is_object
(
$class
))
{
return
$class
;
}
...
...
test/.gitkeep
→
test
s
/.gitkeep
View file @
3a579eab
File moved
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