-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18dcb1f
commit 4ae4a0f
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* KookBC -- The Kook Bot Client & JKook API standard implementation for Java. | ||
* Copyright (C) 2022 - 2023 KookBC contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package snw.kookbc.launcher; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import snw.jkook.JKook; | ||
import snw.jkook.config.file.YamlConfiguration; | ||
import snw.kookbc.impl.CoreImpl; | ||
import snw.kookbc.impl.KBCClient; | ||
import snw.kookbc.impl.command.CommandManagerImpl; | ||
|
||
import java.io.File; | ||
|
||
public class EmbeddedLauncher extends Launcher { | ||
private String token; | ||
private final YamlConfiguration config; | ||
private final Logger logger; | ||
private final File pluginsFolder; | ||
|
||
private KBCClient client; | ||
private CoreImpl core; | ||
|
||
public EmbeddedLauncher(@NotNull File configFile) { | ||
this(YamlConfiguration.loadConfiguration(configFile), null, null, null); | ||
} | ||
|
||
public EmbeddedLauncher(@NotNull YamlConfiguration config, @Nullable String token, @Nullable Logger logger, @Nullable File pluginsFolder) { | ||
super(); | ||
this.config = config; | ||
this.token = token; | ||
this.logger = logger; | ||
this.pluginsFolder = pluginsFolder; | ||
} | ||
|
||
public KBCClient getClient() { | ||
if (client != null) { | ||
return client; | ||
} | ||
build(); | ||
return client; | ||
} | ||
|
||
public CoreImpl getCore() { | ||
if (core != null) { | ||
return core; | ||
} | ||
build(); | ||
return core; | ||
} | ||
|
||
protected void build() { | ||
if (logger != null) { | ||
core = new CoreImpl(logger); | ||
} else { | ||
core = new CoreImpl(); | ||
} | ||
JKook.setCore(core); | ||
|
||
if (token == null) { | ||
String configToken = config.getString("token"); | ||
if (configToken != null && !configToken.isEmpty()) { | ||
if (token == null || token.isEmpty()) { | ||
token = configToken; | ||
} | ||
} else { | ||
throw new IllegalArgumentException("Token is not set"); | ||
} | ||
} | ||
client = new KBCClient(core, config, pluginsFolder, token, CommandManagerImpl::new, | ||
null, null, null, null, null, null); | ||
} | ||
} |