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
1c1801a9
Commit
1c1801a9
authored
Dec 04, 2015
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some cleanup
parent
1d79ce65
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
41 deletions
+15
-41
DB.php
src/DB.php
+7
-16
Chat.php
src/Entities/Chat.php
+1
-1
Telegram.php
src/Telegram.php
+7
-24
No files found.
src/DB.php
View file @
1c1801a9
...
...
@@ -31,7 +31,7 @@ class DB
*
* @var array
*/
static
protected
$mysql_credentials
=
array
()
;
static
protected
$mysql_credentials
=
[]
;
/**
* PDO object
...
...
@@ -65,8 +65,8 @@ class DB
try
{
$pdo
=
new
\PDO
(
$dsn
,
$credentials
[
'user'
],
$credentials
[
'password'
],
$options
);
$pdo
->
setAttribute
(
\PDO
::
ATTR_ERRMODE
,
\PDO
::
ERRMODE_WARNING
);
//Define table
//Define table
if
(
!
defined
(
'TB_MESSAGES'
))
{
define
(
'TB_MESSAGES'
,
self
::
$table_prefix
.
'messages'
);
}
...
...
@@ -122,16 +122,12 @@ class DB
$query
=
'SELECT * FROM `'
.
TB_MESSAGES
.
'`'
;
$query
.=
' ORDER BY '
.
TB_MESSAGES
.
'.`update_id` DESC'
;
$tokens
=
[];
if
(
!
is_null
(
$limit
))
{
//$query .=' LIMIT :limit ';
//$tokens[':limit'] = $limit;
$query
.=
' LIMIT '
.
$limit
;
$query
.=
' LIMIT :limit '
;
}
//echo $query;
$sth
=
self
::
$pdo
->
prepare
(
$query
);
//$sth->execute($tokens
);
$sth
->
bindParam
(
':limit'
,
$limit
,
\PDO
::
PARAM_STR
);
$sth
->
execute
();
$results
=
$sth
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
...
...
@@ -189,7 +185,6 @@ class DB
$status
=
$sth1
->
execute
();
}
catch
(
PDOException
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
...
...
@@ -217,7 +212,6 @@ class DB
}
/**
* Insert request in db
*
...
...
@@ -234,7 +228,6 @@ class DB
$from
=
$message
->
getFrom
();
$chat
=
$message
->
getChat
();
$chat_id
=
$chat
->
getId
();
$date
=
self
::
toTimestamp
(
$message
->
getDate
());
...
...
@@ -246,7 +239,7 @@ class DB
$new_chat_photo
=
$message
->
getNewChatPhoto
();
$left_chat_participant
=
$message
->
getLeftChatParticipant
();
//inser user and the relation with the chat
//inser
t
user and the relation with the chat
self
::
insertUser
(
$from
,
$date
,
$chat
);
//Insert the forwarded message user in users table
...
...
@@ -323,7 +316,6 @@ class DB
$delete_chat_photo
=
$message
->
getDeleteChatPhoto
();
$group_chat_created
=
$message
->
getGroupChatCreated
();
$sth
->
bindParam
(
':update_id'
,
$update_id
,
\PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':message_id'
,
$message_id
,
\PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':user_id'
,
$from_id
,
\PDO
::
PARAM_INT
);
...
...
@@ -357,8 +349,8 @@ class DB
$sth
->
bindParam
(
':new_chat_participant'
,
$new_chat_paticipant
,
\PDO
::
PARAM_STR
);
$sth
->
bindParam
(
':left_chat_participant'
,
$left_chat_paticipant
,
\PDO
::
PARAM_STR
);
$sth
->
bindParam
(
':new_chat_title'
,
$new_chat_title
,
\PDO
::
PARAM_STR
);
//Array of Photosize
//Array of Photosize
$var
=
[];
if
(
is_array
(
$new_chat_photo
))
{
foreach
(
$new_chat_photo
as
$elm
)
{
...
...
@@ -443,7 +435,6 @@ class DB
}
$query
.=
' ORDER BY '
.
TB_CHATS
.
'.`updated_at` ASC'
;
//echo $query."\n";
$sth
=
self
::
$pdo
->
prepare
(
$query
);
$sth
->
execute
(
$tokens
);
...
...
src/Entities/Chat.php
View file @
1c1801a9
...
...
@@ -32,7 +32,7 @@ class Chat extends Entity
//$this->type = isset($data['type']) ? $data['type'] : null;
if
(
isset
(
$data
[
'type'
])
)
{
if
(
isset
(
$data
[
'type'
])
)
{
$this
->
type
=
$data
[
'type'
];
}
else
{
if
(
$this
->
isPrivateChat
())
{
...
...
src/Telegram.php
View file @
1c1801a9
...
...
@@ -85,16 +85,13 @@ class Telegram
*
* @var string
*/
protected
$upload_path
;
/**
* Dowload Path
*
* @var string
*/
protected
$download_path
;
/**
...
...
@@ -110,6 +107,7 @@ class Telegram
* @var boolean
*/
protected
$mysql_enabled
=
false
;
/**
* PDO object
*
...
...
@@ -124,7 +122,6 @@ class Telegram
*/
protected
$commands_config
;
/**
* Message types
*
...
...
@@ -141,7 +138,6 @@ class Telegram
*/
protected
$admins_list
=
[];
/**
* Admin
*
...
...
@@ -150,7 +146,6 @@ class Telegram
protected
$admin_enabled
=
false
;
/**
* Constructor
*
...
...
@@ -326,7 +321,6 @@ class Telegram
return
$this
;
}
/**
* Get custom update string for debug purposes
*
...
...
@@ -337,7 +331,6 @@ class Telegram
return
$this
->
update
;
}
/**
* Handle getUpdates method
*
...
...
@@ -355,7 +348,7 @@ class Telegram
}
else
{
$offset
=
null
;
}
//arrive a server Response object
$ServerResponse
=
Request
::
getUpdates
([
'offset'
=>
$offset
,
'limit'
=>
$limit
,
...
...
@@ -405,11 +398,11 @@ class Telegram
public
function
processUpdate
(
update
$update
)
{
//Load admin Commands
if
(
$this
->
admin_enabled
)
{
$message
=
$update
->
getMessage
();
//Admin command avaiable in any chats
//$from = $message->getFrom();
//$user_id = $from->getId();
...
...
@@ -470,7 +463,6 @@ class Telegram
{
$class
=
$this
->
getCommandClass
(
$command
,
$update
);
//print_r($class);
if
(
!
$class
)
{
//handle a generic command or non existing one
return
$this
->
executeCommand
(
'Generic'
,
$update
);
...
...
@@ -480,8 +472,8 @@ class Telegram
return
false
;
}
//execute
methods will be execute after preexecution
//this for prevent to execute db query witout connection
//execute
() methods will be execute after preexecute() methods
//this for prevent to execute db query wit
h
out connection
return
$class
->
preExecute
();
}
...
...
@@ -533,7 +525,6 @@ class Telegram
protected
function
sanitizeCommand
(
$string
,
$capitalizeFirstCharacter
=
false
)
{
$str
=
str_replace
(
' '
,
''
,
ucwords
(
str_replace
(
'_'
,
' '
,
$string
)));
//$str[0] = strtolower($str[0]);
return
$str
;
}
...
...
@@ -596,11 +587,6 @@ class Telegram
*/
public
function
setUploadPath
(
$folder
)
{
//if (!is_dir($folder)) {
// if(!mkdir($folder, 0755, true)) {
// throw new TelegramException('Directory '.$folder.' cant be created');
// }
//}
$this
->
upload_path
=
$folder
;
return
$this
;
}
...
...
@@ -622,11 +608,6 @@ class Telegram
*/
public
function
setDownloadPath
(
$folder
)
{
//if (!is_dir($folder)) {
// if(!mkdir($folder, 0755, true)) {
// throw new TelegramException('Directory '.$folder.' cant be created');
// }
//}
$this
->
download_path
=
$folder
;
return
$this
;
}
...
...
@@ -732,6 +713,7 @@ class Telegram
return
$result
;
}
/**
* Get available message types
*
...
...
@@ -741,6 +723,7 @@ class Telegram
{
return
$this
->
message_types
;
}
/**
* Get list of admins
*
...
...
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