|
1 | 1 | package ru.untitled_devs.bot; |
2 | 2 |
|
3 | | -import com.mongodb.client.MongoClient; |
4 | | -import com.mongodb.client.MongoClients; |
5 | | -import dev.morphia.Datastore; |
6 | | -import dev.morphia.Morphia; |
7 | | -import org.slf4j.Logger; |
8 | | -import org.slf4j.LoggerFactory; |
9 | | -import org.telegram.telegrambots.meta.TelegramBotsApi; |
10 | | -import org.telegram.telegrambots.updatesreceivers.DefaultBotSession; |
11 | | -import ru.untitled_devs.bot.config.Config; |
12 | | -import ru.untitled_devs.bot.features.localisation.LocalisationMiddleware; |
13 | | -import ru.untitled_devs.bot.features.localisation.LocalisationScene; |
14 | | -import ru.untitled_devs.bot.features.menu.MainMenuScene; |
15 | | -import ru.untitled_devs.bot.features.registration.LoginMiddleware; |
16 | | -import ru.untitled_devs.bot.features.registration.RegistrationScene; |
17 | | -import ru.untitled_devs.bot.features.registration.RegistrationService; |
18 | | -import ru.untitled_devs.bot.features.start.StartMiddleware; |
19 | | -import ru.untitled_devs.bot.shared.geocoder.Geocoder; |
20 | | -import ru.untitled_devs.bot.shared.geocoder.yandex.YandexGeocoder; |
21 | | -import ru.untitled_devs.bot.shared.image.ImageService; |
22 | | -import ru.untitled_devs.core.client.PollingClient; |
23 | | -import ru.untitled_devs.core.dispatcher.Dispatcher; |
24 | | -import ru.untitled_devs.core.fsm.storage.InMemoryStorage; |
25 | | -import ru.untitled_devs.core.routers.scenes.SceneManager; |
26 | | -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; |
27 | | -import software.amazon.awssdk.auth.credentials.AwsCredentials; |
28 | | -import software.amazon.awssdk.regions.Region; |
29 | | - |
30 | | -import java.net.URI; |
| 3 | +import com.google.inject.Guice; |
| 4 | +import com.google.inject.Injector; |
| 5 | +import ru.untitled_devs.bot.di.AppModule; |
31 | 6 |
|
32 | 7 | public class Main { |
33 | 8 | public static void main(String[] args) { |
34 | | - InMemoryStorage storage = new InMemoryStorage(); |
35 | | - SceneManager sceneManager = new SceneManager(); |
36 | | - Logger logger = LoggerFactory.getLogger(Main.class); |
37 | | - Dispatcher dispatcher = new Dispatcher(storage, sceneManager); |
38 | | - MongoClient client = MongoClients.create(Config.getMongoConfig().getMongoString()); |
39 | | - Datastore datastore = Morphia.createDatastore(client, Config.getMongoConfig().getMongoDBName()); |
40 | | - |
41 | | - Geocoder geocoder = |
42 | | - new YandexGeocoder(Config.getGeocodingConfig().getApiUrl(), |
43 | | - Config.getGeocodingConfig().getApiKey()); |
44 | | - |
45 | | - RegistrationService regService = new RegistrationService(datastore); |
46 | | - |
47 | | - URI endpoint = URI.create(Config.getS3Config().getEndpoint()); |
48 | | - String accessKey = Config.getS3Config().getAccessKey(); |
49 | | - String secretKey = Config.getS3Config().getSecretKey(); |
50 | | - String bucketName = Config.getS3Config().getBucketName(); |
51 | | - AwsCredentials credentials = AwsBasicCredentials.create(accessKey, secretKey); |
52 | | - Region region = Region.US_EAST_1; |
53 | | - ImageService imageService = new ImageService(endpoint, credentials, region, bucketName, datastore); |
54 | | - |
55 | | - try { |
56 | | - TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class); |
57 | | - PollingClient bot = new PollingClient(Config.getBotConfig().getBotToken(), |
58 | | - Config.getBotConfig().getBotName(), dispatcher); |
59 | | - |
60 | | - sceneManager.register("register", new RegistrationScene(bot, regService, geocoder, imageService, sceneManager)); |
61 | | - sceneManager.register("lang", new LocalisationScene(bot)); |
62 | | - sceneManager.register("menu", new MainMenuScene(bot, sceneManager)); |
63 | | - |
64 | | - dispatcher.addMiddleware(new LocalisationMiddleware(sceneManager)); |
65 | | - dispatcher.addMiddleware(new LoginMiddleware(sceneManager, regService)); |
66 | | - dispatcher.addMiddleware(new StartMiddleware(sceneManager)); |
67 | | - |
68 | | - botsApi.registerBot(bot); |
69 | | - } catch (Exception e) { |
70 | | - logger.error(e.getMessage()); |
71 | | - } |
72 | | - } |
| 9 | + Injector injector = Guice.createInjector(new AppModule()); |
| 10 | + injector.getInstance(Bootstrap.class).start(); |
| 11 | + } |
73 | 12 | } |
0 commit comments