Convert config fields to methods

This commit is contained in:
Norbi Peti 2023-05-06 14:33:12 +02:00
parent 5d0bd37b28
commit 6bd1de6217
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
6 changed files with 25 additions and 28 deletions

View file

@ -77,18 +77,16 @@ import scala.jdk.OptionConverters.*
/**
* The (bot) channel to use for Discord commands like /role.
*/
var commandChannel: ConfigData[Snowflake] = DPUtils.snowflakeData(getIConfig, "commandChannel", 0L)
def commandChannel: ConfigData[Snowflake] = DPUtils.snowflakeData(getIConfig, "commandChannel", 0L)
/**
* The role that allows using mod-only Discord commands.
* If empty (''), then it will only allow for the owner.
*/
var modRole: ConfigData[Mono[Role]] = null
def modRole: ConfigData[Mono[Role]] = DPUtils.roleData(getIConfig, "modRole", "Moderator")
/**
* The invite link to show by /discord invite. If empty, it defaults to the first invite if the bot has access.
*/
var inviteLink: ConfigData[String] = getIConfig.getData("inviteLink", "")
private def setupConfig(): Unit = modRole = DPUtils.roleData(getIConfig, "modRole", "Moderator")
def inviteLink: ConfigData[String] = getIConfig.getData("inviteLink", "")
override def onLoad(): Unit = { //Needed by ServerWatcher
val thread = Thread.currentThread
@ -172,7 +170,6 @@ import scala.jdk.OptionConverters.*
mainServer.set(Option(DiscordPlugin.mainServer)) //Save in config
}
DiscordPlugin.SafeMode = false
setupConfig()
DPUtils.disableIfConfigErrorRes(null, commandChannel, DPUtils.getMessageChannel(commandChannel))
//Won't disable, just prints the warning here
if (MinecraftChatModule.state eq DPState.STOPPING_SERVER) {

View file

@ -23,21 +23,21 @@ import scala.collection.mutable
/**
* Channel to post new posts.
*/
final val channel = DPUtils.channelData(getConfig, "channel")
final def channel = DPUtils.channelData(getConfig, "channel")
/**
* Channel where distinguished (moderator) posts go.
*/
final private val modChannel = DPUtils.channelData(getConfig, "modChannel")
final private def modChannel = DPUtils.channelData(getConfig, "modChannel")
/**
* Automatically unpins all messages except the last few. Set to 0 or >50 to disable
*/
final private val keepPinned = getConfig.getData("keepPinned", 40.toShort)
final private val lastAnnouncementTime = getConfig.getData("lastAnnouncementTime", 0L)
final private val lastSeenTime = getConfig.getData("lastSeenTime", 0L)
final private def keepPinned = getConfig.getData("keepPinned", 40.toShort)
final private def lastAnnouncementTime = getConfig.getData("lastAnnouncementTime", 0L)
final private def lastSeenTime = getConfig.getData("lastSeenTime", 0L)
/**
* The subreddit to pull the posts from
*/
final private val subredditURL = getConfig.getData("subredditURL", "https://www.reddit.com/r/ChromaGamers")
final private def subredditURL = getConfig.getData("subredditURL", "https://www.reddit.com/r/ChromaGamers")
override protected def enable(): Unit = {
if (DPUtils.disableIfConfigError(this, channel, modChannel)) return ()

View file

@ -75,7 +75,7 @@ class ExceptionListenerModule extends Component[DiscordPlugin] with Listener {
/**
* The channel to post the errors to.
*/
final private val channel = DPUtils.channelData(getConfig, "channel")
final private def channel = DPUtils.channelData(getConfig, "channel")
/**
* The role to ping if an error occurs. Set to empty ('') to disable.

View file

@ -97,7 +97,7 @@ class FunModule extends Component[DiscordPlugin] with Listener {
/**
* Questions that the bot will choose a random answer to give to.
*/
final private val serverReady: ConfigData[Array[String]] =
final private def serverReady: ConfigData[Array[String]] =
getConfig.getData("serverReady", Array[String](
"when will the server be open", "when will the server be ready",
"when will the server be done", "when will the server be complete",
@ -106,7 +106,7 @@ class FunModule extends Component[DiscordPlugin] with Listener {
/**
* Answers for a recognized question. Selected randomly.
*/
final private val serverReadyAnswers: ConfigData[util.ArrayList[String]] =
final private def serverReadyAnswers: ConfigData[util.ArrayList[String]] =
getConfig.getData("serverReadyAnswers", Lists.newArrayList(FunModule.serverReadyStrings: _*))
private def createUsableServerReadyStrings(): Unit =
@ -130,5 +130,5 @@ class FunModule extends Component[DiscordPlugin] with Listener {
/**
* The channel to post the full house to.
*/
final private val fullHouseChannel = DPUtils.channelData(getConfig, "fullHouseChannel")
final private def fullHouseChannel = DPUtils.channelData(getConfig, "fullHouseChannel")
}

View file

@ -37,56 +37,56 @@ class MinecraftChatModule extends Component[DiscordPlugin] {
/**
* A list of commands that can be used in public chats - Warning: Some plugins will treat players as OPs, always test before allowing a command!
*/
val whitelistedCommands: ConfigData[util.ArrayList[String]] = getConfig.getData("whitelistedCommands",
def whitelistedCommands: ConfigData[util.ArrayList[String]] = getConfig.getData("whitelistedCommands",
Lists.newArrayList("list", "u", "shrug", "tableflip", "unflip", "mwiki", "yeehaw", "lenny", "rp", "plugins"))
/**
* The channel to use as the public Minecraft chat - everything public gets broadcasted here
*/
val chatChannel: ConfigData[Snowflake] = DPUtils.snowflakeData(getConfig, "chatChannel", 0L)
def chatChannel: ConfigData[Snowflake] = DPUtils.snowflakeData(getConfig, "chatChannel", 0L)
def chatChannelMono: Mono[MessageChannel] = DPUtils.getMessageChannel(chatChannel.getPath, chatChannel.get)
/**
* The channel where the plugin can log when it mutes a player on Discord because of a Minecraft mute
*/
val modlogChannel: ConfigData[Mono[MessageChannel]] = DPUtils.channelData(getConfig, "modlogChannel")
def modlogChannel: ConfigData[Mono[MessageChannel]] = DPUtils.channelData(getConfig, "modlogChannel")
/**
* The plugins to exclude from fake player events used for the 'mcchat' command - some plugins may crash, add them here
*/
val excludedPlugins: ConfigData[Array[String]] = getConfig.getData("excludedPlugins", Array[String]("ProtocolLib", "LibsDisguises", "JourneyMapServer"))
def excludedPlugins: ConfigData[Array[String]] = getConfig.getData("excludedPlugins", Array[String]("ProtocolLib", "LibsDisguises", "JourneyMapServer"))
/**
* If this setting is on then players logged in through the 'mcchat' command will be able to teleport using plugin commands.
* They can then use commands like /tpahere to teleport others to that place.<br />
* If this is off, then teleporting will have no effect.
*/
val allowFakePlayerTeleports: ConfigData[Boolean] = getConfig.getData("allowFakePlayerTeleports", false)
def allowFakePlayerTeleports: ConfigData[Boolean] = getConfig.getData("allowFakePlayerTeleports", false)
/**
* If this is on, each chat channel will have a player list in their description.
* It only gets added if there's no description yet or there are (at least) two lines of "----" following each other.
* Note that it will replace <b>everything</b> above the first and below the last "----" but it will only detect exactly four dashes.
* So if you want to use dashes for something else in the description, make sure it's either less or more dashes in one line.
*/
val showPlayerListOnDC: ConfigData[Boolean] = getConfig.getData("showPlayerListOnDC", true)
def showPlayerListOnDC: ConfigData[Boolean] = getConfig.getData("showPlayerListOnDC", true)
/**
* This setting controls whether custom chat connections can be <i>created</i> (existing connections will always work).
* Custom chat connections can be created using the channelcon command and they allow players to display town chat in a Discord channel for example.
* See the channelcon command for more details.
*/
val allowCustomChat: ConfigData[Boolean] = getConfig.getData("allowCustomChat", true)
def allowCustomChat: ConfigData[Boolean] = getConfig.getData("allowCustomChat", true)
/**
* This setting allows you to control if players can DM the bot to log on the server from Discord.
* This allows them to both chat and perform any command they can in-game.
*/
val allowPrivateChat: ConfigData[Boolean] = getConfig.getData("allowPrivateChat", true)
def allowPrivateChat: ConfigData[Boolean] = getConfig.getData("allowPrivateChat", true)
/**
* If set, message authors appearing on Discord will link to this URL. A 'type' and 'id' parameter will be added with the user's platform (Discord, Minecraft, ...) and ID.
*/
val profileURL: ConfigData[String] = getConfig.getData("profileURL", "")
def profileURL: ConfigData[String] = getConfig.getData("profileURL", "")
/**
* Enables support for running vanilla commands through Discord, if you ever need it.
*/
val enableVanillaCommands: ConfigData[Boolean] = getConfig.getData("enableVanillaCommands", true)
def enableVanillaCommands: ConfigData[Boolean] = getConfig.getData("enableVanillaCommands", true)
/**
* Whether players logged on from Discord (mcchat command) should be recognised by other plugins. Some plugins might break if it's turned off.
* But it's really hacky.

View file

@ -95,12 +95,12 @@ import scala.jdk.CollectionConverters.SeqHasAsJava
/**
* The channel where the bot logs when it detects a role change that results in a new game role or one being removed.
*/
final private val logChannel = DPUtils.channelData(getConfig, "logChannel")
final private def logChannel = DPUtils.channelData(getConfig, "logChannel")
/**
* The role color that is used by game roles.
* Defaults to the second to last in the upper row - #95a5a6.
*/
final private val roleColor = getConfig.getData("roleColor", Color.of(149, 165, 166),
final private def roleColor = getConfig.getData("roleColor", Color.of(149, 165, 166),
rgb => Color.of(Integer.parseInt(rgb.asInstanceOf[String].substring(1), 16)),
color => String.format("#%08x", color.getRGB), true)