Record Class GuildPrefix

java.lang.Object
java.lang.Record
dev.sympho.modular_commands.execute.GuildPrefix
Record Components:
prefixes - The prefixes per guild, keyed by the guild ID.
defaultPrefix - The default prefix.
All Implemented Interfaces:
PrefixProvider

public record GuildPrefix(Map<Snowflake,String> prefixes, String defaultPrefix) extends Record implements PrefixProvider
Prefix provider that allows prefix overrides per guild while falling back to a default construction-time prefix if no override.

Private channels are treated as guilds with no override, so the default prefix is used in their case.

Since:
1.0
Version:
1.0
  • Constructor Details

    • GuildPrefix

      public GuildPrefix(Map<Snowflake,String> prefixes, String defaultPrefix)
      Creates a new instance with the given set of initial overrides.
      Parameters:
      prefixes - The initial prefixes per guild, keyed by the guild ID.
      defaultPrefix - The default prefix.
    • GuildPrefix

      public GuildPrefix(String defaultPrefix)
      Creates a new instance with no overrides.
      Parameters:
      defaultPrefix - The default prefix.
  • Method Details

    • setPrefix

      public void setPrefix(Snowflake guildId, String prefix)
      Sets a prefix override for a guild.
      Parameters:
      guildId - The guild to set the override for.
      prefix - The prefix to use for that guild.
    • clearPrefix

      public boolean clearPrefix(Snowflake guildId)
      Clears the override for a guild, if there is one.
      Parameters:
      guildId - The guild to reset the prefix override for.
      Returns:
      true if the prefix was reset for the given guild. false if the given guild did not have a prefix override.
    • getPrefix

      public String getPrefix(@Nullable Snowflake guildId)
      Description copied from interface: PrefixProvider
      Determines the prefix that should be used for the given guild.
      Specified by:
      getPrefix in interface PrefixProvider
      Parameters:
      guildId - The ID of the guild that the event was issued from, or null if it was issued from a private channel.
      Returns:
      The prefix to use.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • prefixes

      public Map<Snowflake,String> prefixes()
      Returns the value of the prefixes record component.
      Returns:
      the value of the prefixes record component
    • defaultPrefix

      public String defaultPrefix()
      Returns the value of the defaultPrefix record component.
      Returns:
      the value of the defaultPrefix record component