bot

package
v0.0.0-...-3dd0de1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmpRemote

func CmpRemote(this, other interface{}) int

comparator for plugins

func KillBot

func KillBot(ctx actor.Context, pid *actor.PID)

Types

type BasicBot

type BasicBot interface {
	// a bot that is capable of spawning remote actors
	Remotable
	// ability to plug in functionality
	Pluggable
	// ability to subscribe/ unsubscribe to messages
	Subscribable
	// a bot must have an repository from which to download plugins
	PluggableRepository
	// a bot is an actor so it must have a Receive method
	Receive(ctx actor.Context)
	// a bot's lifecycle should be observable
	LifetimeObservable
}

Basic bot

type Bot

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

func NewSimpleBot

func NewSimpleBot(remoter *remote.Remote) *Bot

Create a new simple bot

func (*Bot) ActivePlugins

func (state *Bot) ActivePlugins() []*plgn.PluginIdentifier

Get active plugins

func (*Bot) AddActivePlugin

func (state *Bot) AddActivePlugin(plugin *plgn.PluginIdentifier)

Add a plugin to active plugins

func (*Bot) AddPeer

func (state *Bot) AddPeer(pid ...*actor.PID)

Add a peer

func (*Bot) AddRemote

func (state *Bot) AddRemote(host ...*Remote)

Add remotes

func (*Bot) AddSubscriber

func (state *Bot) AddSubscriber(subscriber *actor.PID, messageTypes ...msg.MessageType)

Adds a new subscriber to for a certain messaget type If no message type is specified, a subscription for all messages is created

func (*Bot) NotifySubscribers

func (state *Bot) NotifySubscribers(ctx actor.Context, message interface{})

Notify relevant subscribers that an event they have subscribed to has occurred.

func (*Bot) Peers

func (state *Bot) Peers(pid *actor.PID) *actor.PIDSet

Get peers. A copy of actual peers set is created.

func (*Bot) PluginLogger

func (state *Bot) PluginLogger() *log.Logger

Get logger for use in plugins

func (*Bot) Receive

func (state *Bot) Receive(ctx actor.Context)

Proto.Actor central Receive() method which gets passed all messages sent to the post box of this actor.

func (*Bot) RemoteRepoUrl

func (state *Bot) RemoteRepoUrl() *url.URL

Get URL to remote repository

func (*Bot) Remotes

func (state *Bot) Remotes() []*Remote

Get all remotes. Returns a copy of all the remotes.

func (*Bot) RemoveActivePlugin

func (state *Bot) RemoveActivePlugin(plugin plgn.Plugin)

Remove a plugin from active plugins.

func (*Bot) RemovePeer

func (state *Bot) RemovePeer(pid ...*actor.PID)

Remove a peer

func (*Bot) RemoveRemote

func (state *Bot) RemoveRemote(host ...*Remote)

Remove remotes

func (*Bot) RemoveSubscriber

func (state *Bot) RemoveSubscriber(unsubscriber *actor.PID, messageTypes ...msg.MessageType)

Removes a new subscriber from a certain message type If no message type is specified, all subscriptions are removed

func (*Bot) SetPeers

func (state *Bot) SetPeers(peers *actor.PIDSet)

Set peers

func (*Bot) SetRemoteRepoUrl

func (state *Bot) SetRemoteRepoUrl(url *url.URL)

Set URL to remote repository

func (*Bot) SetRemotes

func (state *Bot) SetRemotes(remotes sets.Set)

Set all remotes

func (*Bot) SpawnBot

func (state *Bot) SpawnBot(ctx actor.Context, host string, port int) (*actor.PID, error)

Spawns a new bot on the given remote host

func (*Bot) Subscribers

func (state *Bot) Subscribers() map[msg.MessageType]*actor.PIDSet

Get subscribers

type FinishedFunc

type FinishedFunc func()

type LifetimeObservable

type LifetimeObservable interface {
	// contains filtered or unexported methods
}

Handler methods for lifecycle event

type Pluggable

type Pluggable interface {
	// Get logger for plugins
	PluginLogger() *log.Logger
	// Get active plugins
	ActivePlugins() []*plgn.PluginIdentifier
	// Add a plugin to active plugins
	AddActivePlugin(plugin *plgn.PluginIdentifier)
	// Remove a plugin from active plugins
	RemoveActivePlugin(plugin *plgn.PluginIdentifier)
	// contains filtered or unexported methods
}

Ability to load plugins at runtime

type PluggableRepository

type PluggableRepository interface {
	// remote repository url
	RemoteRepoUrl() string
	// getter and setter
	SetRemoteRepoUrl(url string)
}

Central, pluggable repository to obtain plugins from

type PluginContract

type PluginContract struct {
	OnActivated   func(bot *Bot, ctx actor.Context, plugin plgn.Plugin)
	OnDeactivated func(bot *Bot, ctx actor.Context, plugin plgn.Plugin)
	Receive       func(bot *Bot, ctx actor.Context, plugin plgn.Plugin, finished FinishedFunc)
}

Specification/ Contract which a plugin must obey to

type Remotable

type Remotable interface {
	// Get remotes
	Remotes() sets.Set
	// Set remotes
	SetRemotes(remotes sets.Set)
	// Get peers
	// Adds a remote location
	AddRemote(host ...string)
	// Remove a remote location
	RemoveRemote(host ...string)
	// Get peers
	Peers(pid *actor.PID) *actor.PIDSet
	// Set peers
	SetPeers(peers *actor.PIDSet)
	// Add peer
	AddPeer(pid ...*actor.PID)
	// Remove peer
	RemovePeer(pid ...*actor.PID)
	// Spawn a bot on a given node
	SpawnBot(ctx actor.Context, host string, port int) (*actor.PID, error)
	// Kill a bot
	KillBot(ctx actor.Context, pid *actor.PID)
	// contains filtered or unexported methods
}

Holds remote locations (bot nodes) to spawn bots at

type Remote

type Remote struct {
	Host string
	Port int
}

type Subscribable

type Subscribable interface {
	// Get subscribers
	Subscribers() map[msg.MessageType]*actor.PIDSet
	// Adds a new subscriber to for a certain messaget type
	// If no message type is specified, a subscription for all messages is created
	AddSubscriber(subscriber *actor.PID, messageTypes ...msg.MessageType)
	// Handle *msg.Unsubscribe message
	RemoveSubscriber(unsubscriber *actor.PID, messageTypes ...msg.MessageType)
	// Notify subscribers about an event
	NotifySubscribers(ctx actor.Context, message interface{})
	// contains filtered or unexported methods
}

Ability to subsribe/ unsubsribe to events

Jump to

Keyboard shortcuts

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