|
18 | 18 | import org.slf4j.LoggerFactory; |
19 | 19 | import org.springframework.stereotype.Service; |
20 | 20 |
|
| 21 | +import java.util.Map; |
21 | 22 | import java.util.Objects; |
22 | 23 |
|
| 24 | +import static java.util.Map.entry; |
| 25 | + |
23 | 26 | @Service |
24 | 27 | public class DuncteBotInjector implements AudioPlayerManagerConfiguration { |
25 | | - private final DuncteBotConfig config; |
26 | | - private final DuncteBotConfig.Sources sourcesConfig; |
| 28 | + private final Logger logger = LoggerFactory.getLogger(DuncteBotInjector.class); |
| 29 | + private final Map<String, SourceManagerInfo> sourceManagers; |
27 | 30 |
|
28 | 31 | public DuncteBotInjector(DuncteBotConfig config, DuncteBotConfig.Sources sourcesConfig) { |
29 | | - this.config = config; |
30 | | - this.sourcesConfig = sourcesConfig; |
| 32 | + |
| 33 | + this.sourceManagers = Map.ofEntries( |
| 34 | + entry("yarn", new SourceManagerInfo(sourcesConfig::isGetyarn, GetyarnAudioSourceManager::new)), |
| 35 | + entry("clypit", new SourceManagerInfo(sourcesConfig::isClypit, ClypitAudioSourceManager::new)), |
| 36 | + entry("PornHub", new SourceManagerInfo(sourcesConfig::isPornhub, PornHubAudioSourceManager::new)), |
| 37 | + entry("Reddit", new SourceManagerInfo(sourcesConfig::isReddit, RedditAudioSourceManager::new)), |
| 38 | + entry("OC Remix", new SourceManagerInfo(sourcesConfig::isOcremix, OCRemixAudioSourceManager::new)), |
| 39 | + entry("TikTok", new SourceManagerInfo(sourcesConfig::isTiktok, TikTokAudioSourceManager::new)), |
| 40 | + entry("Mixcloud", new SourceManagerInfo(sourcesConfig::isMixcloud, MixcloudAudioSourceManager::new)), |
| 41 | + entry("Soundgasm", new SourceManagerInfo(sourcesConfig::isSoundgasm, SoundGasmAudioSourceManager::new)), |
| 42 | + entry("Elgato (.streamDeckAudio)", new SourceManagerInfo(sourcesConfig::isElgato, StreamDeckAudioSourceManager::new)), |
| 43 | + entry("pixeldrain", new SourceManagerInfo(sourcesConfig::isPixeldrain, PixeldrainAudioSourceManager::new)), |
| 44 | + entry("Text To Speech", new SourceManagerInfo(sourcesConfig::isTts, () -> { |
| 45 | + final String lang = Objects.requireNonNullElse(config.getTtsLanguage(), "en-AU"); |
| 46 | + |
| 47 | + logger.info("TTS language is: {}", lang); |
| 48 | + |
| 49 | + return new SpeechAudioSourceManager(lang); |
| 50 | + })) |
| 51 | + ); |
31 | 52 | } |
32 | 53 |
|
33 | 54 | @NotNull |
34 | 55 | @Override |
35 | 56 | public AudioPlayerManager configure(@NotNull AudioPlayerManager manager) { |
36 | | - final Logger logger = LoggerFactory.getLogger(DuncteBotInjector.class); |
37 | 57 |
|
38 | 58 | // register custom source managers |
39 | | - |
40 | | - if (this.sourcesConfig.isGetyarn()) { |
41 | | - logger.info("Registering getyarn audio source manager"); |
42 | | - manager.registerSourceManager(new GetyarnAudioSourceManager()); |
43 | | - } |
44 | | - |
45 | | - if (this.sourcesConfig.isClypit()) { |
46 | | - logger.info("Registering clypit audio source manager"); |
47 | | - manager.registerSourceManager(new ClypitAudioSourceManager()); |
48 | | - } |
49 | | - |
50 | | - if (this.sourcesConfig.isTts()) { |
51 | | - final String lang = Objects.requireNonNullElse(this.config.getTtsLanguage(), "en-AU"); |
52 | | - |
53 | | - logger.info("Registering text to speech audio source manager with language {}", lang); |
54 | | - manager.registerSourceManager(new SpeechAudioSourceManager(lang)); |
55 | | - } |
56 | | - |
57 | | - if (this.sourcesConfig.isPornhub()) { |
58 | | - logger.info("Registering PornHub audio source manager"); |
59 | | - manager.registerSourceManager(new PornHubAudioSourceManager()); |
60 | | - } |
61 | | - |
62 | | - if (this.sourcesConfig.isReddit()) { |
63 | | - logger.info("Registering reddit audio source manager"); |
64 | | - manager.registerSourceManager(new RedditAudioSourceManager()); |
65 | | - } |
66 | | - |
67 | | - if (this.sourcesConfig.isOcremix()) { |
68 | | - logger.info("Registering OC Remix audio source manager"); |
69 | | - manager.registerSourceManager(new OCRemixAudioSourceManager()); |
70 | | - } |
71 | | - |
72 | | - if (this.sourcesConfig.isTiktok()) { |
73 | | - logger.info("Registering TikTok audio source manager"); |
74 | | - manager.registerSourceManager(new TikTokAudioSourceManager()); |
75 | | - } |
76 | | - |
77 | | - if (this.sourcesConfig.isMixcloud()) { |
78 | | - logger.info("Registering Mixcloud audio source manager"); |
79 | | - manager.registerSourceManager(new MixcloudAudioSourceManager()); |
80 | | - } |
81 | | - |
82 | | - if (this.sourcesConfig.isSoundgasm()) { |
83 | | - logger.info("Registering Soundgasm audio source manager"); |
84 | | - manager.registerSourceManager(new SoundGasmAudioSourceManager()); |
85 | | - } |
86 | | - |
87 | | - if (this.sourcesConfig.isElgato()) { |
88 | | - logger.warn("Elgato (.streamDeckAudio) audio source manager is not supported atm"); |
89 | | -// logger.info("Registering Elgato (.streamDeckAudio) audio source manager"); |
90 | | -// manager.registerSourceManager(new StreamDeckAudioSourceManager()); |
91 | | - } |
92 | | - |
93 | | - if (this.sourcesConfig.isPixeldrain()) { |
94 | | - logger.info("Registering pixeldrain audio source manager"); |
95 | | - manager.registerSourceManager(new PixeldrainAudioSourceManager()); |
| 59 | + for (var entry : this.sourceManagers.entrySet()) { |
| 60 | + final var info = entry.getValue(); |
| 61 | + |
| 62 | + if (info.configSupplier().getAsBoolean()) { |
| 63 | + logger.info("Registering {} audio source manager", entry.getKey()); |
| 64 | + manager.registerSourceManager(info.supplier().get()); |
| 65 | + } else { |
| 66 | + logger.info("{} audio source manager is disabled, skipping it", entry.getKey()); |
| 67 | + } |
96 | 68 | } |
97 | 69 |
|
98 | 70 | return manager; |
|
0 commit comments