From 8a27740ecd973b6e1e8f215effba3051d56a8cdf Mon Sep 17 00:00:00 2001 From: SciWhiz12 Date: Sat, 27 Mar 2021 12:10:21 +0800 Subject: [PATCH] Add config file and CLI options --- build.gradle | 5 +- gradle.properties | 5 +- .../java/tk/sciwhiz12/janitor/BotStartup.java | 28 ----- .../tk/sciwhiz12/janitor/bot/BotStartup.java | 61 ++++++++++ .../janitor/bot/config/BotFileConfig.java | 104 ++++++++++++++++++ .../janitor/bot/config/BotOptions.java | 59 ++++++++++ .../bot/config/CommandLineBotOptions.java | 103 +++++++++++++++++ .../janitor/bot/config/MergedBotOptions.java | 75 +++++++++++++ src/main/resources/bot-config.toml | 13 +++ 9 files changed, 423 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/tk/sciwhiz12/janitor/BotStartup.java create mode 100644 src/main/java/tk/sciwhiz12/janitor/bot/BotStartup.java create mode 100644 src/main/java/tk/sciwhiz12/janitor/bot/config/BotFileConfig.java create mode 100644 src/main/java/tk/sciwhiz12/janitor/bot/config/BotOptions.java create mode 100644 src/main/java/tk/sciwhiz12/janitor/bot/config/CommandLineBotOptions.java create mode 100644 src/main/java/tk/sciwhiz12/janitor/bot/config/MergedBotOptions.java create mode 100644 src/main/resources/bot-config.toml diff --git a/build.gradle b/build.gradle index 76ed77e..f356436 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,9 @@ dependencies { implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_ver" implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_ver" implementation "ch.qos.logback:logback-classic:$logback_ver" + implementation "com.electronwill.night-config:toml:$nightconfig_ver" + implementation "it.unimi.dsi:fastutil:$fastutil_ver" + implementation "net.sf.jopt-simple:jopt-simple:$jopt_ver" testImplementation "org.junit.jupiter:junit-jupiter:$junit_ver" } @@ -29,7 +32,7 @@ java { } application { - mainClass = 'tk.sciwhiz12.janitor.App' + mainClass = 'tk.sciwhiz12.janitor.bot.BotStartup' } jar { diff --git a/gradle.properties b/gradle.properties index 33c35ae..4ba9199 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,7 @@ junit_ver=5.7.1 jda_ver=4.2.0_222 guava_ver=29.0-jre jackson_ver=2.11.2 -logback_ver=1.3.0-alpha5 \ No newline at end of file +logback_ver=1.3.0-alpha5 +nightconfig_ver=3.6.3 +fastutil_ver=8.5.2 +jopt_ver=6.0-alpha-3 \ No newline at end of file diff --git a/src/main/java/tk/sciwhiz12/janitor/BotStartup.java b/src/main/java/tk/sciwhiz12/janitor/BotStartup.java deleted file mode 100644 index 5f359a1..0000000 --- a/src/main/java/tk/sciwhiz12/janitor/BotStartup.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2021 SciWhiz12 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package tk.sciwhiz12.janitor; - -public class BotStartup { - public static void main(String[] args) { - - } -} diff --git a/src/main/java/tk/sciwhiz12/janitor/bot/BotStartup.java b/src/main/java/tk/sciwhiz12/janitor/bot/BotStartup.java new file mode 100644 index 0000000..bcf47cc --- /dev/null +++ b/src/main/java/tk/sciwhiz12/janitor/bot/BotStartup.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package tk.sciwhiz12.janitor.bot; + +import tk.sciwhiz12.janitor.bot.config.BotFileConfig; +import tk.sciwhiz12.janitor.bot.config.BotOptions; +import tk.sciwhiz12.janitor.bot.config.CommandLineBotOptions; +import tk.sciwhiz12.janitor.bot.config.MergedBotOptions; + +import java.nio.file.Path; + +public class BotStartup { + public static void main(String[] args) { + CommandLineBotOptions cmdLine = new CommandLineBotOptions(args); + Path configFile = cmdLine.getConfigFile(); + BotFileConfig fileConfig = new BotFileConfig(configFile); + + BotOptions options = new MergedBotOptions(fileConfig, cmdLine); + } + +} diff --git a/src/main/java/tk/sciwhiz12/janitor/bot/config/BotFileConfig.java b/src/main/java/tk/sciwhiz12/janitor/bot/config/BotFileConfig.java new file mode 100644 index 0000000..c948950 --- /dev/null +++ b/src/main/java/tk/sciwhiz12/janitor/bot/config/BotFileConfig.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package tk.sciwhiz12.janitor.bot.config; + +import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import com.google.common.primitives.Longs; +import it.unimi.dsi.fastutil.longs.LongArraySet; +import it.unimi.dsi.fastutil.longs.LongSet; + +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * File-backed bot configuration. + */ +public class BotFileConfig implements BotOptions { + private final CommentedFileConfig config; + + public BotFileConfig(Path botConfigFile) { + config = CommentedFileConfig.builder(botConfigFile) + .defaultResource("/bot-config.toml") + .build(); + config.load(); + } + + @Override + public Optional getToken() { + return config.getOptional("token").map(str -> str.isBlank() ? null : str); + } + + @Override + public Optional getBotOwners() { + //noinspection ConstantConditions + return config.>getOptional("owners") + .map(list -> new LongArraySet(list.stream() + .filter(str -> Longs.tryParse(str) != null) + .map(Longs::tryParse) + .collect(Collectors.toUnmodifiableList()))) + .map(list -> list.isEmpty() ? null : list); + } +} diff --git a/src/main/java/tk/sciwhiz12/janitor/bot/config/BotOptions.java b/src/main/java/tk/sciwhiz12/janitor/bot/config/BotOptions.java new file mode 100644 index 0000000..297f456 --- /dev/null +++ b/src/main/java/tk/sciwhiz12/janitor/bot/config/BotOptions.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package tk.sciwhiz12.janitor.bot.config; + +import it.unimi.dsi.fastutil.longs.LongSet; + +import java.util.Optional; + +/** + * Configuration options interface for the main bot configuration. + * + *

The configuration options exposed by this class are meant for controlling bot behaviors by the bot owner. + * These configuration options are also meant to be read-only.

+ */ +public interface BotOptions { + Optional getToken(); + + Optional getBotOwners(); +} diff --git a/src/main/java/tk/sciwhiz12/janitor/bot/config/CommandLineBotOptions.java b/src/main/java/tk/sciwhiz12/janitor/bot/config/CommandLineBotOptions.java new file mode 100644 index 0000000..7615718 --- /dev/null +++ b/src/main/java/tk/sciwhiz12/janitor/bot/config/CommandLineBotOptions.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package tk.sciwhiz12.janitor.bot.config; + +import com.google.common.primitives.Longs; +import it.unimi.dsi.fastutil.longs.LongArraySet; +import it.unimi.dsi.fastutil.longs.LongSet; +import joptsimple.ArgumentAcceptingOptionSpec; +import joptsimple.OptionParser; +import joptsimple.OptionSet; +import joptsimple.util.PathConverter; +import joptsimple.util.PathProperties; + +import javax.annotation.Nullable; +import java.nio.file.Path; +import java.util.Optional; +import java.util.stream.Collectors; + +import static java.util.List.of; + +public class CommandLineBotOptions implements BotOptions { + @Nullable + private final String token; + private final LongSet owners; + private final Path configFile; + + public CommandLineBotOptions(String[] args) { + OptionParser parser = new OptionParser(); + ArgumentAcceptingOptionSpec token = parser.acceptsAll(of("token", "t"), "Discord API token") + .withRequiredArg(); + ArgumentAcceptingOptionSpec owners = parser.acceptsAll(of("owner", "o"), "Snowflake ID(s) of bot owners") + .withRequiredArg().withValuesSeparatedBy(','); + ArgumentAcceptingOptionSpec configFile = parser.acceptsAll(of("config", "config-file", "c"), "Bot config file") + .withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING, PathProperties.WRITABLE)) + .defaultsTo(Path.of("bot-config.toml")); + + OptionSet parsed = parser.parse(args); + + this.token = parsed.valueOf(token); + + //noinspection ConstantConditions + this.owners = new LongArraySet(parsed.valuesOf(owners).stream() + .filter(str -> Longs.tryParse(str) != null) + .map(Longs::tryParse) + .collect(Collectors.toUnmodifiableList())); + + this.configFile = parsed.valueOf(configFile); + } + + @Override + public Optional getToken() { + return Optional.ofNullable(this.token); + } + + @Override + public Optional getBotOwners() { + return this.owners.isEmpty() ? Optional.empty() : Optional.of(this.owners); + } + + public Path getConfigFile() { + return this.configFile; + } +} diff --git a/src/main/java/tk/sciwhiz12/janitor/bot/config/MergedBotOptions.java b/src/main/java/tk/sciwhiz12/janitor/bot/config/MergedBotOptions.java new file mode 100644 index 0000000..3d182b5 --- /dev/null +++ b/src/main/java/tk/sciwhiz12/janitor/bot/config/MergedBotOptions.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * Copyright (c) 2021 SciWhiz12 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package tk.sciwhiz12.janitor.bot.config; + +import it.unimi.dsi.fastutil.longs.LongSet; + +import java.util.Optional; + +public class MergedBotOptions implements BotOptions { + private final BotOptions parent; + private final BotOptions child; + + public MergedBotOptions(BotOptions parent, BotOptions child) { + this.parent = parent; + this.child = child; + } + + public BotOptions getParent() { + return parent; + } + + public BotOptions getChild() { + return child; + } + + @Override + public Optional getToken() { + return child.getToken().or(parent::getToken); + } + + @Override + public Optional getBotOwners() { + return child.getBotOwners().or(parent::getBotOwners); + } +} diff --git a/src/main/resources/bot-config.toml b/src/main/resources/bot-config.toml new file mode 100644 index 0000000..030b303 --- /dev/null +++ b/src/main/resources/bot-config.toml @@ -0,0 +1,13 @@ +# Bot-specific configuration for Janitor +# These configurations are read-only, and will not be modified + +# The bot client token, used when connecting to the Discord API. +# Must be specified, either here or using the command line interface. +token = "" + +# List of snowflake IDs of users who act as bot owners. +# Bot owners have access to bot maintenance commands, along with specific admin commands for troubleshooting +# May be unspecified. Defaults to sciwhiz12#1286, maintainer of Janitor +owners = [ 607058472709652501 ] + +