aussiebroadwan / tony

The Discord Bot for the TAB
0 stars 1 forks source link

Application Refactor #5

Closed lcox74 closed 8 months ago

lcox74 commented 8 months ago

The configuration and management of Applications and Application Rules were previously complex and somewhat cumbersome for feature development. Additionally, it was burdensome to have to code all application callbacks, even when they were not needed (NOP).

To simplify this process, we've reorganized all Application types under the applications directory. The specific application type is now determined by what is returned in the app.GetType() AppType function. The application types are as follows:

// AppTypeNOP is a command that does nothing and is used as a
// routing placeholder for parent containers for their sub applications.
framework.AppTypeNOP

// AppTypeCommand is an discord application command that is executed by a
// user and handled by the OnCommand() handler. You will also need to implement
// the GetDefinition() method to return the discordgo.ApplicationCommand
// definition for the command
framework.AppTypeCommand
    Implement: OnCommand(ctx framework.CommandContext)
               GetDefinition() *discordgo.ApplicationCommand

// AppTypeCommand is an discord application command that is executed by a
// user and handled by the OnCommand() handler
framework.AppTypeSubCommand
    Implement: OnCommand(ctx framework.CommandContext)

// AppTypeEvent is an event based application which handles user
// interactions with the OnEvent() handler
// message components or modals
framework.AppTypeEvent
    Implement: OnEvent(ctx framework.EventContext, eventType discordgo.InteractionType)

// AppTypeMessage is an application which runs on messages, handled by the
// OnMessage() handler
framework.AppTypeMessage
    Implement: OnMessage(ctx framework.MessageContext)

// AppTypeReaction is an application which runs on reactions, handled by the
// OnReaction() handler
framework.AppTypeReaction
    Implement: OnReaction(ctx framework.ReactionContext)

// AppTypeMountable is an application which requires something to run when the
// application is mounted after the discord session is made. Handled by the
// OnMount() handler
framework.AppTypeMountable
    Implement: OnMount(ctx framework.MountContext)

Application types can be mixed to suit your application's needs using the | operator, except for the combination of AppTypeCommand | AppTypeSubCommand, as command structures and routing are specifically managed to avoid issues with the Discord API.

For guidance on how to use these types and integrate applications effectively, refer to the examples provided with the currently implemented applications.