Skip to content

Commit 1eac648

Browse files
committed
Improve service provider
1 parent e06959b commit 1eac648

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/Laravel/PhpTelegramBotServiceProvider.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ public function boot()
3232
// Publish config files
3333
$this->publishes([
3434
__DIR__ . '/../config/config.php' => config_path('phptelegrambot.php'),
35-
]);
35+
], 'config');
3636

3737
// Append the default settings
3838
$this->mergeConfigFrom(
3939
__DIR__ . '/../config/config.php',
4040
'phptelegrambot'
4141
);
42+
43+
$this->publishes([
44+
__DIR__.'/../database/migrations/' => database_path('migrations')
45+
], 'migrations');
4246
}
4347

4448
/**
@@ -51,7 +55,39 @@ public function register()
5155
$this->app->bind(PhpTelegramBotContract::class, function (Application $app) {
5256
$config = $app['config']->get('phptelegrambot');
5357

54-
$bot = new PhpTelegramBot($config['api_key'], ! empty($config['name']) ? $config['name'] : []);
58+
$bot = new PhpTelegramBot($config['bot']['api_key'], ! empty($config['bot']['name']) ? $config['bot']['name'] : '');
59+
60+
// Add commands if paths are given
61+
if (! empty($config['commands']['paths'])) {
62+
$bot->addCommandsPaths($config['commands']['paths']);
63+
}
64+
65+
// Set command related configs
66+
if (! empty($config['commands']['configs'])) {
67+
foreach ($config['commands']['configs'] as $command_name => $command_config) {
68+
$bot->setCommandConfig($command_name, $command_config);
69+
}
70+
}
71+
72+
// Set database connection
73+
if ($config['database']['enabled'] === true) {
74+
/** @var \Illuminate\Database\Connection $connection */
75+
$connection = $app['db']->connection($config['database']['connection']);
76+
$bot->enableExternalMySql($connection->getPdo());
77+
}
78+
79+
// Enable admins if provided
80+
if (! empty($config['admins'])) {
81+
$bot->enableAdmins($config['admins']);
82+
}
83+
84+
// Set paths
85+
if (! empty($config['download_path'])) {
86+
$bot->setDownloadPath($config['download_path']);
87+
}
88+
if (! empty($config['upload_path'])) {
89+
$bot->setUploadPath($config['upload_path']);
90+
}
5591

5692
return $bot;
5793
});

0 commit comments

Comments
 (0)