1 | <?php |
||
14 | class BotsManager |
||
15 | { |
||
16 | /** |
||
17 | * The config instance. |
||
18 | * |
||
19 | * @var \Illuminate\Contracts\Config\Repository |
||
20 | */ |
||
21 | protected $config; |
||
22 | |||
23 | /** |
||
24 | * The app instance. |
||
25 | * |
||
26 | * @var \Illuminate\Contracts\Foundation\Application |
||
27 | */ |
||
28 | protected $app; |
||
29 | |||
30 | /** |
||
31 | * @var string Config Name |
||
32 | */ |
||
33 | protected $configName = 'telegram'; |
||
34 | |||
35 | /** |
||
36 | * The active bot instances. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $bots = []; |
||
41 | |||
42 | /** |
||
43 | * TelegramManager constructor. |
||
44 | * |
||
45 | * @param Repository $config |
||
46 | * @param Application $app |
||
47 | */ |
||
48 | public function __construct(Repository $config, Application $app) |
||
53 | |||
54 | /** |
||
55 | * Get the configuration for a bot. |
||
56 | * |
||
57 | * @param string $name |
||
58 | * |
||
59 | * @throws \InvalidArgumentException |
||
60 | * |
||
61 | * @return array |
||
62 | */ |
||
63 | public function getBotConfig($name) |
||
76 | |||
77 | /** |
||
78 | * Get a bot instance. |
||
79 | * |
||
80 | * @param string $name |
||
81 | * |
||
82 | * @return object |
||
83 | */ |
||
84 | public function bot($name = null) |
||
94 | |||
95 | /** |
||
96 | * Reconnect to the given bot. |
||
97 | * |
||
98 | * @param string $name |
||
99 | * |
||
100 | * @return object |
||
101 | */ |
||
102 | public function reconnect($name = null) |
||
109 | |||
110 | /** |
||
111 | * Disconnect from the given bot. |
||
112 | * |
||
113 | * @param string $name |
||
114 | * |
||
115 | * @return void |
||
116 | */ |
||
117 | public function disconnect($name = null) |
||
122 | |||
123 | /** |
||
124 | * Get the specified configuration value for Telegram. |
||
125 | * |
||
126 | * @param string $key |
||
127 | * @param mixed $default |
||
128 | * |
||
129 | * @return mixed |
||
130 | */ |
||
131 | public function getConfig($key, $default = null) |
||
135 | |||
136 | /** |
||
137 | * Get the default bot name. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getDefaultBot() |
||
145 | |||
146 | /** |
||
147 | * Set the default bot name. |
||
148 | * |
||
149 | * @param string $name |
||
150 | * |
||
151 | * @return void |
||
152 | */ |
||
153 | public function setDefaultBot($name) |
||
157 | |||
158 | /** |
||
159 | * Return all of the created bots. |
||
160 | * |
||
161 | * @return object[] |
||
162 | */ |
||
163 | public function getBots() |
||
167 | |||
168 | /** |
||
169 | * De-duplicate an array. |
||
170 | * |
||
171 | * @param array $array |
||
172 | * |
||
173 | * @return array |
||
174 | */ |
||
175 | protected function deduplicateArray(array $array) |
||
179 | |||
180 | /** |
||
181 | * Make the bot instance. |
||
182 | * |
||
183 | * @param string $name |
||
184 | * |
||
185 | * @return Api |
||
186 | */ |
||
187 | protected function makeBot($name) |
||
212 | |||
213 | /** |
||
214 | * Builds the list of commands for the given commands array. |
||
215 | * |
||
216 | * @param array $commands |
||
217 | * |
||
218 | * @return array An array of commands which includes global and bot specific commands. |
||
219 | */ |
||
220 | protected function parseBotCommands(array $commands) |
||
227 | |||
228 | /** |
||
229 | * Parse an array of commands and build a list. |
||
230 | * |
||
231 | * @param array $commands |
||
232 | * |
||
233 | * @return array |
||
234 | */ |
||
235 | protected function parseCommands(array $commands) |
||
270 | |||
271 | /** |
||
272 | * Magically pass methods to the default bot. |
||
273 | * |
||
274 | * @param string $method |
||
275 | * @param array $parameters |
||
276 | * |
||
277 | * @return mixed |
||
278 | */ |
||
279 | public function __call($method, $parameters) |
||
283 | } |