Skip to content

Commit

Permalink
Allow providing token via config
Browse files Browse the repository at this point in the history
  • Loading branch information
Erdragh committed Mar 24, 2024
1 parent 9448cc0 commit d40e674
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions common/src/main/kotlin/dev/erdragh/astralbot/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ fun startAstralbot(server: MinecraftServer) {
LOGGER.debug("Created $MODID directory")
}

if (!env.containsKey("DISCORD_TOKEN")) {
LOGGER.warn("Not starting AstralBot because of missing DISCORD_TOKEN environment variable.")
val token: String? = env["DISCORD_TOKEN"] ?: AstralBotConfig.DISCORD_TOKEN.get()

if (token == null || token == "") {
LOGGER.warn("Not starting AstralBot because no token was not provided")
return
}

minecraftHandler = MinecraftHandler(server)

jda = JDABuilder.createLight(
env["DISCORD_TOKEN"],
token,
GatewayIntent.MESSAGE_CONTENT,
GatewayIntent.GUILD_MESSAGES,
GatewayIntent.GUILD_MEMBERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import java.net.URL
object AstralBotConfig {
val SPEC: ForgeConfigSpec

/**
* If the `DISCORD_TOKEN` environment variable isn't set, the bot will
* look for a token in this config option.
*/
val DISCORD_TOKEN: ForgeConfigSpec.ConfigValue<String>

/**
* Whether the default whitelisting process is respected or ignored.
* Setting this to `true` will *force* every user who wants to join
Expand Down Expand Up @@ -80,6 +86,9 @@ object AstralBotConfig {

builder.comment("AstralBot Config")

DISCORD_TOKEN = builder.comment("Discord token for the bot. Can also be supplied via DISCORD_TOKEN environment variable")
.define("token", "")

REQUIRE_LINK_FOR_WHITELIST = builder.comment("Whether to require being linked to be whitelisted")
.define("requireLinkForWhitelist", false)
DISCORD_LINK = builder.comment("Link to the discord where your users can run the /link command")
Expand Down

0 comments on commit d40e674

Please sign in to comment.