@@ -32,13 +32,17 @@ public function boot()
32
32
// Publish config files
33
33
$ this ->publishes ([
34
34
__DIR__ . '/../config/config.php ' => config_path ('phptelegrambot.php ' ),
35
- ]);
35
+ ], ' config ' );
36
36
37
37
// Append the default settings
38
38
$ this ->mergeConfigFrom (
39
39
__DIR__ . '/../config/config.php ' ,
40
40
'phptelegrambot '
41
41
);
42
+
43
+ $ this ->publishes ([
44
+ __DIR__ .'/../database/migrations/ ' => database_path ('migrations ' )
45
+ ], 'migrations ' );
42
46
}
43
47
44
48
/**
@@ -51,7 +55,39 @@ public function register()
51
55
$ this ->app ->bind (PhpTelegramBotContract::class, function (Application $ app ) {
52
56
$ config = $ app ['config ' ]->get ('phptelegrambot ' );
53
57
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
+ }
55
91
56
92
return $ bot ;
57
93
});
0 commit comments