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
2858ff5d
Commit
2858ff5d
authored
Mar 13, 2016
by
Marco Boretto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9 from noplanman/small_cleanup_fixes
Small cleanup fixes
parents
8a5a5c58
b8e3b4b9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
25 deletions
+29
-25
SendtochannelCommand.php
src/Commands/AdminCommands/SendtochannelCommand.php
+8
-6
Conversation.php
src/Conversation.php
+17
-16
ConversationDB.php
src/ConversationDB.php
+4
-3
No files found.
src/Commands/AdminCommands/SendtochannelCommand.php
View file @
2858ff5d
...
...
@@ -215,18 +215,20 @@ class SendtochannelCommand extends AdminCommand
$this
->
conversation
->
notes
[
'last_message_id'
]
=
$message
->
getMessageId
();
// no break
case
5
:
$this
->
conversation
->
stop
();
$data
[
'reply_markup'
]
=
new
ReplyKeyBoardHide
([
'selective'
=>
true
]);
if
(
$this
->
conversation
->
notes
[
'post_message'
])
{
$data
[
'text'
]
=
$this
->
publish
(
new
Message
(
$this
->
conversation
->
notes
[
'message'
],
'anystring'
),
$this
->
conversation
->
notes
[
'channel'
],
$this
->
conversation
->
notes
[
'caption'
]);
$result
=
Request
::
sendMessage
(
$data
);
break
;
$data
[
'text'
]
=
$this
->
publish
(
new
Message
(
$this
->
conversation
->
notes
[
'message'
],
'anystring'
),
$this
->
conversation
->
notes
[
'channel'
],
$this
->
conversation
->
notes
[
'caption'
]
);
}
else
{
$data
[
'text'
]
=
'Abort by user, message not sent..'
;
}
$
data
[
'text'
]
=
'Abort by user, message not sent..'
;
$
this
->
conversation
->
stop
()
;
$result
=
Request
::
sendMessage
(
$data
);
break
;
}
return
$result
;
}
...
...
src/Conversation.php
View file @
2858ff5d
...
...
@@ -60,13 +60,6 @@ class Conversation
*/
protected
$command
;
/**
* Command has been provided
*
* @var string
*/
protected
$command_is_provided
;
/**
* Conversation contructor to initialize a new conversation
*
...
...
@@ -80,26 +73,35 @@ class Conversation
$this
->
chat_id
=
$chat_id
;
$this
->
command
=
$command
;
$this
->
command_is_provided
=
(
$command
!==
null
);
//Try to load an existing conversation if possible
if
(
!
$this
->
load
()
&&
$
this
->
command_is_provided
)
{
if
(
!
$this
->
load
()
&&
$
command
!==
null
)
{
//A new conversation start
$this
->
start
();
}
}
/**
*
Load the conversation from the database
*
Clear all conversation variables.
*
* @return bool
* @return bool
Always return true, to allow this method in an if statement.
*/
protected
function
load
()
protected
function
clear
()
{
$this
->
conversation
=
null
;
$this
->
protected_notes
=
null
;
$this
->
notes
=
null
;
return
true
;
}
/**
* Load the conversation from the database
*
* @return bool
*/
protected
function
load
()
{
//Select an active conversation
$conversation
=
ConversationDB
::
selectConversation
(
$this
->
user_id
,
$this
->
chat_id
,
1
);
if
(
isset
(
$conversation
[
0
]))
{
...
...
@@ -111,7 +113,6 @@ class Conversation
if
(
$this
->
command
!==
$this
->
conversation
[
'command'
])
{
$this
->
cancel
();
$this
->
conversation
=
null
;
return
false
;
}
...
...
@@ -162,7 +163,7 @@ class Conversation
*/
public
function
stop
()
{
return
$this
->
updateStatus
(
'stopped'
);
return
(
$this
->
updateStatus
(
'stopped'
)
&&
$this
->
clear
()
);
}
/**
...
...
@@ -172,7 +173,7 @@ class Conversation
*/
public
function
cancel
()
{
return
$this
->
updateStatus
(
'cancelled'
);
return
(
$this
->
updateStatus
(
'cancelled'
)
&&
$this
->
clear
()
);
}
/**
...
...
src/ConversationDB.php
View file @
2858ff5d
...
...
@@ -11,6 +11,7 @@
namespace
Longman\TelegramBot
;
use
Longman\TelegramBot\DB
;
use
Longman\TelegramBot\Exception\TelegramException
;
/**
* Class ConversationDB
...
...
@@ -63,7 +64,7 @@ class ConversationDB extends DB
$results
=
$sth
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
catch
(
PDO
Exception
$e
)
{
}
catch
(
\
Exception
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
return
$results
;
...
...
@@ -106,7 +107,7 @@ class ConversationDB extends DB
$sth
->
bindParam
(
':date'
,
$created_at
);
$status
=
$sth
->
execute
();
}
catch
(
PDO
Exception
$e
)
{
}
catch
(
\
Exception
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
return
$status
;
...
...
@@ -178,7 +179,7 @@ class ConversationDB extends DB
try
{
$sth
=
self
::
$pdo
->
prepare
(
$query
);
$status
=
$sth
->
execute
(
$tokens
);
}
catch
(
PDO
Exception
$e
)
{
}
catch
(
\
Exception
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
return
$status
;
...
...
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