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
0c97f937
Commit
0c97f937
authored
May 17, 2016
by
Jack'lul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename chosen_inline_query to chosen_inline_result
parent
e5b6d415
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
58 deletions
+71
-58
DB.php
src/DB.php
+67
-54
structure.sql
structure.sql
+4
-4
No files found.
src/DB.php
View file @
0c97f937
...
...
@@ -11,9 +11,10 @@
namespace
Longman\TelegramBot
;
use
Longman\TelegramBot\Entities\CallbackQuery
;
use
Longman\TelegramBot\Entities\Chat
;
use
Longman\TelegramBot\Entities\ChosenInlineResult
;
use
Longman\TelegramBot\Entities\InlineQuery
;
use
Longman\TelegramBot\Entities\CallbackQuery
;
use
Longman\TelegramBot\Entities\Message
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Entities\User
;
...
...
@@ -135,12 +136,12 @@ class DB
if
(
!
defined
(
'TB_INLINE_QUERY'
))
{
define
(
'TB_INLINE_QUERY'
,
self
::
$table_prefix
.
'inline_query'
);
}
if
(
!
defined
(
'TB_CHOSEN_INLINE_RESULT'
))
{
define
(
'TB_CHOSEN_INLINE_RESULT'
,
self
::
$table_prefix
.
'chosen_inline_result'
);
}
if
(
!
defined
(
'TB_CALLBACK_QUERY'
))
{
define
(
'TB_CALLBACK_QUERY'
,
self
::
$table_prefix
.
'callback_query'
);
}
if
(
!
defined
(
'TB_CHOSEN_INLINE_QUERY'
))
{
define
(
'TB_CHOSEN_INLINE_QUERY'
,
self
::
$table_prefix
.
'chosen_inline_query'
);
}
if
(
!
defined
(
'TB_USER'
))
{
define
(
'TB_USER'
,
self
::
$table_prefix
.
'user'
);
}
...
...
@@ -256,14 +257,14 @@ class DB
* @param int $chat_id
* @param int $message_id
* @param int $inline_query_id
* @param int $chosen_inline_
query
_id
* @param int $chosen_inline_
result
_id
* @param int $callback_query_id
*
* @return bool|null
*/
public
static
function
insertTelegramUpdate
(
$id
,
$chat_id
,
$message_id
,
$inline_query_id
,
$chosen_inline_
query
_id
,
$callback_query_id
)
public
static
function
insertTelegramUpdate
(
$id
,
$chat_id
,
$message_id
,
$inline_query_id
,
$chosen_inline_
result
_id
,
$callback_query_id
)
{
if
(
is_null
(
$message_id
)
&&
is_null
(
$inline_query_id
)
&&
is_null
(
$chosen_inline_
query
_id
)
&&
is_null
(
$callback_query_id
))
{
if
(
is_null
(
$message_id
)
&&
is_null
(
$inline_query_id
)
&&
is_null
(
$chosen_inline_
result
_id
)
&&
is_null
(
$callback_query_id
))
{
throw
new
TelegramException
(
'Error both query_id and message_id are null'
);
}
...
...
@@ -275,10 +276,10 @@ class DB
//telegram_update table
$sth_insert_telegram_update
=
self
::
$pdo
->
prepare
(
'INSERT IGNORE INTO `'
.
TB_TELEGRAM_UPDATE
.
'`
(
`id`, `chat_id`, `message_id`, `inline_query_id`, `chosen_inline_
query
_id`, `callback_query_id`
`id`, `chat_id`, `message_id`, `inline_query_id`, `chosen_inline_
result
_id`, `callback_query_id`
)
VALUES (
:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_
query
_id, :callback_query_id
:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_
result
_id, :callback_query_id
)
'
);
...
...
@@ -286,7 +287,7 @@ class DB
$sth_insert_telegram_update
->
bindParam
(
':chat_id'
,
$chat_id
,
\PDO
::
PARAM_INT
);
$sth_insert_telegram_update
->
bindParam
(
':message_id'
,
$message_id
,
\PDO
::
PARAM_INT
);
$sth_insert_telegram_update
->
bindParam
(
':inline_query_id'
,
$inline_query_id
,
\PDO
::
PARAM_INT
);
$sth_insert_telegram_update
->
bindParam
(
':chosen_inline_
query_id'
,
$chosen_inline_query
_id
,
\PDO
::
PARAM_INT
);
$sth_insert_telegram_update
->
bindParam
(
':chosen_inline_
result_id'
,
$chosen_inline_result
_id
,
\PDO
::
PARAM_INT
);
$sth_insert_telegram_update
->
bindParam
(
':callback_query_id'
,
$callback_query_id
,
\PDO
::
PARAM_INT
);
$status
=
$sth_insert_telegram_update
->
execute
();
...
...
@@ -436,50 +437,10 @@ class DB
self
::
insertInlineQueryRequest
(
$inline_query
);
return
self
::
insertTelegramUpdate
(
$update_id
,
null
,
null
,
$inline_query_id
,
null
,
null
);
}
elseif
(
$update
->
getUpdateType
()
==
'chosen_inline_result'
)
{
$chosen_inline_query
=
$update
->
getChosenInlineResult
();
if
(
!
self
::
isDbConnected
())
{
return
false
;
}
try
{
//Inline query Table
$mysql_query
=
'INSERT INTO `'
.
TB_CHOSEN_INLINE_QUERY
.
'`
(
`result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`
)
VALUES (
:result_id, :user_id, :location, :inline_message_id, :query, :created_at
)'
;
$sth_insert_chosen_inline_query
=
self
::
$pdo
->
prepare
(
$mysql_query
);
$date
=
self
::
getTimestamp
(
time
());
$result_id
=
$chosen_inline_query
->
getResultId
();
$from
=
$chosen_inline_query
->
getFrom
();
$user_id
=
null
;
if
(
is_object
(
$from
))
{
$user_id
=
$from
->
getId
();
self
::
insertUser
(
$from
,
$date
);
}
$location
=
$chosen_inline_query
->
getLocation
();
$inline_message_id
=
$chosen_inline_query
->
getInlineMessageId
();
$query
=
$chosen_inline_query
->
getQuery
();
$sth_insert_chosen_inline_query
->
bindParam
(
':result_id'
,
$result_id
,
\PDO
::
PARAM_STR
);
$sth_insert_chosen_inline_query
->
bindParam
(
':user_id'
,
$user_id
,
\PDO
::
PARAM_INT
);
$sth_insert_chosen_inline_query
->
bindParam
(
':location'
,
$location
,
\PDO
::
PARAM_INT
);
$sth_insert_chosen_inline_query
->
bindParam
(
':inline_message_id'
,
$inline_message_id
,
\PDO
::
PARAM_INT
);
$sth_insert_chosen_inline_query
->
bindParam
(
':query'
,
$query
,
\PDO
::
PARAM_STR
);
$sth_insert_chosen_inline_query
->
bindParam
(
':created_at'
,
$date
,
\PDO
::
PARAM_STR
);
$status
=
$sth_insert_chosen_inline_query
->
execute
();
$chosen_inline_query_local_id
=
self
::
$pdo
->
lastInsertId
();
}
catch
(
PDOException
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
return
self
::
insertTelegramUpdate
(
$update_id
,
null
,
null
,
null
,
$chosen_inline_query_local_id
,
null
);
$chosen_inline_result
=
$update
->
getChosenInlineResult
();
self
::
insertChosenInlineResultRequest
(
$chosen_inline_result
);
$chosen_inline_result_local_id
=
self
::
$pdo
->
lastInsertId
();
return
self
::
insertTelegramUpdate
(
$update_id
,
null
,
null
,
null
,
$chosen_inline_result_local_id
,
null
);
}
elseif
(
$update
->
getUpdateType
()
==
'callback_query'
)
{
$callback_query
=
$update
->
getCallbackQuery
();
$callback_query_id
=
$callback_query
->
getId
();
...
...
@@ -540,6 +501,57 @@ class DB
}
}
/**
* Insert chosen inline result request into database
*
* @param Entities\ChosenInlineResult &$chosen_inline_result
*
* @return bool
*/
public
static
function
insertChosenInlineResultRequest
(
ChosenInlineResult
&
$chosen_inline_result
)
{
if
(
!
self
::
isDbConnected
())
{
return
false
;
}
try
{
//Chosen inline result Table
$mysql_query
=
'INSERT INTO `'
.
TB_CHOSEN_INLINE_RESULT
.
'`
(
`result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`
)
VALUES (
:result_id, :user_id, :location, :inline_message_id, :query, :created_at
)'
;
$sth_insert_chosen_inline_result
=
self
::
$pdo
->
prepare
(
$mysql_query
);
$date
=
self
::
getTimestamp
(
time
());
$result_id
=
$chosen_inline_result
->
getResultId
();
$from
=
$chosen_inline_result
->
getFrom
();
$user_id
=
null
;
if
(
is_object
(
$from
))
{
$user_id
=
$from
->
getId
();
self
::
insertUser
(
$from
,
$date
);
}
$location
=
$chosen_inline_result
->
getLocation
();
$inline_message_id
=
$chosen_inline_result
->
getInlineMessageId
();
$query
=
$chosen_inline_result
->
getQuery
();
$sth_insert_chosen_inline_result
->
bindParam
(
':result_id'
,
$result_id
,
\PDO
::
PARAM_STR
);
$sth_insert_chosen_inline_result
->
bindParam
(
':user_id'
,
$user_id
,
\PDO
::
PARAM_INT
);
$sth_insert_chosen_inline_result
->
bindParam
(
':location'
,
$location
,
\PDO
::
PARAM_INT
);
$sth_insert_chosen_inline_result
->
bindParam
(
':inline_message_id'
,
$inline_message_id
,
\PDO
::
PARAM_INT
);
$sth_insert_chosen_inline_result
->
bindParam
(
':query'
,
$query
,
\PDO
::
PARAM_STR
);
$sth_insert_chosen_inline_result
->
bindParam
(
':created_at'
,
$date
,
\PDO
::
PARAM_STR
);
$status
=
$sth_insert_chosen_inline_result
->
execute
();
}
catch
(
PDOException
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
}
/**
* Insert callback query request into database
*
...
...
@@ -711,6 +723,7 @@ class DB
$sth
->
bindParam
(
':forward_from'
,
$forward_from
,
\PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':forward_from_chat'
,
$forward_from_chat
,
\PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':forward_date'
,
$forward_date
,
\PDO
::
PARAM_STR
);
$reply_chat_id
=
null
;
if
(
$reply_to_message_id
)
{
$reply_chat_id
=
$chat_id
;
...
...
structure.sql
View file @
0c97f937
...
...
@@ -45,7 +45,7 @@ CREATE TABLE IF NOT EXISTS `inline_query` (
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COLLATE
=
utf8_general_ci
;
CREATE
TABLE
IF
NOT
EXISTS
`chosen_inline_
query
`
(
CREATE
TABLE
IF
NOT
EXISTS
`chosen_inline_
result
`
(
`id`
bigint
UNSIGNED
AUTO_INCREMENT
COMMENT
'Unique identifier for chosen query.'
,
`result_id`
CHAR
(
255
)
NOT
NULL
DEFAULT
''
COMMENT
'Id of the chosen result'
,
`user_id`
bigint
NULL
COMMENT
'Sender'
,
...
...
@@ -136,18 +136,18 @@ CREATE TABLE IF NOT EXISTS `telegram_update` (
`chat_id`
bigint
NULL
DEFAULT
NULL
COMMENT
'Chat identifier.'
,
`message_id`
bigint
UNSIGNED
DEFAULT
NULL
COMMENT
'Unique message identifier'
,
`inline_query_id`
bigint
UNSIGNED
DEFAULT
NULL
COMMENT
'The inline query unique identifier.'
,
`chosen_inline_
query
_id`
bigint
UNSIGNED
DEFAULT
NULL
COMMENT
'The chosen query unique identifier.'
,
`chosen_inline_
result
_id`
bigint
UNSIGNED
DEFAULT
NULL
COMMENT
'The chosen query unique identifier.'
,
`callback_query_id`
bigint
UNSIGNED
DEFAULT
NULL
COMMENT
'The callback query unique identifier.'
,
PRIMARY
KEY
(
`id`
),
KEY
`message_id`
(
`chat_id`
,
`message_id`
),
KEY
`inline_query_id`
(
`inline_query_id`
),
KEY
`chosen_inline_
query_id`
(
`chosen_inline_query
_id`
),
KEY
`chosen_inline_
result_id`
(
`chosen_inline_result
_id`
),
KEY
`callback_query_id`
(
`callback_query_id`
),
FOREIGN
KEY
(
`chat_id`
,
`message_id`
)
REFERENCES
`message`
(
`chat_id`
,
`id`
),
FOREIGN
KEY
(
`inline_query_id`
)
REFERENCES
`inline_query`
(
`id`
),
FOREIGN
KEY
(
`chosen_inline_
query_id`
)
REFERENCES
`chosen_inline_query
`
(
`id`
),
FOREIGN
KEY
(
`chosen_inline_
result_id`
)
REFERENCES
`chosen_inline_result
`
(
`id`
),
FOREIGN
KEY
(
`callback_query_id`
)
REFERENCES
`callback_query`
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COLLATE
=
utf8_general_ci
;
...
...
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