Class Context
- java.lang.Object
-
- com.github.alex1304.ultimategdbot.api.Context
-
public class Context extends Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>
getArgs()
Gets the arguments of the command.Bot
getBot()
Gets the bot instance.Command
getCommand()
Gets the command that created this context.discord4j.core.event.domain.message.MessageCreateEvent
getEvent()
Gets the message create event associated to this command.reactor.core.publisher.Mono<Map<Plugin,Map<String,String>>>
getGuildSettings()
Gets the guild settingsString
getPrefixUsed()
Gets the prefix used in the command that created this context.<T> T
getVar(String name, Class<T> type)
Gets the value of a variable.<T> T
getVarOrDefault(String name, T defaultVal)
Gets the value of a variable.reactor.core.publisher.Mono<discord4j.core.object.entity.Message>
reply(String message)
Sends a message in the same channel the command was sent.reactor.core.publisher.Mono<discord4j.core.object.entity.Message>
reply(java.util.function.Consumer<? super discord4j.core.spec.MessageCreateSpec> spec)
Sends a message in the same channel the command was sent.reactor.core.publisher.Mono<Void>
setGuildSetting(String key, String val)
Edits an entry of the guild settings.void
setVar(String name, Object val)
Adds a variable in this context.void
setVarIfNotExists(String name, Object val)
Adds a variable in this context.
-
-
-
Method Detail
-
getCommand
public Command getCommand()
Gets the command that created this context.- Returns:
- the original command
-
getEvent
public discord4j.core.event.domain.message.MessageCreateEvent getEvent()
Gets the message create event associated to this command.- Returns:
- the event
-
getBot
public Bot getBot()
Gets the bot instance.- Returns:
- the bot
-
reply
public reactor.core.publisher.Mono<discord4j.core.object.entity.Message> reply(String message)
Sends a message in the same channel the command was sent.- Parameters:
message
- the message content of the reply- Returns:
- a Mono emitting the message sent
-
reply
public reactor.core.publisher.Mono<discord4j.core.object.entity.Message> reply(java.util.function.Consumer<? super discord4j.core.spec.MessageCreateSpec> spec)
Sends a message in the same channel the command was sent. This method supports advanced message construction.- Parameters:
spec
- the message content of the reply- Returns:
- a Mono emitting the message sent
-
getPrefixUsed
public String getPrefixUsed()
Gets the prefix used in the command that created this context.- Returns:
- the prefix used
-
setVar
public void setVar(String name, Object val)
Adds a variable in this context. If a variable of the same name exists, it is overwritten.- Parameters:
name
- the name of the variableval
- the value of the variable
-
setVarIfNotExists
public void setVarIfNotExists(String name, Object val)
Adds a variable in this context. If a variable of the same name exists, nothing happens.- Parameters:
name
- the name of the variableval
- the value of the variable
-
getVar
public <T> T getVar(String name, Class<T> type)
Gets the value of a variable.- Type Parameters:
T
- the variable type- Parameters:
name
- the variable nametype
- the type of the variable- Returns:
- the value of the variable, or null if not found or exists in the wrong type
-
getVarOrDefault
public <T> T getVarOrDefault(String name, T defaultVal)
Gets the value of a variable. If not found, the provided default value is returned instead.- Type Parameters:
T
- the variable type- Parameters:
name
- the variable namedefaultVal
- the default value to return if not found- Returns:
- the value of the variable, or the default value if not found or exists in the wrong type
-
getGuildSettings
public reactor.core.publisher.Mono<Map<Plugin,Map<String,String>>> getGuildSettings()
Gets the guild settings- Returns:
- an unmodifiable Map containing the guild settings keys and their associated values, grouped by plugins
-
setGuildSetting
public reactor.core.publisher.Mono<Void> setGuildSetting(String key, String val)
Edits an entry of the guild settings.- Parameters:
key
- the setting keyval
- the setting value- Returns:
- a Mono that completes when successfully updated
- Throws:
NoSuchElementException
- if no entry is found for the given keyIllegalArgumentException
- if the given value is not accepted by the entryUnsupportedOperationException
- if this method is called in a context that is outside of a Discord guild
-
-