Help us shape the future of Go! Take the 2026 Go Developer Survey

interactive

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package interactive contains basic API for creating menus with buttons and selects.

menu := NewInteractive(manager, interaction)
yes := func(i *interactions.Interaction) bool {
	i.ComponentMessageUpdate().Content("Message successfully deleted!").Execute()
	return false
}
no := func(i *interactions.Interaction) bool {
	i.ComponentMessageUpdate().Content("Message deletion has been canceled!").Execute()
	return false
}
interaction.SendMessageReply().
	Content("Are you sure you want to delete this message?").
	ActionRow(
		components.NewButton(components.ButtonStyleSuccess).SetCustomID("yes").SetLabel("Yes!"),
		components.NewButton(components.ButtonStyleDanger).SetCustomID("nope").SetLabel("Nope!")).
	Execute()
menu.SetFilter(func(i *interactions.Interaction) bool {
	return i.UserID() == interaction.UserID()
})
menu.Start(interactive.Actions{
	"yes": yes,
	"nope": no,
})

The boolean output variable in action handler means if you want to listen for another interaction (if false, stops listening and exits a loop).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actions

type Actions map[string]Handler

type Handler

type Handler func(i *interactions.Interaction) bool

Return false if you no longer want to listen for interactions.

type Interactive

type Interactive struct {
	// contains filtered or unexported fields
}

func NewInteractive

func NewInteractive(manager *Manager, i *interactions.Interaction) *Interactive

func (*Interactive) Close

func (i *Interactive) Close()

func (*Interactive) OnTimeout

func (i *Interactive) OnTimeout(handler func(i *Interactive))

func (*Interactive) ResetTimeout

func (i *Interactive) ResetTimeout()

func (*Interactive) SetFilter

func (i *Interactive) SetFilter(handler func(i *interactions.Interaction) bool)

func (*Interactive) Start

func (i *Interactive) Start(actions Actions) error

func (*Interactive) WithTimeout

func (i *Interactive) WithTimeout(time time.Duration) *Interactive

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(client client.Client) *Manager

Jump to

Keyboard shortcuts

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