|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the TelegramBot package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Longman\TelegramBot; |
|
12
|
|
|
|
|
13
|
|
|
use Illuminate\Config\Repository; |
|
14
|
|
|
|
|
15
|
|
|
class Config extends Repository |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Add a single custom commands path |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $path Custom commands path to add |
|
21
|
|
|
* @param bool $before If the path should be prepended or appended to the list |
|
22
|
|
|
* |
|
23
|
|
|
* @return void |
|
24
|
|
|
*/ |
|
25
|
36 |
|
public function addCommandsPath($path, $before = true) |
|
26
|
|
|
{ |
|
27
|
36 |
|
$paths = $this->get('commands.paths', []); |
|
28
|
|
|
|
|
29
|
36 |
|
if (! is_dir($path)) { |
|
30
|
1 |
|
Logger::error('Commands path "%s" does not exist.', $path); |
|
31
|
36 |
|
} else if (! in_array($path, $paths, true)) { |
|
32
|
36 |
|
if ($before) { |
|
33
|
35 |
|
array_unshift($paths, $path); |
|
34
|
|
|
} else { |
|
35
|
1 |
|
$paths[] = $path; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
36 |
|
$this->set('commands.paths', $paths); |
|
40
|
36 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Add multiple custom commands paths |
|
44
|
|
|
* |
|
45
|
|
|
* @param array $paths Custom commands paths to add |
|
46
|
|
|
* @param bool $before If the paths should be prepended or appended to the list |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
3 |
|
public function addCommandsPaths(array $paths, $before = true) |
|
51
|
|
|
{ |
|
52
|
3 |
|
foreach ($paths as $path) { |
|
53
|
3 |
|
$this->addCommandsPath($path, $before); |
|
54
|
|
|
} |
|
55
|
3 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Return the list of commands paths |
|
59
|
|
|
* |
|
60
|
|
|
* @return array |
|
61
|
|
|
*/ |
|
62
|
6 |
|
public function getCommandsPaths() |
|
63
|
|
|
{ |
|
64
|
6 |
|
return $this->get('commands.paths', []); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Enable a single Admin account |
|
69
|
|
|
* |
|
70
|
|
|
* @param integer $admin_id Single admin id |
|
71
|
|
|
* |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
2 |
|
public function addAdmin($admin_id) |
|
75
|
|
|
{ |
|
76
|
2 |
|
$admins = $this->get('admins', []); |
|
77
|
|
|
|
|
78
|
2 |
|
if (! is_int($admin_id) || $admin_id <= 0) { |
|
79
|
1 |
|
Logger::error('Invalid value "%s" for admin.', $admin_id); |
|
80
|
2 |
|
} else if (! in_array($admin_id, $admins, true)) { |
|
81
|
2 |
|
$admins[] = $admin_id; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
$this->set('admins', $admins); |
|
85
|
2 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Enable a list of Admin Accounts |
|
89
|
|
|
* |
|
90
|
|
|
* @param array $admin_ids List of admin ids |
|
91
|
|
|
* |
|
92
|
|
|
* @return void |
|
93
|
|
|
*/ |
|
94
|
2 |
|
public function addAdmins(array $admin_ids) |
|
95
|
|
|
{ |
|
96
|
2 |
|
foreach ($admin_ids as $admin_id) { |
|
97
|
2 |
|
$this->addAdmin($admin_id); |
|
98
|
|
|
} |
|
99
|
2 |
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get list of admins |
|
103
|
|
|
* |
|
104
|
|
|
* @return array |
|
105
|
|
|
*/ |
|
106
|
5 |
|
public function getAdmins() |
|
107
|
|
|
{ |
|
108
|
5 |
|
return $this->get('admins', []); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Set custom upload path |
|
113
|
|
|
* |
|
114
|
|
|
* @param string $path Custom upload path |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function setUploadPath($path) |
|
119
|
|
|
{ |
|
120
|
1 |
|
$this->set('upload_path', $path); |
|
121
|
1 |
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get custom upload path |
|
125
|
|
|
* |
|
126
|
|
|
* @return string |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function getUploadPath() |
|
129
|
|
|
{ |
|
130
|
1 |
|
return $this->get('upload_path', ''); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Set custom download path |
|
135
|
|
|
* |
|
136
|
|
|
* @param string $path Custom download path |
|
137
|
|
|
* |
|
138
|
|
|
* @return void |
|
139
|
|
|
*/ |
|
140
|
1 |
|
public function setDownloadPath($path) |
|
141
|
|
|
{ |
|
142
|
1 |
|
$this->set('download_path', $path); |
|
143
|
1 |
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Get custom download path |
|
147
|
|
|
* |
|
148
|
|
|
* @return string |
|
149
|
|
|
*/ |
|
150
|
1 |
|
public function getDownloadPath() |
|
151
|
|
|
{ |
|
152
|
1 |
|
return $this->get('download_path', ''); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|