bot_webapi

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const CommandDTOsWebApiCacheKey = "bot_web_api_commands_get_cache"

CommandDTOsWebApiCacheKey is the cache key used to store and retrieve all commands as CommandDTO instances from the cache.

View Source
const CommandIdSeparator = "_"

CommandIdSeparator separator used for command ids. A command id consists of the entire path of command names until the target is reached.

View Source
const CommandOptionsDTOWebApiCacheKey = "bot_web_api_specific_command_options_get_%s_cache"

CommandOptionsDTOWebApiCacheKey is the template cache key used to cache command option API responses.

View Source
const ComponentDTOsResponseWebApiCacheKey = "bot_web_api_components_get_cache"

ComponentDTOsResponseWebApiCacheKey is the cache key used to store and retrieve all components as ComponentDTO instances from the cache.

View Source
const ParamCommandID = "id"

ParamCommandID is the name of the parameter that carries a requested command name.

View Source
const SpecificCommandDTOWebApiCacheKey = "bot_web_api_specific_command_get_%s_cache"

SpecificCommandDTOWebApiCacheKey is the cache key format used to store and retrieve a specific command as CommandDTO instance from the cache. There is exactly one placeholder in this constant, that should be replaced with the ID of the command to get.

Variables

View Source
var C = api.Component{

	Code:         "bot_webapi",
	Name:         "Bot WebAPI",
	Categories:   api.Categories{api.CategoryInternal},
	Description:  "This component handles setup of the web api for the bots core api endpoints.",
	LoadPriority: 999,

	State: &api.State{
		DefaultEnabled: true,
	},
}

Functions

func CommandGet added in v0.4.0

func CommandGet(g *gin.Context)

CommandGet endpoint

@Summary Get a specific command of the bot. @Description This endpoint returns information about the specific requested command. @Description The result on a success contains relevant information like name, description and category of commands. @Description Note that this endpoint does not return detailed information like the options of a command. @Description To obtain the available command options, the command must be queried on its own using the @Description single command options get endpoint. @Tags Command System @Param id path string true "ID of the command to search for" @Produce json @Success 200 {array} CommandDTO "An object containing information about a specific command" @Failure 404 {object} webapi.ErrorResponse "An error indicating that the requested resource could not be found" @Failure 500 {object} webapi.ErrorResponse "An error indicating that an internal error happened" @Router /commands/{id} [get]

func CommandOptionsGet added in v0.4.0

func CommandOptionsGet(g *gin.Context)

CommandOptionsGet endpoint

@Summary Get the options of a specific command of the bot. @Description This endpoint returns information about the options of the specified command. @Description The result on a success contains relevant information about the options and their choices. @Tags Command System @Param id path string true "ID of the command to search for options" @Produce json @Success 200 {array} CommandOptionDTO "An object containing information about the options of a specific command" @Failure 404 {object} webapi.ErrorResponse "An error indicating that the requested resource could not be found" @Failure 500 {object} webapi.ErrorResponse "An error indicating that an internal error happened" @Router /commands/{id}/options [get]

func CommandsGet added in v0.4.0

func CommandsGet(g *gin.Context)

CommandsGet endpoint

@Summary Get all available commands of the bot @Description This endpoint collects all available commands and returns them. @Description The result on a success contains relevant information like name, description and category of commands. @Description Note that this endpoint does not return detailed information like the options of a command. @Description To obtain the available command options, the command must be queried on its own using the @Description single command options get endpoint. @Tags Command System @Produce json @Success 200 {array} CommandDTO "An array consisting of objects containing information about commands" @Router /commands [get]

func ComponentsGet

func ComponentsGet(g *gin.Context)

ComponentsGet endpoint

@Summary Get all available components of the bot @Description This endpoint collects all available components and returns them. @Description The result on a success contains all relevant information, which includes name and description of components. @Description Additionally, the endpoint also returns the status of the components. @Description @Description The guild status is currently not populated and always false! @Tags Component System @Produce json @Success 200 {array} ComponentDTO "An array consisting of objects containing information about components" @Failure 500 {object} webapi.ErrorResponse "An error indicating that an internal error happened" @Router /components [get]

func LoadComponent

func LoadComponent(_ *discordgo.Session) error

LoadComponent loads the bot core component and handles migration of core entities and registration of important core event handlers.

Types

type CommandDTO added in v0.4.0

type CommandDTO struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Component   entities.ComponentCode `json:"component"`
	Category    api.Category           `json:"category"`
	Description string                 `json:"description"`

} //@Name Command

CommandDTO is an intermediate data transfer object that can be output or received by the WebAPI. This type is used, because the bot both has the general api.Command. This type represents a command with only API relevant data.

@Description Command holds information about a slash-command like its name, @Description description and its options. Note that commands are always @Description built from the deepest level commands. This means a command is either a sub command or the @Description top-level command.

func CommandDTOsFromCommands added in v0.4.0

func CommandDTOsFromCommands(cmds []*api.Command) []CommandDTO

CommandDTOsFromCommands creates an array of CommandDTO instances. The general data is computed from the passed api.Command. This function returns all commands that are currently registered.

type CommandOptionChoiceDTO added in v0.4.0

type CommandOptionChoiceDTO struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"`

} //@Name CommandOptionChoice

CommandOptionChoiceDTO is an intermediate data transfer object that can be output or received by the WebAPI. This type only contains necessary data to output a command choice on the web api.

@Description CommandOptionChoice holds information about a single choice of a command option. @Description This is only used as embedded data in a CommandOption normally.

type CommandOptionDTO added in v0.4.0

type CommandOptionDTO struct {
	Owner   string                   `json:"id"`
	Name    string                   `json:"name"`
	Type    int                      `json:"type"`
	Choices []CommandOptionChoiceDTO `json:"choices"`

} //@Name CommandOption

CommandOptionDTO is an intermediate data transfer object that can be output or received by the WebAPI. This type only contains necessary data to output one or more command options on the web api.

@Description CommandOption holds information about a single option of a command.

type ComponentDTO

type ComponentDTO struct {
	Code          entities.ComponentCode `json:"code"`
	Name          string                 `json:"name"`
	Categories    api.Categories         `json:"categories"`
	Description   string                 `json:"description"`
	GlobalEnabled bool                   `json:"global_enabled"`
	GuildEnabled  bool                   `json:"guild_enabled"`

} //@Name Component

ComponentDTO is an intermediate data transfer object that can be output or received by the WebAPI. This type is used, because the bot both has the general api.Component and the entities.RegisteredComponent types. This type represents a component with only API relevant data.

@Description Component holds the metadata of a component like its name and @Description and description. Additionally, it holds the current global @Description and guild status.

func ComponentDTOFromComponent

func ComponentDTOFromComponent(c *api.Component, guildId string) (ComponentDTO, error)

ComponentDTOFromComponent creates a new ComponentDTO. The general data is taken from the passed api.Component. The enabled states are pulled from the database.

Note that the guild status will only being pulled when a valid GuildID is passed. The passed GuildID must be present in the database. If no GuildID is passed or the ID is invalid, the Guild enabled status will result in false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL