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
84cd8f50
Commit
84cd8f50
authored
Aug 24, 2016
by
Avtandil Kikabidze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved code and doc-blocks in admin and user commands
parent
e986a12d
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
426 additions
and
234 deletions
+426
-234
AdminCommand.php
src/Commands/AdminCommand.php
+0
-3
ChatsCommand.php
src/Commands/AdminCommands/ChatsCommand.php
+28
-13
SendtoallCommand.php
src/Commands/AdminCommands/SendtoallCommand.php
+22
-7
SendtochannelCommand.php
src/Commands/AdminCommands/SendtochannelCommand.php
+80
-60
WhoisCommand.php
src/Commands/AdminCommands/WhoisCommand.php
+37
-20
Command.php
src/Commands/Command.php
+2
-5
SystemCommand.php
src/Commands/SystemCommand.php
+1
-4
UserCommand.php
src/Commands/UserCommand.php
+0
-3
CancelCommand.php
src/Commands/UserCommands/CancelCommand.php
+31
-10
DateCommand.php
src/Commands/UserCommands/DateCommand.php
+26
-11
EchoCommand.php
src/Commands/UserCommands/EchoCommand.php
+18
-5
HelpCommand.php
src/Commands/UserCommands/HelpCommand.php
+19
-6
SlapCommand.php
src/Commands/UserCommands/SlapCommand.php
+19
-6
SurveyCommand.php
src/Commands/UserCommands/SurveyCommand.php
+84
-53
WeatherCommand.php
src/Commands/UserCommands/WeatherCommand.php
+23
-9
WhoamiCommand.php
src/Commands/UserCommands/WhoamiCommand.php
+36
-19
No files found.
src/Commands/AdminCommand.php
View file @
84cd8f50
...
@@ -10,9 +10,6 @@
...
@@ -10,9 +10,6 @@
namespace
Longman\TelegramBot\Commands
;
namespace
Longman\TelegramBot\Commands
;
/**
* Abstract Admin Command Class
*/
abstract
class
AdminCommand
extends
Command
abstract
class
AdminCommand
extends
Command
{
{
...
...
src/Commands/AdminCommands/ChatsCommand.php
View file @
84cd8f50
...
@@ -15,23 +15,37 @@ use Longman\TelegramBot\DB;
...
@@ -15,23 +15,37 @@ use Longman\TelegramBot\DB;
use
Longman\TelegramBot\Entities\Chat
;
use
Longman\TelegramBot\Entities\Chat
;
use
Longman\TelegramBot\Request
;
use
Longman\TelegramBot\Request
;
/**
* Admin "/chats" command
*/
class
ChatsCommand
extends
AdminCommand
class
ChatsCommand
extends
AdminCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'chats'
;
protected
$name
=
'chats'
;
/**
* @var string
*/
protected
$description
=
'List or search all chats stored by the bot'
;
protected
$description
=
'List or search all chats stored by the bot'
;
/**
* @var string
*/
protected
$usage
=
'/chats, /chats * or /chats <search string>'
;
protected
$usage
=
'/chats, /chats * or /chats <search string>'
;
/**
* @var string
*/
protected
$version
=
'1.0.2'
;
protected
$version
=
'1.0.2'
;
/**
* @var bool
*/
protected
$need_mysql
=
true
;
protected
$need_mysql
=
true
;
/**#@-*/
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
@@ -69,7 +83,8 @@ class ChatsCommand extends AdminCommand
...
@@ -69,7 +83,8 @@ class ChatsCommand extends AdminCommand
$whois
=
$chat
->
getId
();
$whois
=
$chat
->
getId
();
if
(
$this
->
telegram
->
getCommandObject
(
'whois'
))
{
if
(
$this
->
telegram
->
getCommandObject
(
'whois'
))
{
$whois
=
'/whois'
.
str_replace
(
'-'
,
'g'
,
$chat
->
getId
());
//We can't use '-' in command because part of it will become unclickable
$whois
=
'/whois'
.
str_replace
(
'-'
,
'g'
,
$chat
->
getId
());
//We can't use '-' in command because part of it will become unclickable
}
}
if
(
$chat
->
isPrivateChat
())
{
if
(
$chat
->
isPrivateChat
())
{
...
@@ -102,7 +117,7 @@ class ChatsCommand extends AdminCommand
...
@@ -102,7 +117,7 @@ class ChatsCommand extends AdminCommand
$text_back
.=
"
\n
"
.
'Total: '
.
(
$user_chats
+
$group_chats
+
$super_group_chats
);
$text_back
.=
"
\n
"
.
'Total: '
.
(
$user_chats
+
$group_chats
+
$super_group_chats
);
if
(
$text
===
''
)
{
if
(
$text
===
''
)
{
$text_back
.=
"
\n\n
"
.
'List all chats: /'
.
$this
->
name
.
' *'
.
"
\n
"
.
'Search for chats: /'
.
$this
->
name
.
' <search string>'
;
$text_back
.=
"
\n\n
"
.
'List all chats: /'
.
$this
->
name
.
' *'
.
"
\n
"
.
'Search for chats: /'
.
$this
->
name
.
' <search string>'
;
}
}
}
}
...
...
src/Commands/AdminCommands/SendtoallCommand.php
View file @
84cd8f50
...
@@ -18,15 +18,30 @@ use Longman\TelegramBot\Request;
...
@@ -18,15 +18,30 @@ use Longman\TelegramBot\Request;
*/
*/
class
SendtoallCommand
extends
AdminCommand
class
SendtoallCommand
extends
AdminCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'sendtoall'
;
protected
$name
=
'sendtoall'
;
/**
* @var string
*/
protected
$description
=
'Send the message to all the user\'s bot'
;
protected
$description
=
'Send the message to all the user\'s bot'
;
/**
* @var string
*/
protected
$usage
=
'/sendtoall <message to send>'
;
protected
$usage
=
'/sendtoall <message to send>'
;
/**
* @var string
*/
protected
$version
=
'1.2.1'
;
protected
$version
=
'1.2.1'
;
/**
* @var bool
*/
protected
$need_mysql
=
true
;
protected
$need_mysql
=
true
;
/**#@-*/
/**
/**
* Execute command
* Execute command
...
...
src/Commands/AdminCommands/SendtochannelCommand.php
View file @
84cd8f50
...
@@ -20,15 +20,30 @@ use Longman\TelegramBot\Exception\TelegramException;
...
@@ -20,15 +20,30 @@ use Longman\TelegramBot\Exception\TelegramException;
class
SendtochannelCommand
extends
AdminCommand
class
SendtochannelCommand
extends
AdminCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'sendtochannel'
;
protected
$name
=
'sendtochannel'
;
/**
* @var string
*/
protected
$description
=
'Send message to a channel'
;
protected
$description
=
'Send message to a channel'
;
/**
* @var string
*/
protected
$usage
=
'/sendtochannel <message to send>'
;
protected
$usage
=
'/sendtochannel <message to send>'
;
/**
* @var string
*/
protected
$version
=
'0.1.4'
;
protected
$version
=
'0.1.4'
;
/**
* @var bool
*/
protected
$need_mysql
=
true
;
protected
$need_mysql
=
true
;
/**#@-*/
/**
/**
* Conversation Object
* Conversation Object
...
@@ -38,7 +53,9 @@ class SendtochannelCommand extends AdminCommand
...
@@ -38,7 +53,9 @@ class SendtochannelCommand extends AdminCommand
protected
$conversation
;
protected
$conversation
;
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return \Longman\TelegramBot\Entities\ServerResponse|mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
@@ -57,7 +74,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -57,7 +74,7 @@ class SendtochannelCommand extends AdminCommand
// Conversation
// Conversation
$this
->
conversation
=
new
Conversation
(
$user_id
,
$chat_id
,
$this
->
getName
());
$this
->
conversation
=
new
Conversation
(
$user_id
,
$chat_id
,
$this
->
getName
());
$channels
=
(
array
)
$this
->
getConfig
(
'your_channel'
);
$channels
=
(
array
)
$this
->
getConfig
(
'your_channel'
);
if
(
!
isset
(
$this
->
conversation
->
notes
[
'state'
]))
{
if
(
!
isset
(
$this
->
conversation
->
notes
[
'state'
]))
{
$state
=
(
count
(
$channels
)
==
0
)
?
-
1
:
0
;
$state
=
(
count
(
$channels
)
==
0
)
?
-
1
:
0
;
$this
->
conversation
->
notes
[
'last_message_id'
]
=
$message
->
getMessageId
();
$this
->
conversation
->
notes
[
'last_message_id'
]
=
$message
->
getMessageId
();
...
@@ -96,7 +113,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -96,7 +113,7 @@ class SendtochannelCommand extends AdminCommand
}
}
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
[
[
'keyboard'
=>
$keyboard
,
'keyboard'
=>
$keyboard
,
'resize_keyboard'
=>
true
,
'resize_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'selective'
=>
true
'selective'
=>
true
...
@@ -139,7 +156,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -139,7 +156,7 @@ class SendtochannelCommand extends AdminCommand
$keyboard
=
[[
'Yes'
,
'No'
]];
$keyboard
=
[[
'Yes'
,
'No'
]];
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
[
[
'keyboard'
=>
$keyboard
,
'keyboard'
=>
$keyboard
,
'resize_keyboard'
=>
true
,
'resize_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'selective'
=>
true
'selective'
=>
true
...
@@ -162,7 +179,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -162,7 +179,7 @@ class SendtochannelCommand extends AdminCommand
$this
->
conversation
->
notes
[
'last_message_id'
]
=
$message
->
getMessageId
();
$this
->
conversation
->
notes
[
'last_message_id'
]
=
$message
->
getMessageId
();
// no break
// no break
case
3
:
case
3
:
if
((
$this
->
conversation
->
notes
[
'last_message_id'
]
==
$message
->
getMessageId
()
||
$type
!=
'Message'
)
&&
$this
->
conversation
->
notes
[
'set_caption'
])
{
if
((
$this
->
conversation
->
notes
[
'last_message_id'
]
==
$message
->
getMessageId
()
||
$type
!=
'Message'
)
&&
$this
->
conversation
->
notes
[
'set_caption'
])
{
$this
->
conversation
->
notes
[
'state'
]
=
3
;
$this
->
conversation
->
notes
[
'state'
]
=
3
;
$this
->
conversation
->
update
();
$this
->
conversation
->
update
();
...
@@ -195,7 +212,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -195,7 +212,7 @@ class SendtochannelCommand extends AdminCommand
$keyboard
=
[[
'Yes'
,
'No'
]];
$keyboard
=
[[
'Yes'
,
'No'
]];
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
[
[
'keyboard'
=>
$keyboard
,
'keyboard'
=>
$keyboard
,
'resize_keyboard'
=>
true
,
'resize_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'selective'
=>
true
'selective'
=>
true
...
@@ -233,7 +250,9 @@ class SendtochannelCommand extends AdminCommand
...
@@ -233,7 +250,9 @@ class SendtochannelCommand extends AdminCommand
}
}
/**
/**
* {@inheritdoc}
* Execute without db
*
* @return mixed
*/
*/
public
function
executeNoDb
()
public
function
executeNoDb
()
{
{
...
@@ -247,7 +266,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -247,7 +266,7 @@ class SendtochannelCommand extends AdminCommand
if
(
$text
===
''
)
{
if
(
$text
===
''
)
{
$data
[
'text'
]
=
'Usage: /sendtochannel <text>'
;
$data
[
'text'
]
=
'Usage: /sendtochannel <text>'
;
}
else
{
}
else
{
$channels
=
(
array
)
$this
->
getConfig
(
'your_channel'
);
$channels
=
(
array
)
$this
->
getConfig
(
'your_channel'
);
$first_channel
=
$channels
[
0
];
$first_channel
=
$channels
[
0
];
$data
[
'text'
]
=
$this
->
publish
(
new
Message
(
$message
->
reflect
(),
'anystring'
),
$first_channel
);
$data
[
'text'
]
=
$this
->
publish
(
new
Message
(
$message
->
reflect
(),
'anystring'
),
$first_channel
);
}
}
...
@@ -295,6 +314,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -295,6 +314,7 @@ class SendtochannelCommand extends AdminCommand
* @param array $data
* @param array $data
*
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
protected
function
sendBack
(
Message
$message
,
array
$data
)
protected
function
sendBack
(
Message
$message
,
array
$data
)
{
{
...
@@ -323,7 +343,7 @@ class SendtochannelCommand extends AdminCommand
...
@@ -323,7 +343,7 @@ class SendtochannelCommand extends AdminCommand
}
}
$callback_path
=
'Longman\TelegramBot\Request'
;
$callback_path
=
'Longman\TelegramBot\Request'
;
$callback_function
=
'send'
.
$type
;
$callback_function
=
'send'
.
$type
;
if
(
!
method_exists
(
$callback_path
,
$callback_function
))
{
if
(
!
method_exists
(
$callback_path
,
$callback_function
))
{
throw
new
TelegramException
(
'Methods: '
.
$callback_function
.
' not found in class Request.'
);
throw
new
TelegramException
(
'Methods: '
.
$callback_function
.
' not found in class Request.'
);
}
}
...
...
src/Commands/AdminCommands/WhoisCommand.php
View file @
84cd8f50
...
@@ -22,18 +22,35 @@ use Longman\TelegramBot\Request;
...
@@ -22,18 +22,35 @@ use Longman\TelegramBot\Request;
*/
*/
class
WhoisCommand
extends
AdminCommand
class
WhoisCommand
extends
AdminCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'whois'
;
protected
$name
=
'whois'
;
/**
* @var string
*/
protected
$description
=
'Lookup user or group info'
;
protected
$description
=
'Lookup user or group info'
;
/**
* @var string
*/
protected
$usage
=
'/whois <id> or /whois <search string>'
;
protected
$usage
=
'/whois <id> or /whois <search string>'
;
/**
* @var string
*/
protected
$version
=
'1.1.0'
;
protected
$version
=
'1.1.0'
;
/**
* @var bool
*/
protected
$need_mysql
=
true
;
protected
$need_mysql
=
true
;
/**#@-*/
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
@@ -43,7 +60,7 @@ class WhoisCommand extends AdminCommand
...
@@ -43,7 +60,7 @@ class WhoisCommand extends AdminCommand
$command
=
$message
->
getCommand
();
$command
=
$message
->
getCommand
();
$text
=
trim
(
$message
->
getText
(
true
));
$text
=
trim
(
$message
->
getText
(
true
));
$data
=
[
'chat_id'
=>
$chat_id
];
$data
=
[
'chat_id'
=>
$chat_id
];
//No point in replying to messages in private chats
//No point in replying to messages in private chats
if
(
!
$message
->
getChat
()
->
isPrivateChat
())
{
if
(
!
$message
->
getChat
()
->
isPrivateChat
())
{
...
@@ -117,7 +134,7 @@ class WhoisCommand extends AdminCommand
...
@@ -117,7 +134,7 @@ class WhoisCommand extends AdminCommand
$limit
=
10
;
$limit
=
10
;
$offset
=
null
;
$offset
=
null
;
$ServerResponse
=
Request
::
getUserProfilePhotos
([
$ServerResponse
=
Request
::
getUserProfilePhotos
([
'user_id'
=>
$user_id
,
'user_id'
=>
$user_id
,
'limit'
=>
$limit
,
'limit'
=>
$limit
,
'offset'
=>
$offset
,
'offset'
=>
$offset
,
]);
]);
...
@@ -140,7 +157,7 @@ class WhoisCommand extends AdminCommand
...
@@ -140,7 +157,7 @@ class WhoisCommand extends AdminCommand
return
Request
::
sendPhoto
(
$data
);
return
Request
::
sendPhoto
(
$data
);
}
}
}
elseif
(
$chat
->
isGroupChat
())
{
}
elseif
(
$chat
->
isGroupChat
())
{
$text
=
'Chat ID: '
.
$user_id
.
(
!
empty
(
$old_id
)
?
' (previously: '
.
$old_id
.
')'
:
''
)
.
"
\n
"
;
$text
=
'Chat ID: '
.
$user_id
.
(
!
empty
(
$old_id
)
?
' (previously: '
.
$old_id
.
')'
:
''
)
.
"
\n
"
;
$text
.=
'Type: '
.
ucfirst
(
$chat
->
getType
())
.
"
\n
"
;
$text
.=
'Type: '
.
ucfirst
(
$chat
->
getType
())
.
"
\n
"
;
$text
.=
'Title: '
.
$chat
->
getTitle
()
.
"
\n
"
;
$text
.=
'Title: '
.
$chat
->
getTitle
()
.
"
\n
"
;
$text
.=
'First time added to group: '
.
$created_at
.
"
\n
"
;
$text
.=
'First time added to group: '
.
$created_at
.
"
\n
"
;
...
...
src/Commands/Command.php
View file @
84cd8f50
...
@@ -15,9 +15,6 @@ use Longman\TelegramBot\Request;
...
@@ -15,9 +15,6 @@ use Longman\TelegramBot\Request;
use
Longman\TelegramBot\Telegram
;
use
Longman\TelegramBot\Telegram
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Entities\Update
;
/**
* Abstract Command Class
*/
abstract
class
Command
abstract
class
Command
{
{
/**
/**
...
...
src/Commands/SystemCommand.php
View file @
84cd8f50
...
@@ -12,9 +12,6 @@ namespace Longman\TelegramBot\Commands;
...
@@ -12,9 +12,6 @@ namespace Longman\TelegramBot\Commands;
use
Longman\TelegramBot\Request
;
use
Longman\TelegramBot\Request
;
/**
* Abstract System Command Class
*/
abstract
class
SystemCommand
extends
Command
abstract
class
SystemCommand
extends
Command
{
{
/**
/**
...
@@ -23,7 +20,7 @@ abstract class SystemCommand extends Command
...
@@ -23,7 +20,7 @@ abstract class SystemCommand extends Command
* Although system commands should just work and return a successful ServerResponse,
* Although system commands should just work and return a successful ServerResponse,
* each system command can override this method to add custom functionality.
* each system command can override this method to add custom functionality.
*
*
* @return Entities\ServerResponse
* @return
\Longman\TelegramBot\
Entities\ServerResponse
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
...
src/Commands/UserCommand.php
View file @
84cd8f50
...
@@ -10,9 +10,6 @@
...
@@ -10,9 +10,6 @@
namespace
Longman\TelegramBot\Commands
;
namespace
Longman\TelegramBot\Commands
;
/**
* Abstract User Command Class
*/
abstract
class
UserCommand
extends
Command
abstract
class
UserCommand
extends
Command
{
{
...
...
src/Commands/UserCommands/CancelCommand.php
View file @
84cd8f50
...
@@ -24,18 +24,35 @@ use Longman\TelegramBot\Request;
...
@@ -24,18 +24,35 @@ use Longman\TelegramBot\Request;
*/
*/
class
CancelCommand
extends
UserCommand
class
CancelCommand
extends
UserCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'cancel'
;
protected
$name
=
'cancel'
;
/**
* @var string
*/
protected
$description
=
'Cancel the currently active conversation'
;
protected
$description
=
'Cancel the currently active conversation'
;
/**
* @var string
*/
protected
$usage
=
'/cancel'
;
protected
$usage
=
'/cancel'
;
/**
* @var string
*/
protected
$version
=
'0.1.1'
;
protected
$version
=
'0.1.1'
;
/**
* @var bool
*/
protected
$need_mysql
=
true
;
protected
$need_mysql
=
true
;
/**#@-*/
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
@@ -56,7 +73,9 @@ class CancelCommand extends UserCommand
...
@@ -56,7 +73,9 @@ class CancelCommand extends UserCommand
}
}
/**
/**
* {@inheritdoc}
* Execute no db
*
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
*/
public
function
executeNoDb
()
public
function
executeNoDb
()
{
{
...
@@ -72,10 +91,12 @@ class CancelCommand extends UserCommand
...
@@ -72,10 +91,12 @@ class CancelCommand extends UserCommand
*/
*/
private
function
hideKeyboard
(
$text
)
private
function
hideKeyboard
(
$text
)
{
{
return
Request
::
sendMessage
([
return
Request
::
sendMessage
(
[
'reply_markup'
=>
new
ReplyKeyboardHide
([
'selective'
=>
true
]),
'reply_markup'
=>
new
ReplyKeyboardHide
([
'selective'
=>
true
]),
'chat_id'
=>
$this
->
getMessage
()
->
getChat
()
->
getId
(),
'chat_id'
=>
$this
->
getMessage
()
->
getChat
()
->
getId
(),
'text'
=>
$text
,
'text'
=>
$text
,
]);
]
);
}
}
}
}
src/Commands/UserCommands/DateCommand.php
View file @
84cd8f50
...
@@ -21,14 +21,25 @@ use Longman\TelegramBot\Request;
...
@@ -21,14 +21,25 @@ use Longman\TelegramBot\Request;
*/
*/
class
DateCommand
extends
UserCommand
class
DateCommand
extends
UserCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'date'
;
protected
$name
=
'date'
;
/**
* @var string
*/
protected
$description
=
'Show date/time by location'
;
protected
$description
=
'Show date/time by location'
;
/**
* @var string
*/
protected
$usage
=
'/date <location>'
;
protected
$usage
=
'/date <location>'
;
/**
* @var string
*/
protected
$version
=
'1.3.0'
;
protected
$version
=
'1.3.0'
;
/**#@-*/
/**
/**
* Guzzle Client object
* Guzzle Client object
...
@@ -64,6 +75,7 @@ class DateCommand extends UserCommand
...
@@ -64,6 +75,7 @@ class DateCommand extends UserCommand
* @param string $location
* @param string $location
*
*
* @return array|boolean
* @return array|boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
private
function
getCoordinates
(
$location
)
private
function
getCoordinates
(
$location
)
{
{
...
@@ -100,6 +112,7 @@ class DateCommand extends UserCommand
...
@@ -100,6 +112,7 @@ class DateCommand extends UserCommand
* @param string $lng
* @param string $lng
*
*
* @return array|boolean
* @return array|boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
private
function
getDate
(
$lat
,
$lng
)
private
function
getDate
(
$lat
,
$lng
)
{
{
...
@@ -184,7 +197,9 @@ class DateCommand extends UserCommand
...
@@ -184,7 +197,9 @@ class DateCommand extends UserCommand
}
}
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
...
src/Commands/UserCommands/EchoCommand.php
View file @
84cd8f50
...
@@ -18,17 +18,30 @@ use Longman\TelegramBot\Request;
...
@@ -18,17 +18,30 @@ use Longman\TelegramBot\Request;
*/
*/
class
EchoCommand
extends
UserCommand
class
EchoCommand
extends
UserCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'echo'
;
protected
$name
=
'echo'
;
/**
* @var string
*/
protected
$description
=
'Show text'
;
protected
$description
=
'Show text'
;
/**
* @var string
*/
protected
$usage
=
'/echo <text>'
;
protected
$usage
=
'/echo <text>'
;
/**
* @var string
*/
protected
$version
=
'1.0.1'
;
protected
$version
=
'1.0.1'
;
/**#@-*/
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
...
src/Commands/UserCommands/HelpCommand.php
View file @
84cd8f50
...
@@ -18,17 +18,30 @@ use Longman\TelegramBot\Request;
...
@@ -18,17 +18,30 @@ use Longman\TelegramBot\Request;
*/
*/
class
HelpCommand
extends
UserCommand
class
HelpCommand
extends
UserCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'help'
;
protected
$name
=
'help'
;
/**
* @var string
*/
protected
$description
=
'Show bot commands help'
;
protected
$description
=
'Show bot commands help'
;
/**
* @var string
*/
protected
$usage
=
'/help or /help <command>'
;
protected
$usage
=
'/help or /help <command>'
;
/**
* @var string
*/
protected
$version
=
'1.0.1'
;
protected
$version
=
'1.0.1'
;
/**#@-*/
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
...
src/Commands/UserCommands/SlapCommand.php
View file @
84cd8f50
...
@@ -18,17 +18,30 @@ use Longman\TelegramBot\Request;
...
@@ -18,17 +18,30 @@ use Longman\TelegramBot\Request;
*/
*/
class
SlapCommand
extends
UserCommand
class
SlapCommand
extends
UserCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'slap'
;
protected
$name
=
'slap'
;
/**
* @var string
*/
protected
$description
=
'Slap someone with their username'
;
protected
$description
=
'Slap someone with their username'
;
/**
* @var string
*/
protected
$usage
=
'/slap <@user>'
;
protected
$usage
=
'/slap <@user>'
;
/**
* @var string
*/
protected
$version
=
'1.0.1'
;
protected
$version
=
'1.0.1'
;
/**#@-*/
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
...
src/Commands/UserCommands/SurveyCommand.php
View file @
84cd8f50
...
@@ -22,15 +22,30 @@ use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
...
@@ -22,15 +22,30 @@ use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
*/
*/
class
SurveyCommand
extends
UserCommand
class
SurveyCommand
extends
UserCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'survey'
;
protected
$name
=
'survey'
;
/**
* @var string
*/
protected
$description
=
'Survery for bot users'
;
protected
$description
=
'Survery for bot users'
;
/**
* @var string
*/
protected
$usage
=
'/survey'
;
protected
$usage
=
'/survey'
;
/**
* @var string
*/
protected
$version
=
'0.2.0'
;
protected
$version
=
'0.2.0'
;
/**
* @var bool
*/
protected
$need_mysql
=
true
;
protected
$need_mysql
=
true
;
/**#@-*/
/**
/**
* Conversation Object
* Conversation Object
...
@@ -40,7 +55,9 @@ class SurveyCommand extends UserCommand
...
@@ -40,7 +55,9 @@ class SurveyCommand extends UserCommand
protected
$conversation
;
protected
$conversation
;
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
@@ -58,7 +75,7 @@ class SurveyCommand extends UserCommand
...
@@ -58,7 +75,7 @@ class SurveyCommand extends UserCommand
if
(
$chat
->
isGroupChat
()
||
$chat
->
isSuperGroup
())
{
if
(
$chat
->
isGroupChat
()
||
$chat
->
isSuperGroup
())
{
//reply to message id is applied by default
//reply to message id is applied by default
//Force reply is applied by default to so can work with privacy on
//Force reply is applied by default to so can work with privacy on
$data
[
'reply_markup'
]
=
new
ForceReply
([
'selective'
=>
true
]);
$data
[
'reply_markup'
]
=
new
ForceReply
([
'selective'
=>
true
]);
}
}
$data
[
'chat_id'
]
=
$chat_id
;
$data
[
'chat_id'
]
=
$chat_id
;
...
@@ -124,10 +141,10 @@ class SurveyCommand extends UserCommand
...
@@ -124,10 +141,10 @@ class SurveyCommand extends UserCommand
$this
->
conversation
->
notes
[
'state'
]
=
3
;
$this
->
conversation
->
notes
[
'state'
]
=
3
;
$this
->
conversation
->
update
();
$this
->
conversation
->
update
();
$keyboard
=
[[
'M'
,
'F'
]];
$keyboard
=
[[
'M'
,
'F'
]];
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
$reply_keyboard_markup
=
new
ReplyKeyboardMarkup
(
[
[
'keyboard'
=>
$keyboard
,
'keyboard'
=>
$keyboard
,
'resize_keyboard'
=>
true
,
'resize_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'selective'
=>
true
'selective'
=>
true
...
@@ -149,14 +166,21 @@ class SurveyCommand extends UserCommand
...
@@ -149,14 +166,21 @@ class SurveyCommand extends UserCommand
if
(
is_null
(
$message
->
getLocation
()))
{
if
(
is_null
(
$message
->
getLocation
()))
{
$this
->
conversation
->
notes
[
'state'
]
=
4
;
$this
->
conversation
->
notes
[
'state'
]
=
4
;
$this
->
conversation
->
update
();
$this
->
conversation
->
update
();
$data
[
'reply_markup'
]
=
new
ReplyKeyboardMarkup
([
$data
[
'reply_markup'
]
=
new
ReplyKeyboardMarkup
(
'keyboard'
=>
[[
[
[
'text'
=>
'Share Location'
,
'request_location'
=>
true
],
'keyboard'
=>
[
]],
[
[
'text'
=>
'Share Location'
,
'request_location'
=>
true
],
]
],
'resize_keyboard'
=>
true
,
'resize_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'selective'
=>
true
,
'selective'
=>
true
,
]);
]
);
$data
[
'text'
]
=
'Share your location:'
;
$data
[
'text'
]
=
'Share your location:'
;
$result
=
Request
::
sendMessage
(
$data
);
$result
=
Request
::
sendMessage
(
$data
);
break
;
break
;
...
@@ -185,14 +209,21 @@ class SurveyCommand extends UserCommand
...
@@ -185,14 +209,21 @@ class SurveyCommand extends UserCommand
$this
->
conversation
->
update
();
$this
->
conversation
->
update
();
$data
[
'text'
]
=
'Share your contact information:'
;
$data
[
'text'
]
=
'Share your contact information:'
;
$data
[
'reply_markup'
]
=
new
ReplyKeyboardMarkup
([
$data
[
'reply_markup'
]
=
new
ReplyKeyboardMarkup
(
'keyboard'
=>
[[
[
[
'text'
=>
'Share Contact'
,
'request_contact'
=>
true
],
'keyboard'
=>
[
]],
[
[
'text'
=>
'Share Contact'
,
'request_contact'
=>
true
],
]
],
'resize_keyboard'
=>
true
,
'resize_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'one_time_keyboard'
=>
true
,
'selective'
=>
true
,
'selective'
=>
true
,
]);
]
);
$result
=
Request
::
sendMessage
(
$data
);
$result
=
Request
::
sendMessage
(
$data
);
break
;
break
;
}
}
...
@@ -204,7 +235,7 @@ class SurveyCommand extends UserCommand
...
@@ -204,7 +235,7 @@ class SurveyCommand extends UserCommand
$out_text
=
'/Survey result:'
.
"
\n
"
;
$out_text
=
'/Survey result:'
.
"
\n
"
;
unset
(
$this
->
conversation
->
notes
[
'state'
]);
unset
(
$this
->
conversation
->
notes
[
'state'
]);
foreach
(
$this
->
conversation
->
notes
as
$k
=>
$v
)
{
foreach
(
$this
->
conversation
->
notes
as
$k
=>
$v
)
{
$out_text
.=
"
\n
"
.
ucfirst
(
$k
)
.
': '
.
$v
;
$out_text
.=
"
\n
"
.
ucfirst
(
$k
)
.
': '
.
$v
;
}
}
$data
[
'photo'
]
=
$this
->
conversation
->
notes
[
'photo_id'
];
$data
[
'photo'
]
=
$this
->
conversation
->
notes
[
'photo_id'
];
...
...
src/Commands/UserCommands/WeatherCommand.php
View file @
84cd8f50
...
@@ -21,14 +21,25 @@ use Longman\TelegramBot\Request;
...
@@ -21,14 +21,25 @@ use Longman\TelegramBot\Request;
*/
*/
class
WeatherCommand
extends
UserCommand
class
WeatherCommand
extends
UserCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'weather'
;
protected
$name
=
'weather'
;
/**
* @var string
*/
protected
$description
=
'Show weather by location'
;
protected
$description
=
'Show weather by location'
;
/**
* @var string
*/
protected
$usage
=
'/weather <location>'
;
protected
$usage
=
'/weather <location>'
;
/**
* @var string
*/
protected
$version
=
'1.1.0'
;
protected
$version
=
'1.1.0'
;
/**#@-*/
/**
/**
* Base URI for OpenWeatherMap API
* Base URI for OpenWeatherMap API
...
@@ -43,6 +54,7 @@ class WeatherCommand extends UserCommand
...
@@ -43,6 +54,7 @@ class WeatherCommand extends UserCommand
* @param string $location
* @param string $location
*
*
* @return string
* @return string
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
private
function
getWeatherData
(
$location
)
private
function
getWeatherData
(
$location
)
{
{
...
@@ -60,7 +72,7 @@ class WeatherCommand extends UserCommand
...
@@ -60,7 +72,7 @@ class WeatherCommand extends UserCommand
throw
new
TelegramException
(
$e
->
getMessage
());
throw
new
TelegramException
(
$e
->
getMessage
());
}
}
return
(
string
)
$response
->
getBody
();
return
(
string
)
$response
->
getBody
();
}
}
/**
/**
...
@@ -103,7 +115,9 @@ class WeatherCommand extends UserCommand
...
@@ -103,7 +115,9 @@ class WeatherCommand extends UserCommand
}
}
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
...
src/Commands/UserCommands/WhoamiCommand.php
View file @
84cd8f50
...
@@ -21,18 +21,35 @@ use Longman\TelegramBot\Request;
...
@@ -21,18 +21,35 @@ use Longman\TelegramBot\Request;
*/
*/
class
WhoamiCommand
extends
UserCommand
class
WhoamiCommand
extends
UserCommand
{
{
/**
#@+
/**
*
{@inheritdoc}
*
@var string
*/
*/
protected
$name
=
'whoami'
;
protected
$name
=
'whoami'
;
/**
* @var string
*/
protected
$description
=
'Show your id, name and username'
;
protected
$description
=
'Show your id, name and username'
;
/**
* @var string
*/
protected
$usage
=
'/whoami'
;
protected
$usage
=
'/whoami'
;
/**
* @var string
*/
protected
$version
=
'1.0.1'
;
protected
$version
=
'1.0.1'
;
/**
* @var bool
*/
protected
$public
=
true
;
protected
$public
=
true
;
/**#@-*/
/**
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
*/
public
function
execute
()
public
function
execute
()
{
{
...
@@ -55,7 +72,7 @@ class WhoamiCommand extends UserCommand
...
@@ -55,7 +72,7 @@ class WhoamiCommand extends UserCommand
$limit
=
10
;
$limit
=
10
;
$offset
=
null
;
$offset
=
null
;
$ServerResponse
=
Request
::
getUserProfilePhotos
([
$ServerResponse
=
Request
::
getUserProfilePhotos
([
'user_id'
=>
$user_id
,
'user_id'
=>
$user_id
,
'limit'
=>
$limit
,
'limit'
=>
$limit
,
'offset'
=>
$offset
,
'offset'
=>
$offset
,
]);
]);
...
...
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