11package com .dunctebot .tss ;
22
33import com .sedmelluq .discord .lavaplayer .player .AudioPlayerManager ;
4+ import com .sedmelluq .discord .lavaplayer .tools .JsonBrowser ;
45import dev .arbjerg .lavalink .api .AudioPlayerManagerConfiguration ;
56import org .slf4j .Logger ;
67import org .slf4j .LoggerFactory ;
78import org .springframework .stereotype .Service ;
89import org .springframework .util .StringUtils ;
910
11+ import java .io .File ;
12+ import java .nio .file .Files ;
13+
1014@ Service
1115public class TTSPlugin implements AudioPlayerManagerConfiguration {
1216 private static final Logger LOG = LoggerFactory .getLogger (TTSPlugin .class );
@@ -15,6 +19,8 @@ public class TTSPlugin implements AudioPlayerManagerConfiguration {
1519 public TTSPlugin (LavalinkTTSConfig config ) throws Exception {
1620 LOG .info ("Loading GCLOUD TTS plugin" );
1721
22+ this .checkEnvVar (config );
23+
1824 if (StringUtils .isEmpty (config .getClientEmail ())) {
1925 LOG .error ("Client email is not set in the config, aborting. Config key is 'plugins.dunctebot.tts.clientEmail'" );
2026 return ;
@@ -36,4 +42,23 @@ public AudioPlayerManager configure(AudioPlayerManager manager) {
3642
3743 return manager ;
3844 }
45+
46+ private void checkEnvVar (LavalinkTTSConfig config ) {
47+ final String googleCreds = System .getenv ("GOOGLE_APPLICATION_CREDENTIALS" );
48+
49+ if (googleCreds == null ) {
50+ return ;
51+ }
52+
53+ try {
54+ final String json = Files .readString (new File (googleCreds ).toPath ());
55+ final JsonBrowser browser = JsonBrowser .parse (json );
56+
57+ config .setClientEmail (browser .get ("client_email" ).text ());
58+ config .setPrivateKey (browser .get ("private_key" ).text ());
59+ } catch (Exception e ) {
60+ // Fail silently?
61+ LOG .error ("Found google application credentials but could not parse json" , e );
62+ }
63+ }
3964}
0 commit comments