From 9abce70359604dacbd977ee65bd3fe1d06ba5d41 Mon Sep 17 00:00:00 2001 From: CalvinDesktop <1283045105@qq.com> Date: Sat, 15 May 2021 13:42:32 +0800 Subject: [PATCH 1/2] Add feature #755, can use properties to configure ability toggle --- .../abilitybots/api/toggle/ConfigLoader.java | 467 ++++++++++++++++++ .../abilitybots/api/toggle/CustomToggle.java | 78 ++- .../api/toggle/CustomToggleTest.java | 37 ++ .../src/test/resources/toggle.properties | 2 + 4 files changed, 582 insertions(+), 2 deletions(-) create mode 100644 telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/ConfigLoader.java create mode 100644 telegrambots-abilities/src/test/resources/toggle.properties diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/ConfigLoader.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/ConfigLoader.java new file mode 100644 index 00000000..e588cb8d --- /dev/null +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/ConfigLoader.java @@ -0,0 +1,467 @@ +//package org.telegram.abilitybots.api.toggle; +// +//import org.simplejavamail.api.mailer.config.LoadBalancingStrategy; +//import org.simplejavamail.api.mailer.config.TransportStrategy; +//import org.simplejavamail.internal.util.SimpleConversions; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +// +//import org.jetbrains.annotations.NotNull; +//import org.jetbrains.annotations.Nullable; +// +//import java.io.File; +//import java.io.FileInputStream; +//import java.io.FileNotFoundException; +//import java.io.IOException; +//import java.io.InputStream; +//import java.util.Collection; +//import java.util.HashMap; +//import java.util.HashSet; +//import java.util.Map; +//import java.util.Properties; +//import java.util.Set; +//import java.util.regex.Matcher; +//import java.util.regex.Pattern; +// +//import static java.util.Collections.unmodifiableMap; +//import static java.util.regex.Pattern.compile; +//import static org.simplejavamail.internal.util.MiscUtil.checkArgumentNotEmpty; +//import static org.simplejavamail.internal.util.MiscUtil.valueNullOrEmpty; +//import static org.simplejavamail.internal.util.Preconditions.assumeTrue; +// +///** +// * Contains list of possible properties names and can produce a map of property values, if provided as file {@value #DEFAULT_CONFIG_FILENAME} on the +// * classpath or as environment property. +// *

+// * The following properties are allowed: +// *

+// */ +//public final class ConfigLoader { +// +// private static final Logger LOGGER = LoggerFactory.getLogger(ConfigLoader.class); +// +// /** +// * By default the optional file {@value} will be loaded from classpath to load initial defaults. +// */ +// public static final String DEFAULT_CONFIG_FILENAME = "simplejavamail.properties"; +// +// /** +// * This pattern recognizes extra property lines that should be loaded directly into JavaMail on the Session object. +// */ +// private static final Pattern EXTRA_PROPERTY_PATTERN = compile("^simplejavamail\\.extraproperties\\.(?.*)"); +// +// /** +// * Initially try to load properties from "{@value #DEFAULT_CONFIG_FILENAME}". +// * +// * @see #loadProperties(String, boolean) +// * @see #loadProperties(InputStream, boolean) +// */ +// private static final Map RESOLVED_PROPERTIES = new HashMap<>(); +// +// static { +// // static initializer block, because loadProperties needs to modify RESOLVED_PROPERTIES while loading +// // this is not possible when we are initializing the same field. +// // RESOLVED_PROPERTIES = loadProperties(DEFAULT_CONFIG_FILENAME); <-- not possible +// loadProperties(DEFAULT_CONFIG_FILENAME, false); +// } +// +// /** +// * List of all the properties recognized by Simple Java Mail. Can be used to programmatically get, set or remove default values. +// * +// * @see simplejavamail.org +// */ +// public enum Property { +// JAVAXMAIL_DEBUG("simplejavamail.javaxmail.debug"), +// TRANSPORT_STRATEGY("simplejavamail.transportstrategy"), +// SMTP_HOST("simplejavamail.smtp.host"), +// SMTP_PORT("simplejavamail.smtp.port"), +// SMTP_USERNAME("simplejavamail.smtp.username"), +// SMTP_PASSWORD("simplejavamail.smtp.password"), +// CUSTOM_SSLFACTORY_CLASS("simplejavamail.custom.sslfactory.class"), +// PROXY_HOST("simplejavamail.proxy.host"), +// PROXY_PORT("simplejavamail.proxy.port"), +// PROXY_USERNAME("simplejavamail.proxy.username"), +// PROXY_PASSWORD("simplejavamail.proxy.password"), +// PROXY_SOCKS5BRIDGE_PORT("simplejavamail.proxy.socks5bridge.port"), +// DEFAULT_SUBJECT("simplejavamail.defaults.subject"), +// DEFAULT_FROM_NAME("simplejavamail.defaults.from.name"), +// DEFAULT_FROM_ADDRESS("simplejavamail.defaults.from.address"), +// DEFAULT_REPLYTO_NAME("simplejavamail.defaults.replyto.name"), +// DEFAULT_REPLYTO_ADDRESS("simplejavamail.defaults.replyto.address"), +// DEFAULT_BOUNCETO_NAME("simplejavamail.defaults.bounceto.name"), +// DEFAULT_BOUNCETO_ADDRESS("simplejavamail.defaults.bounceto.address"), +// DEFAULT_TO_NAME("simplejavamail.defaults.to.name"), +// DEFAULT_TO_ADDRESS("simplejavamail.defaults.to.address"), +// DEFAULT_CC_NAME("simplejavamail.defaults.cc.name"), +// DEFAULT_CC_ADDRESS("simplejavamail.defaults.cc.address"), +// DEFAULT_BCC_NAME("simplejavamail.defaults.bcc.name"), +// DEFAULT_BCC_ADDRESS("simplejavamail.defaults.bcc.address"), +// DEFAULT_POOL_SIZE("simplejavamail.defaults.poolsize"), +// DEFAULT_CONNECTIONPOOL_CLUSTER_KEY("simplejavamail.defaults.connectionpool.clusterkey.uuid"), +// DEFAULT_CONNECTIONPOOL_CORE_SIZE("simplejavamail.defaults.connectionpool.coresize"), +// DEFAULT_CONNECTIONPOOL_MAX_SIZE("simplejavamail.defaults.connectionpool.maxsize"), +// DEFAULT_CONNECTIONPOOL_CLAIMTIMEOUT_MILLIS("simplejavamail.defaults.connectionpool.claimtimeout.millis"), +// DEFAULT_CONNECTIONPOOL_EXPIREAFTER_MILLIS("simplejavamail.defaults.connectionpool.expireafter.millis"), +// DEFAULT_CONNECTIONPOOL_LOADBALANCING_STRATEGY("simplejavamail.defaults.connectionpool.loadbalancing.strategy"), +// DEFAULT_POOL_KEEP_ALIVE_TIME("simplejavamail.defaults.poolsize.keepalivetime"), +// DEFAULT_SESSION_TIMEOUT_MILLIS("simplejavamail.defaults.sessiontimeoutmillis"), +// DEFAULT_TRUST_ALL_HOSTS("simplejavamail.defaults.trustallhosts"), +// DEFAULT_TRUSTED_HOSTS("simplejavamail.defaults.trustedhosts"), +// DEFAULT_VERIFY_SERVER_IDENTITY("simplejavamail.defaults.verifyserveridentity"), +// TRANSPORT_MODE_LOGGING_ONLY("simplejavamail.transport.mode.logging.only"), +// OPPORTUNISTIC_TLS("simplejavamail.opportunistic.tls"), +// SMIME_SIGNING_KEYSTORE("simplejavamail.smime.signing.keystore"), +// SMIME_SIGNING_KEYSTORE_PASSWORD("simplejavamail.smime.signing.keystore_password"), +// SMIME_SIGNING_KEY_ALIAS("simplejavamail.smime.signing.key_alias"), +// SMIME_SIGNING_KEY_PASSWORD("simplejavamail.smime.signing.key_password"), +// SMIME_ENCRYPTION_CERTIFICATE("simplejavamail.smime.encryption.certificate"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_DIR("simplejavamail.embeddedimages.dynamicresolution.enable.dir"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_CLASSPATH("simplejavamail.embeddedimages.dynamicresolution.enable.classpath"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_URL("simplejavamail.embeddedimages.dynamicresolution.enable.url"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_DIR("simplejavamail.embeddedimages.dynamicresolution.base.dir"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_CLASSPATH("simplejavamail.embeddedimages.dynamicresolution.base.classpath"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_URL("simplejavamail.embeddedimages.dynamicresolution.base.url"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_OUTSIDE_BASE_DIR("simplejavamail.embeddedimages.dynamicresolution.outside.base.dir"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_OUTSIDE_BASE_URL("simplejavamail.embeddedimages.dynamicresolution.outside.base.classpath"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_OUTSIDE_BASE_CLASSPATH("simplejavamail.embeddedimages.dynamicresolution.outside.base.url"), +// EMBEDDEDIMAGES_DYNAMICRESOLUTION_MUSTBESUCCESFUL("simplejavamail.embeddedimages.dynamicresolution.mustbesuccesful"), +// EXTRA_PROPERTIES("simplejavamail.extraproperties.*"); +// +// private final String key; +// +// Property(final String key) { +// this.key = key; +// } +// +// public String key() { +// return key; +// } +// } +// +// private ConfigLoader() { +// } +// +// +// // +// // cannot initiate an instance of ConfigLoader, only as util class +// // +// +// +// /** +// * @return The value if not null or else the value from config file if provided or else null. +// */ +// @Nullable +// public static T valueOrProperty(final @Nullable T value, final Property property) { +// return valueOrProperty(value, property, null); +// } +// +// /** +// * See {@link #valueOrProperty(Object, Property, Object)}. +// */ +// @Nullable +// public static String valueOrPropertyAsString(@Nullable final String value, @NotNull final Property property, @Nullable final String defaultValue) { +// return SimpleConversions.convertToString(valueOrProperty(value, property, defaultValue)); +// } +// +// /** +// * See {@link #valueOrProperty(Object, Property, Object)}. +// */ +// @Nullable +// public static Boolean valueOrPropertyAsBoolean(@Nullable final Boolean value, @NotNull final Property property, @Nullable final Boolean defaultValue) { +// return SimpleConversions.convertToBoolean(valueOrProperty(value, property, defaultValue)); +// } +// +// /** +// * See {@link #valueOrProperty(Object, Property, Object)}. +// */ +// @Nullable +// public static Integer valueOrPropertyAsInteger(@Nullable final Integer value, @NotNull final Property property, @Nullable final Integer defaultValue) { +// return SimpleConversions.convertToInteger(valueOrProperty(value, property, defaultValue)); +// } +// +// /** +// * Returns the given value if not null and not empty, otherwise tries to resolve the given property and if still not found resort to the default value if +// * provided. +// *

+// * Null or blank values are never allowed, so they are always ignored. +// * +// * @return The value if not null or else the value from config file if provided or else defaultValue. +// */ +// @Nullable +// public static T valueOrProperty(@Nullable final T value, @NotNull final Property property, @Nullable final T defaultValue) { +// if (!valueNullOrEmpty(value)) { +// LOGGER.trace("using provided argument value {} for property {}", value, property); +// return value; +// } else if (hasProperty(property)) { +// final T propertyValue = getProperty(property); +// LOGGER.trace("using value {} from config file for property {}", propertyValue, property); +// return propertyValue; +// } else { +// LOGGER.trace("no value provided as argument or in config file for property {}, using default value {}", property, defaultValue); +// return defaultValue; +// } +// } +// +// public static synchronized boolean hasProperty(final Property property) { +// return !valueNullOrEmpty(RESOLVED_PROPERTIES.get(property)); +// } +// +// @SuppressWarnings("unchecked") +// @Nullable +// public static synchronized T getProperty(final Property property) { +// return (T) RESOLVED_PROPERTIES.get(property); +// } +// +// @Nullable +// public static synchronized String getStringProperty(final Property property) { +// return SimpleConversions.convertToString(RESOLVED_PROPERTIES.get(property)); +// } +// +// @Nullable +// public static synchronized Integer getIntegerProperty(final Property property) { +// return SimpleConversions.convertToInteger(RESOLVED_PROPERTIES.get(property)); +// } +// +// @Nullable +// public static synchronized Boolean getBooleanProperty(final Property property) { +// return SimpleConversions.convertToBoolean(RESOLVED_PROPERTIES.get(property)); +// } +// +// /** +// * Loads properties from property file on the classpath, if provided. Calling this method only has effect on new Email and Mailer instances after +// * this. +// * +// * @param filename Any file that is on the classpath that holds a list of key=value pairs. +// * @param addProperties Flag to indicate if the new properties should be added or replacing the old properties. +// * @return The updated properties map that is used internally. +// */ +// public static Map loadProperties(final String filename, final boolean addProperties) { +// final InputStream input = ConfigLoader.class.getClassLoader().getResourceAsStream(filename); +// if (input != null) { +// return loadProperties(input, addProperties); +// } +// LOGGER.debug("Property file not found on classpath, skipping config file"); +// return new HashMap<>(); +// } +// +// /** +// * Loads properties from another properties source, in case you want to provide your own list. +// * +// * @param properties Your own list of properties +// * @param addProperties Flag to indicate if the new properties should be added or replacing the old properties. +// * @return The updated properties map that is used internally. +// */ +// public static Map loadProperties(final Properties properties, final boolean addProperties) { +// if (!addProperties) { +// RESOLVED_PROPERTIES.clear(); +// } +// RESOLVED_PROPERTIES.putAll(readProperties(properties)); +// return unmodifiableMap(RESOLVED_PROPERTIES); +// } +// +// /** +// * Loads properties from property {@link File}, if provided. Calling this method only has effect on new Email and Mailer instances after this. +// * +// * @param filename Any file reference that holds a properties list. +// * @param addProperties Flag to indicate if the new properties should be added or replacing the old properties. +// * @return The updated properties map that is used internally. +// */ +// public static Map loadProperties(final File filename, final boolean addProperties) { +// try { +// return loadProperties(new FileInputStream(filename), addProperties); +// } catch (final FileNotFoundException e) { +// throw new IllegalStateException("error reading properties file from File", e); +// } +// } +// +// /** +// * Loads properties from {@link InputStream}. Calling this method only has effect on new Email and Mailer instances after this. +// * +// * @param inputStream Source of property key=value pairs separated by newline \n characters. +// * @param addProperties Flag to indicate if the new properties should be added or replacing the old properties. +// * @return The updated properties map that is used internally. +// */ +// public static synchronized Map loadProperties(final @Nullable InputStream inputStream, final boolean addProperties) { +// final Properties prop = new Properties(); +// +// try { +// prop.load(checkArgumentNotEmpty(inputStream, "InputStream was null")); +// } catch (final IOException e) { +// throw new IllegalStateException("error reading properties file from inputstream", e); +// } finally { +// if (inputStream != null) { +// try { +// inputStream.close(); +// } catch (final IOException e) { +// LOGGER.error(e.getMessage(), e); +// } +// } +// } +// +// if (!addProperties) { +// RESOLVED_PROPERTIES.clear(); +// } +// RESOLVED_PROPERTIES.putAll(readProperties(prop)); +// return unmodifiableMap(RESOLVED_PROPERTIES); +// } +// +// /** +// * @return All properties in priority of System property {@code >} File properties. +// */ +// private static Map readProperties(final @NotNull Properties fileProperties) { +// final Properties filePropertiesLeft = new Properties(); +// filePropertiesLeft.putAll(fileProperties); +// final Map resolvedProps = new HashMap<>(); +// for (final Property prop : Property.values()) { +// if (System.getProperty(prop.key) != null) { +// LOGGER.debug(prop.key + ": " + System.getProperty(prop.key)); +// } +// final Object asSystemProperty = parsePropertyValue(System.getProperty(prop.key)); +// if (asSystemProperty != null) { +// resolvedProps.put(prop, asSystemProperty); +// filePropertiesLeft.remove(prop.key); +// } else { +// final Object asEnvProperty = parsePropertyValue(System.getenv().get(prop.key)); +// if (asEnvProperty != null) { +// resolvedProps.put(prop, asEnvProperty); +// filePropertiesLeft.remove(prop.key); +// } else { +// final Object rawValue = filePropertiesLeft.remove(prop.key); +// if (rawValue != null) { +// if (rawValue instanceof String) { +// resolvedProps.put(prop, parsePropertyValue((String) rawValue)); +// } else { +// resolvedProps.put(prop, rawValue); +// } +// } +// } +// } +// } +// +// final Map extraProperties = new HashMap<>(); +// extraProperties.putAll(filterExtraJavaMailProperties(null, System.getProperties().entrySet())); +// //noinspection unchecked,rawtypes +// extraProperties.putAll(filterExtraJavaMailProperties(null, (Set) System.getenv().entrySet())); +// extraProperties.putAll(filterExtraJavaMailProperties(filePropertiesLeft, fileProperties.entrySet())); +// resolvedProps.put(Property.EXTRA_PROPERTIES, extraProperties); +// +// if (!filePropertiesLeft.isEmpty()) { +// throw new IllegalArgumentException("unknown properties provided " + filePropertiesLeft); +// } +// +// return resolvedProps; +// } +// +// private static Map filterExtraJavaMailProperties(@Nullable final Properties filePropertiesLeft, final Set> entries) { +// final Map extraProperties = new HashMap<>(); +// for (Map.Entry propertyKey : entries) { +// if (propertyKey.getKey() instanceof String) { +// final Matcher matcher = EXTRA_PROPERTY_PATTERN.matcher((String) propertyKey.getKey()); +// if (matcher.matches()) { +// assumeTrue(propertyKey.getValue() instanceof String, "Simple Java Mail property value can only be of type String"); +// extraProperties.put(matcher.group("actualProperty"), (String) propertyKey.getValue()); +// if (filePropertiesLeft != null) { +// filePropertiesLeft.remove(propertyKey.getKey()); +// } +// } +// } +// } +// return extraProperties; +// } +// +// /** +// * @return The property value in boolean, integer or as original string value. +// */ +// @Nullable +// static Object parsePropertyValue(final @Nullable String propertyValue) { +// if (propertyValue == null) { +// return null; +// } +// // read boolean value +// final Map booleanConversionMap = new HashMap<>(); +// booleanConversionMap.put("0", false); +// booleanConversionMap.put("1", true); +// booleanConversionMap.put("false", false); +// booleanConversionMap.put("true", true); +// booleanConversionMap.put("no", false); +// booleanConversionMap.put("yes", true); +// if (booleanConversionMap.containsKey(propertyValue)) { +// return booleanConversionMap.get(propertyValue.toLowerCase()); +// } +// // read number value +// try { +// return Integer.valueOf(propertyValue); +// } catch (final NumberFormatException nfe) { +// // ok, so not a number +// } +// // read TransportStrategy value +// try { +// return TransportStrategy.valueOf(propertyValue); +// } catch (final IllegalArgumentException nfe) { +// // ok, so not a TransportStrategy either +// } +// // read LoadBalancingStrategy value +// try { +// return LoadBalancingStrategy.valueOf(propertyValue); +// } catch (final IllegalArgumentException nfe) { +// // ok, so not a TransportStrategy either +// } +// // return value as is (which should be string) +// return propertyValue; +// } +//} diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/CustomToggle.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/CustomToggle.java index 22e02fa8..8f0ce237 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/CustomToggle.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/CustomToggle.java @@ -3,11 +3,13 @@ package org.telegram.abilitybots.api.toggle; import org.telegram.abilitybots.api.objects.Ability; import java.util.HashMap; +import java.util.Locale; import java.util.Map; +import java.util.Properties; /** - * This custom toggle can be used to customize default abilities supplied by the library. Users can call {@link CustomToggle#toggle} to - * rename the default abilites or {@link CustomToggle#turnOff} to simply turn off the said ability. + * This custom toggle can be used to customize default abilities supplied by the library. Users can call {@link CustomToggle#config} to + * rename the default abilities or {@link CustomToggle#turnOff} to simply turn off the said ability. */ public class CustomToggle implements AbilityToggle { public static final String OFF = "turn_off_base_ability"; @@ -53,4 +55,76 @@ public class CustomToggle implements AbilityToggle { baseMapping.put(ability, OFF); return this; } + + /** + * @param properties the abilities toggle definition + * @return the toggle instance + */ + public CustomToggle config(Properties properties) { + for (String key : properties.stringPropertyNames()) { + String value = properties.getProperty(key); + key = key.toLowerCase(); + + // compare with legal configuration names + for (Property p: Property.values()) { + if (key.equals(p.key())) { + String ability = key.split("\\.")[1]; + if (key.contains("enabled") && value.equalsIgnoreCase("false")) { + this.turnOff(ability); + }else if (key.contains("toggle")) { + this.toggle(ability, value); + } + } + } + } + return this; + } + + /** + * List of all the properties recognized by {@link CustomToggle}. + * Can be used to programmatically get, set or remove default values. + */ + public enum Property{ + CLAIM_ENABLED("ability.claim.enabled"), + CLAIM_TOGGLE("ability.claim.toggle"), + + BAN_ENABLED("ability.ban.enabled"), + BAN_TOGGLE("ability.ban.toggle"), + + PROMOTE_ENABLED("ability.promote.enabled"), + PROMOTE_TOGGLE("ability.promote.toggle"), + + DEMOTE_ENABLED("ability.demote.enabled"), + DEMOTE_TOGGLE("ability.demote.toggle"), + + UNBAN_ENABLED("ability.unban.enabled"), + UNBAN_TOGGLE("ability.unban.toggle"), + + BACKUP_ENABLED("ability.backup.enabled"), + BACKUP_TOGGLE("ability.backup.toggle"), + + RECOVER_ENABLED("ability.recover.enabled"), + RECOVER_TOGGLE("ability.recover.toggle"), + + COMMANDS_ENABLED("ability.commands.enabled"), + COMMANDS_TOGGLE("ability.commands.toggle"), + + REPORT_ENABLED("ability.report.enabled"), + REPORT_TOGGLE("ability.report.toggle"), + + STATS_ENABLED("ability.stats.enabled"), + STATS_TOGGLE("ability.stats.toggle") + ; + + private final String key; + + Property (final String key){ + this.key = key; + } + + public String key() { + return key; + } + } + } diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/toggle/CustomToggleTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/toggle/CustomToggleTest.java index 098533ea..e2b131f3 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/toggle/CustomToggleTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/toggle/CustomToggleTest.java @@ -7,7 +7,9 @@ import org.telegram.abilitybots.api.bot.DefaultAbilities; import org.telegram.abilitybots.api.bot.DefaultBot; import org.telegram.abilitybots.api.db.DBContext; +import java.io.FileInputStream; import java.io.IOException; +import java.util.Properties; import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.junit.jupiter.api.Assertions.*; @@ -17,10 +19,12 @@ class CustomToggleTest { private DBContext db; private AbilityToggle toggle; private DefaultBot customBot; + private String filename; @BeforeEach void setUp() { db = offlineInstance("db"); + filename = "src/test/resources/toggle.properties"; } @AfterEach @@ -47,4 +51,37 @@ class CustomToggleTest { assertTrue(customBot.abilities().containsKey(targetName)); } + @Test + public void canTurnOffAbilitiesThroughProperties() { + Properties properties = new Properties(); + try { + properties.load(new FileInputStream(filename)); + toggle = new CustomToggle().config(properties); + } catch (IOException e) { + System.out.println("No such file"); + } + + customBot = new DefaultBot(EMPTY, EMPTY, db, toggle); + customBot.onRegister(); + + assertFalse(customBot.abilities().containsKey(DefaultAbilities.CLAIM)); + } + + @Test + public void canProcessAbilitiesThroughProperties() { + Properties properties = new Properties(); + try { + properties.load(new FileInputStream(filename)); + toggle = new CustomToggle().config(properties); + } catch (IOException e) { + System.out.println("No such file"); + } + + customBot = new DefaultBot(EMPTY, EMPTY, db, toggle); + customBot.onRegister(); + + String targetName = "restrict"; + assertTrue(customBot.abilities().containsKey(targetName)); + } + } \ No newline at end of file diff --git a/telegrambots-abilities/src/test/resources/toggle.properties b/telegrambots-abilities/src/test/resources/toggle.properties new file mode 100644 index 00000000..7e9bcf95 --- /dev/null +++ b/telegrambots-abilities/src/test/resources/toggle.properties @@ -0,0 +1,2 @@ +ability.claim.enabled=false +ability.ban.toggle=restrict \ No newline at end of file From 330d9c29fa0d90d782a0cdce3f08468011b292a3 Mon Sep 17 00:00:00 2001 From: CalvinDesktop <1283045105@qq.com> Date: Sat, 15 May 2021 14:16:12 +0800 Subject: [PATCH 2/2] fix minor issues for previous commit fix issue #755 --- .../abilitybots/api/toggle/ConfigLoader.java | 467 ------------------ .../abilitybots/api/toggle/CustomToggle.java | 3 +- 2 files changed, 1 insertion(+), 469 deletions(-) delete mode 100644 telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/ConfigLoader.java diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/ConfigLoader.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/ConfigLoader.java deleted file mode 100644 index e588cb8d..00000000 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/ConfigLoader.java +++ /dev/null @@ -1,467 +0,0 @@ -//package org.telegram.abilitybots.api.toggle; -// -//import org.simplejavamail.api.mailer.config.LoadBalancingStrategy; -//import org.simplejavamail.api.mailer.config.TransportStrategy; -//import org.simplejavamail.internal.util.SimpleConversions; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -// -//import org.jetbrains.annotations.NotNull; -//import org.jetbrains.annotations.Nullable; -// -//import java.io.File; -//import java.io.FileInputStream; -//import java.io.FileNotFoundException; -//import java.io.IOException; -//import java.io.InputStream; -//import java.util.Collection; -//import java.util.HashMap; -//import java.util.HashSet; -//import java.util.Map; -//import java.util.Properties; -//import java.util.Set; -//import java.util.regex.Matcher; -//import java.util.regex.Pattern; -// -//import static java.util.Collections.unmodifiableMap; -//import static java.util.regex.Pattern.compile; -//import static org.simplejavamail.internal.util.MiscUtil.checkArgumentNotEmpty; -//import static org.simplejavamail.internal.util.MiscUtil.valueNullOrEmpty; -//import static org.simplejavamail.internal.util.Preconditions.assumeTrue; -// -///** -// * Contains list of possible properties names and can produce a map of property values, if provided as file {@value #DEFAULT_CONFIG_FILENAME} on the -// * classpath or as environment property. -// *

-// * The following properties are allowed: -// *

    -// *
  • simplejavamail.javaxmail.debug
  • -// *
  • simplejavamail.transportstrategy
  • -// *
  • simplejavamail.smtp.host
  • -// *
  • simplejavamail.smtp.port
  • -// *
  • simplejavamail.smtp.username
  • -// *
  • simplejavamail.smtp.password
  • -// *
  • simplejavamail.custom.sslfactory.class
  • -// *
  • simplejavamail.proxy.host
  • -// *
  • simplejavamail.proxy.port
  • -// *
  • simplejavamail.proxy.username
  • -// *
  • simplejavamail.proxy.password
  • -// *
  • simplejavamail.proxy.socks5bridge.port
  • -// *
  • simplejavamail.defaults.subject
  • -// *
  • simplejavamail.defaults.from.name
  • -// *
  • simplejavamail.defaults.from.address
  • -// *
  • simplejavamail.defaults.replyto.name
  • -// *
  • simplejavamail.defaults.replyto.address
  • -// *
  • simplejavamail.defaults.bounceto.name
  • -// *
  • simplejavamail.defaults.bounceto.address
  • -// *
  • simplejavamail.defaults.to.name
  • -// *
  • simplejavamail.defaults.to.address
  • -// *
  • simplejavamail.defaults.cc.name
  • -// *
  • simplejavamail.defaults.cc.address
  • -// *
  • simplejavamail.defaults.bcc.name
  • -// *
  • simplejavamail.defaults.bcc.address
  • -// *
  • simplejavamail.defaults.poolsize
  • -// *
  • simplejavamail.defaults.poolsize.keepalivetime
  • -// *
  • simplejavamail.defaults.connectionpool.clusterkey.uuid
  • -// *
  • simplejavamail.defaults.connectionpool.coresize
  • -// *
  • simplejavamail.defaults.connectionpool.maxsize
  • -// *
  • simplejavamail.defaults.connectionpool.claimtimeout.millis
  • -// *
  • simplejavamail.defaults.connectionpool.expireafter.millis
  • -// *
  • simplejavamail.defaults.connectionpool.loadbalancing.strategy
  • -// *
  • simplejavamail.defaults.sessiontimeoutmillis
  • -// *
  • simplejavamail.defaults.trustallhosts
  • -// *
  • simplejavamail.defaults.trustedhosts
  • -// *
  • simplejavamail.defaults.verifyserveridentity
  • -// *
  • simplejavamail.transport.mode.logging.only
  • -// *
  • simplejavamail.opportunistic.tls
  • -// *
  • simplejavamail.smime.signing.keystore
  • -// *
  • simplejavamail.smime.signing.keystore_password
  • -// *
  • simplejavamail.smime.signing.key_alias
  • -// *
  • simplejavamail.smime.signing.key_password
  • -// *
  • simplejavamail.smime.encryption.certificate
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.enable.dir
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.enable.url
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.enable.classpath
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.base.dir
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.base.url
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.base.classpath
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.outside.base.dir
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.outside.base.classpath
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.outside.base.url
  • -// *
  • simplejavamail.embeddedimages.dynamicresolution.mustbesuccesful
  • -// *
-// */ -//public final class ConfigLoader { -// -// private static final Logger LOGGER = LoggerFactory.getLogger(ConfigLoader.class); -// -// /** -// * By default the optional file {@value} will be loaded from classpath to load initial defaults. -// */ -// public static final String DEFAULT_CONFIG_FILENAME = "simplejavamail.properties"; -// -// /** -// * This pattern recognizes extra property lines that should be loaded directly into JavaMail on the Session object. -// */ -// private static final Pattern EXTRA_PROPERTY_PATTERN = compile("^simplejavamail\\.extraproperties\\.(?.*)"); -// -// /** -// * Initially try to load properties from "{@value #DEFAULT_CONFIG_FILENAME}". -// * -// * @see #loadProperties(String, boolean) -// * @see #loadProperties(InputStream, boolean) -// */ -// private static final Map RESOLVED_PROPERTIES = new HashMap<>(); -// -// static { -// // static initializer block, because loadProperties needs to modify RESOLVED_PROPERTIES while loading -// // this is not possible when we are initializing the same field. -// // RESOLVED_PROPERTIES = loadProperties(DEFAULT_CONFIG_FILENAME); <-- not possible -// loadProperties(DEFAULT_CONFIG_FILENAME, false); -// } -// -// /** -// * List of all the properties recognized by Simple Java Mail. Can be used to programmatically get, set or remove default values. -// * -// * @see simplejavamail.org -// */ -// public enum Property { -// JAVAXMAIL_DEBUG("simplejavamail.javaxmail.debug"), -// TRANSPORT_STRATEGY("simplejavamail.transportstrategy"), -// SMTP_HOST("simplejavamail.smtp.host"), -// SMTP_PORT("simplejavamail.smtp.port"), -// SMTP_USERNAME("simplejavamail.smtp.username"), -// SMTP_PASSWORD("simplejavamail.smtp.password"), -// CUSTOM_SSLFACTORY_CLASS("simplejavamail.custom.sslfactory.class"), -// PROXY_HOST("simplejavamail.proxy.host"), -// PROXY_PORT("simplejavamail.proxy.port"), -// PROXY_USERNAME("simplejavamail.proxy.username"), -// PROXY_PASSWORD("simplejavamail.proxy.password"), -// PROXY_SOCKS5BRIDGE_PORT("simplejavamail.proxy.socks5bridge.port"), -// DEFAULT_SUBJECT("simplejavamail.defaults.subject"), -// DEFAULT_FROM_NAME("simplejavamail.defaults.from.name"), -// DEFAULT_FROM_ADDRESS("simplejavamail.defaults.from.address"), -// DEFAULT_REPLYTO_NAME("simplejavamail.defaults.replyto.name"), -// DEFAULT_REPLYTO_ADDRESS("simplejavamail.defaults.replyto.address"), -// DEFAULT_BOUNCETO_NAME("simplejavamail.defaults.bounceto.name"), -// DEFAULT_BOUNCETO_ADDRESS("simplejavamail.defaults.bounceto.address"), -// DEFAULT_TO_NAME("simplejavamail.defaults.to.name"), -// DEFAULT_TO_ADDRESS("simplejavamail.defaults.to.address"), -// DEFAULT_CC_NAME("simplejavamail.defaults.cc.name"), -// DEFAULT_CC_ADDRESS("simplejavamail.defaults.cc.address"), -// DEFAULT_BCC_NAME("simplejavamail.defaults.bcc.name"), -// DEFAULT_BCC_ADDRESS("simplejavamail.defaults.bcc.address"), -// DEFAULT_POOL_SIZE("simplejavamail.defaults.poolsize"), -// DEFAULT_CONNECTIONPOOL_CLUSTER_KEY("simplejavamail.defaults.connectionpool.clusterkey.uuid"), -// DEFAULT_CONNECTIONPOOL_CORE_SIZE("simplejavamail.defaults.connectionpool.coresize"), -// DEFAULT_CONNECTIONPOOL_MAX_SIZE("simplejavamail.defaults.connectionpool.maxsize"), -// DEFAULT_CONNECTIONPOOL_CLAIMTIMEOUT_MILLIS("simplejavamail.defaults.connectionpool.claimtimeout.millis"), -// DEFAULT_CONNECTIONPOOL_EXPIREAFTER_MILLIS("simplejavamail.defaults.connectionpool.expireafter.millis"), -// DEFAULT_CONNECTIONPOOL_LOADBALANCING_STRATEGY("simplejavamail.defaults.connectionpool.loadbalancing.strategy"), -// DEFAULT_POOL_KEEP_ALIVE_TIME("simplejavamail.defaults.poolsize.keepalivetime"), -// DEFAULT_SESSION_TIMEOUT_MILLIS("simplejavamail.defaults.sessiontimeoutmillis"), -// DEFAULT_TRUST_ALL_HOSTS("simplejavamail.defaults.trustallhosts"), -// DEFAULT_TRUSTED_HOSTS("simplejavamail.defaults.trustedhosts"), -// DEFAULT_VERIFY_SERVER_IDENTITY("simplejavamail.defaults.verifyserveridentity"), -// TRANSPORT_MODE_LOGGING_ONLY("simplejavamail.transport.mode.logging.only"), -// OPPORTUNISTIC_TLS("simplejavamail.opportunistic.tls"), -// SMIME_SIGNING_KEYSTORE("simplejavamail.smime.signing.keystore"), -// SMIME_SIGNING_KEYSTORE_PASSWORD("simplejavamail.smime.signing.keystore_password"), -// SMIME_SIGNING_KEY_ALIAS("simplejavamail.smime.signing.key_alias"), -// SMIME_SIGNING_KEY_PASSWORD("simplejavamail.smime.signing.key_password"), -// SMIME_ENCRYPTION_CERTIFICATE("simplejavamail.smime.encryption.certificate"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_DIR("simplejavamail.embeddedimages.dynamicresolution.enable.dir"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_CLASSPATH("simplejavamail.embeddedimages.dynamicresolution.enable.classpath"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_URL("simplejavamail.embeddedimages.dynamicresolution.enable.url"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_DIR("simplejavamail.embeddedimages.dynamicresolution.base.dir"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_CLASSPATH("simplejavamail.embeddedimages.dynamicresolution.base.classpath"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_URL("simplejavamail.embeddedimages.dynamicresolution.base.url"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_OUTSIDE_BASE_DIR("simplejavamail.embeddedimages.dynamicresolution.outside.base.dir"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_OUTSIDE_BASE_URL("simplejavamail.embeddedimages.dynamicresolution.outside.base.classpath"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_OUTSIDE_BASE_CLASSPATH("simplejavamail.embeddedimages.dynamicresolution.outside.base.url"), -// EMBEDDEDIMAGES_DYNAMICRESOLUTION_MUSTBESUCCESFUL("simplejavamail.embeddedimages.dynamicresolution.mustbesuccesful"), -// EXTRA_PROPERTIES("simplejavamail.extraproperties.*"); -// -// private final String key; -// -// Property(final String key) { -// this.key = key; -// } -// -// public String key() { -// return key; -// } -// } -// -// private ConfigLoader() { -// } -// -// -// // -// // cannot initiate an instance of ConfigLoader, only as util class -// // -// -// -// /** -// * @return The value if not null or else the value from config file if provided or else null. -// */ -// @Nullable -// public static T valueOrProperty(final @Nullable T value, final Property property) { -// return valueOrProperty(value, property, null); -// } -// -// /** -// * See {@link #valueOrProperty(Object, Property, Object)}. -// */ -// @Nullable -// public static String valueOrPropertyAsString(@Nullable final String value, @NotNull final Property property, @Nullable final String defaultValue) { -// return SimpleConversions.convertToString(valueOrProperty(value, property, defaultValue)); -// } -// -// /** -// * See {@link #valueOrProperty(Object, Property, Object)}. -// */ -// @Nullable -// public static Boolean valueOrPropertyAsBoolean(@Nullable final Boolean value, @NotNull final Property property, @Nullable final Boolean defaultValue) { -// return SimpleConversions.convertToBoolean(valueOrProperty(value, property, defaultValue)); -// } -// -// /** -// * See {@link #valueOrProperty(Object, Property, Object)}. -// */ -// @Nullable -// public static Integer valueOrPropertyAsInteger(@Nullable final Integer value, @NotNull final Property property, @Nullable final Integer defaultValue) { -// return SimpleConversions.convertToInteger(valueOrProperty(value, property, defaultValue)); -// } -// -// /** -// * Returns the given value if not null and not empty, otherwise tries to resolve the given property and if still not found resort to the default value if -// * provided. -// *

-// * Null or blank values are never allowed, so they are always ignored. -// * -// * @return The value if not null or else the value from config file if provided or else defaultValue. -// */ -// @Nullable -// public static T valueOrProperty(@Nullable final T value, @NotNull final Property property, @Nullable final T defaultValue) { -// if (!valueNullOrEmpty(value)) { -// LOGGER.trace("using provided argument value {} for property {}", value, property); -// return value; -// } else if (hasProperty(property)) { -// final T propertyValue = getProperty(property); -// LOGGER.trace("using value {} from config file for property {}", propertyValue, property); -// return propertyValue; -// } else { -// LOGGER.trace("no value provided as argument or in config file for property {}, using default value {}", property, defaultValue); -// return defaultValue; -// } -// } -// -// public static synchronized boolean hasProperty(final Property property) { -// return !valueNullOrEmpty(RESOLVED_PROPERTIES.get(property)); -// } -// -// @SuppressWarnings("unchecked") -// @Nullable -// public static synchronized T getProperty(final Property property) { -// return (T) RESOLVED_PROPERTIES.get(property); -// } -// -// @Nullable -// public static synchronized String getStringProperty(final Property property) { -// return SimpleConversions.convertToString(RESOLVED_PROPERTIES.get(property)); -// } -// -// @Nullable -// public static synchronized Integer getIntegerProperty(final Property property) { -// return SimpleConversions.convertToInteger(RESOLVED_PROPERTIES.get(property)); -// } -// -// @Nullable -// public static synchronized Boolean getBooleanProperty(final Property property) { -// return SimpleConversions.convertToBoolean(RESOLVED_PROPERTIES.get(property)); -// } -// -// /** -// * Loads properties from property file on the classpath, if provided. Calling this method only has effect on new Email and Mailer instances after -// * this. -// * -// * @param filename Any file that is on the classpath that holds a list of key=value pairs. -// * @param addProperties Flag to indicate if the new properties should be added or replacing the old properties. -// * @return The updated properties map that is used internally. -// */ -// public static Map loadProperties(final String filename, final boolean addProperties) { -// final InputStream input = ConfigLoader.class.getClassLoader().getResourceAsStream(filename); -// if (input != null) { -// return loadProperties(input, addProperties); -// } -// LOGGER.debug("Property file not found on classpath, skipping config file"); -// return new HashMap<>(); -// } -// -// /** -// * Loads properties from another properties source, in case you want to provide your own list. -// * -// * @param properties Your own list of properties -// * @param addProperties Flag to indicate if the new properties should be added or replacing the old properties. -// * @return The updated properties map that is used internally. -// */ -// public static Map loadProperties(final Properties properties, final boolean addProperties) { -// if (!addProperties) { -// RESOLVED_PROPERTIES.clear(); -// } -// RESOLVED_PROPERTIES.putAll(readProperties(properties)); -// return unmodifiableMap(RESOLVED_PROPERTIES); -// } -// -// /** -// * Loads properties from property {@link File}, if provided. Calling this method only has effect on new Email and Mailer instances after this. -// * -// * @param filename Any file reference that holds a properties list. -// * @param addProperties Flag to indicate if the new properties should be added or replacing the old properties. -// * @return The updated properties map that is used internally. -// */ -// public static Map loadProperties(final File filename, final boolean addProperties) { -// try { -// return loadProperties(new FileInputStream(filename), addProperties); -// } catch (final FileNotFoundException e) { -// throw new IllegalStateException("error reading properties file from File", e); -// } -// } -// -// /** -// * Loads properties from {@link InputStream}. Calling this method only has effect on new Email and Mailer instances after this. -// * -// * @param inputStream Source of property key=value pairs separated by newline \n characters. -// * @param addProperties Flag to indicate if the new properties should be added or replacing the old properties. -// * @return The updated properties map that is used internally. -// */ -// public static synchronized Map loadProperties(final @Nullable InputStream inputStream, final boolean addProperties) { -// final Properties prop = new Properties(); -// -// try { -// prop.load(checkArgumentNotEmpty(inputStream, "InputStream was null")); -// } catch (final IOException e) { -// throw new IllegalStateException("error reading properties file from inputstream", e); -// } finally { -// if (inputStream != null) { -// try { -// inputStream.close(); -// } catch (final IOException e) { -// LOGGER.error(e.getMessage(), e); -// } -// } -// } -// -// if (!addProperties) { -// RESOLVED_PROPERTIES.clear(); -// } -// RESOLVED_PROPERTIES.putAll(readProperties(prop)); -// return unmodifiableMap(RESOLVED_PROPERTIES); -// } -// -// /** -// * @return All properties in priority of System property {@code >} File properties. -// */ -// private static Map readProperties(final @NotNull Properties fileProperties) { -// final Properties filePropertiesLeft = new Properties(); -// filePropertiesLeft.putAll(fileProperties); -// final Map resolvedProps = new HashMap<>(); -// for (final Property prop : Property.values()) { -// if (System.getProperty(prop.key) != null) { -// LOGGER.debug(prop.key + ": " + System.getProperty(prop.key)); -// } -// final Object asSystemProperty = parsePropertyValue(System.getProperty(prop.key)); -// if (asSystemProperty != null) { -// resolvedProps.put(prop, asSystemProperty); -// filePropertiesLeft.remove(prop.key); -// } else { -// final Object asEnvProperty = parsePropertyValue(System.getenv().get(prop.key)); -// if (asEnvProperty != null) { -// resolvedProps.put(prop, asEnvProperty); -// filePropertiesLeft.remove(prop.key); -// } else { -// final Object rawValue = filePropertiesLeft.remove(prop.key); -// if (rawValue != null) { -// if (rawValue instanceof String) { -// resolvedProps.put(prop, parsePropertyValue((String) rawValue)); -// } else { -// resolvedProps.put(prop, rawValue); -// } -// } -// } -// } -// } -// -// final Map extraProperties = new HashMap<>(); -// extraProperties.putAll(filterExtraJavaMailProperties(null, System.getProperties().entrySet())); -// //noinspection unchecked,rawtypes -// extraProperties.putAll(filterExtraJavaMailProperties(null, (Set) System.getenv().entrySet())); -// extraProperties.putAll(filterExtraJavaMailProperties(filePropertiesLeft, fileProperties.entrySet())); -// resolvedProps.put(Property.EXTRA_PROPERTIES, extraProperties); -// -// if (!filePropertiesLeft.isEmpty()) { -// throw new IllegalArgumentException("unknown properties provided " + filePropertiesLeft); -// } -// -// return resolvedProps; -// } -// -// private static Map filterExtraJavaMailProperties(@Nullable final Properties filePropertiesLeft, final Set> entries) { -// final Map extraProperties = new HashMap<>(); -// for (Map.Entry propertyKey : entries) { -// if (propertyKey.getKey() instanceof String) { -// final Matcher matcher = EXTRA_PROPERTY_PATTERN.matcher((String) propertyKey.getKey()); -// if (matcher.matches()) { -// assumeTrue(propertyKey.getValue() instanceof String, "Simple Java Mail property value can only be of type String"); -// extraProperties.put(matcher.group("actualProperty"), (String) propertyKey.getValue()); -// if (filePropertiesLeft != null) { -// filePropertiesLeft.remove(propertyKey.getKey()); -// } -// } -// } -// } -// return extraProperties; -// } -// -// /** -// * @return The property value in boolean, integer or as original string value. -// */ -// @Nullable -// static Object parsePropertyValue(final @Nullable String propertyValue) { -// if (propertyValue == null) { -// return null; -// } -// // read boolean value -// final Map booleanConversionMap = new HashMap<>(); -// booleanConversionMap.put("0", false); -// booleanConversionMap.put("1", true); -// booleanConversionMap.put("false", false); -// booleanConversionMap.put("true", true); -// booleanConversionMap.put("no", false); -// booleanConversionMap.put("yes", true); -// if (booleanConversionMap.containsKey(propertyValue)) { -// return booleanConversionMap.get(propertyValue.toLowerCase()); -// } -// // read number value -// try { -// return Integer.valueOf(propertyValue); -// } catch (final NumberFormatException nfe) { -// // ok, so not a number -// } -// // read TransportStrategy value -// try { -// return TransportStrategy.valueOf(propertyValue); -// } catch (final IllegalArgumentException nfe) { -// // ok, so not a TransportStrategy either -// } -// // read LoadBalancingStrategy value -// try { -// return LoadBalancingStrategy.valueOf(propertyValue); -// } catch (final IllegalArgumentException nfe) { -// // ok, so not a TransportStrategy either -// } -// // return value as is (which should be string) -// return propertyValue; -// } -//} diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/CustomToggle.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/CustomToggle.java index 8f0ce237..20392650 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/CustomToggle.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/toggle/CustomToggle.java @@ -3,12 +3,11 @@ package org.telegram.abilitybots.api.toggle; import org.telegram.abilitybots.api.objects.Ability; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import java.util.Properties; /** - * This custom toggle can be used to customize default abilities supplied by the library. Users can call {@link CustomToggle#config} to + * This custom toggle can be used to customize default abilities supplied by the library. Users can call {@link CustomToggle#toggle} to * rename the default abilities or {@link CustomToggle#turnOff} to simply turn off the said ability. */ public class CustomToggle implements AbilityToggle {