hub

package
v0.0.0-...-1680768 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgTypeCommon = "common"
	MsgTypeDirect = "direct"
)
View Source
const (
	RequestTypeGet           = "get"
	RequestTypePostJsonObj   = "post-json-obj"
	RequestTypePostJsonArray = "post-json-array"
)
View Source
const (
	ActionTypeProxy = "proxy"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType string

type Bot

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

func NewBot

func NewBot(ctx context.Context, logger *log.Logger, cfg *Config, state Store, cmds ...Cmd) *Bot

func (*Bot) InteractionRespond

func (b *Bot) InteractionRespond(interaction *discordgo.Interaction, resp *discordgo.InteractionResponse)

func (*Bot) Send

func (b *Bot) Send(msg *Msg)

func (*Bot) Start

func (b *Bot) Start() error

type Cmd

type Cmd interface {
	Meta() *discordgo.ApplicationCommand
	Handle(b *Bot, options map[string]interface{}, s *discordgo.Session, i *discordgo.InteractionCreate)
	Autocomplete(b *Bot, s *discordgo.Session, i *discordgo.InteractionCreate)
}

type Config

type Config struct {
	*viper.Viper
}

func NewConfig

func NewConfig() (*Config, error)

func (*Config) Addr

func (c *Config) Addr() string

func (*Config) AppID

func (c *Config) AppID() string

func (*Config) DB

func (c *Config) DB() string

func (*Config) GuildID

func (c *Config) GuildID() string

func (*Config) Sources

func (c *Config) Sources() map[string]*SourceConfig

func (*Config) Token

func (c *Config) Token() string

type Dispatcher

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

func NewDispatcher

func NewDispatcher(logger *log.Logger, cfg *Config, state *FileStore, bot *Bot) *Dispatcher

func (*Dispatcher) HandlerWebhook

func (d *Dispatcher) HandlerWebhook(source string, body []byte, params interface{}, chCfg *SourceConfig) error

func (*Dispatcher) Proxy

func (d *Dispatcher) Proxy(source string, body []byte, params interface{}, srcCfg *SourceConfig) error

func (*Dispatcher) ServeHTTP

func (d *Dispatcher) ServeHTTP(w http.ResponseWriter, r *http.Request)

type FileStore

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

func NewFileStore

func NewFileStore(logger *log.Logger, fn string) (*FileStore, error)

func (*FileStore) AddSubscription

func (s *FileStore) AddSubscription(sub *Subscription) error

func (*FileStore) FindSubscriptionsBySource

func (s *FileStore) FindSubscriptionsBySource(source string) ([]*Subscription, error)

func (*FileStore) RemoveSubscription

func (s *FileStore) RemoveSubscription(source string, userID string) (*Subscription, error)

func (*FileStore) Save

func (s *FileStore) Save()

func (*FileStore) SaveLoop

func (s *FileStore) SaveLoop()

type Interaction

type Interaction struct {
	I *discordgo.Interaction
	R *discordgo.InteractionResponse
}

type Msg

type Msg struct {
	Body      string
	ChannelID string
	UserID    string
	Type      MsgType
	AsEmbed   bool
}

type MsgType

type MsgType string

type RequestType

type RequestType string

type Scope

type Scope struct {
	Raw string
	Sub *Subscription
	R   interface{}
	Cfg *SourceConfig
}

func (*Scope) JsonPath

func (s *Scope) JsonPath(p string) string

func (*Scope) MatchTokens

func (s *Scope) MatchTokens(found, val string) bool

type Server

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

func NewServer

func NewServer(cfg *Config, logger *log.Logger, dispatcher *Dispatcher) *Server

func (*Server) Start

func (s *Server) Start() error

type SourceConfig

type SourceConfig struct {
	RequestType     RequestType `json:"request_type" yaml:"request_type"`
	ActionType      ActionType  `json:"action_type" yaml:"action_type"`
	Template        string      `json:"template" yaml:"template"`
	FindPersonaExpr string      `json:"find_persona_expr" yaml:"find_persona_expr"`
	SendAsEmbed     bool        `json:"send_as_embed" yaml:"send_as_embed"`
}

type Store

type Store interface {
	FindSubscriptionsBySource(source string) ([]*Subscription, error)
	AddSubscription(sub *Subscription) error
	RemoveSubscription(source string, userID string) (*Subscription, error)
}

type SubscribeCmd

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

func NewSubscribeCmd

func NewSubscribeCmd(cfg *Config, store Store) *SubscribeCmd

func (*SubscribeCmd) Autocomplete

func (c *SubscribeCmd) Autocomplete(b *Bot, _ *discordgo.Session, i *discordgo.InteractionCreate)

func (*SubscribeCmd) Handle

func (c *SubscribeCmd) Handle(b *Bot, options map[string]interface{}, _ *discordgo.Session, i *discordgo.InteractionCreate)

func (*SubscribeCmd) Meta

type Subscription

type Subscription struct {
	Source       string
	ChannelID    string
	UserID       string
	Username     string
	Email        string
	Direct       bool
	OnlyPersonal bool
	CustomFilter string
}

type UnsubscribeCmd

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

func NewUnsubscribeCmd

func NewUnsubscribeCmd(cfg *Config, store Store) *UnsubscribeCmd

func (*UnsubscribeCmd) Autocomplete

func (c *UnsubscribeCmd) Autocomplete(b *Bot, _ *discordgo.Session, i *discordgo.InteractionCreate)

func (*UnsubscribeCmd) Handle

func (c *UnsubscribeCmd) Handle(b *Bot, options map[string]interface{}, _ *discordgo.Session, i *discordgo.InteractionCreate)

func (*UnsubscribeCmd) Meta

Jump to

Keyboard shortcuts

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