events

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Event code groups, for convenience.

View Source
var EventsChannelMessages = []EventCode{EventChatNotice, EventChatMessage}

Functions

This section is empty.

Types

type EventCode

type EventCode int
const (
	// Normal chat message.
	EventChatMessage EventCode = iota
	// Chat notice.
	EventChatNotice
	// Private message received.
	EventPrivateMessage
	// URL found in the message.
	EventURLFound

	// Bot activity, like command or event handler started.
	EventBotWorking
	// Bot finished activity.
	EventBotDone

	// Transport connected.
	EventConnected
	// Someone joined a channel.
	EventJoinedChannel
	// Bot re-joined a channel.
	EventReJoinedChannel
	// Someone left a channel.
	EventPartChannel
	// Someone was kicked from a channel.
	EventKickedFromChannel
	// Someone was banned from a channel.
	EventBannedFromChannel
	// Other channel operations.
	EventChannelOps

	// Bot tick.
	EventTick
	// Daily bot tick.
	EventDailyTick
)

Single event codes.

type EventDispatcher

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

Event dispatcher.

func New

func New(logger *logrus.Logger) *EventDispatcher

New will create a new event dispatcher instance.

func (*EventDispatcher) RegisterListener

func (dispatcher *EventDispatcher) RegisterListener(eventCode EventCode, listener EventListenerFunc)

RegisterListener will register a listener to an event.

func (*EventDispatcher) RegisterMultiListener

func (dispatcher *EventDispatcher) RegisterMultiListener(eventCodes []EventCode, listener EventListenerFunc)

RegisterMultiListener will attach a listener to multiple events.

func (*EventDispatcher) SetBlackList

func (dispatcher *EventDispatcher) SetBlackList(blackList []string)

SetBlackList sets the ignore list.

func (*EventDispatcher) Trigger

func (dispatcher *EventDispatcher) Trigger(eventMessage EventMessage)

Trigger will trigger an event.

type EventListenerFunc

type EventListenerFunc func(message EventMessage)

Type for a valid event listener function.

type EventMessage

type EventMessage struct {
	// Name of the transport that triggered the event.
	TransportName string
	// Message formatting accepted by the transport.
	TransportFormatting Formatting
	// Event code.
	EventCode EventCode
	// Sender information
	Nick, UserId string
	Channel      string
	Message      string
	// Context for the message, will be passed back if any listener sends a message.
	Context string
	// Was the message directed at the bot? If yes, bot will check for commands.
	// Message directed at the bot should be stripped of the prefixes like dot or bot's name.
	// In case of join, part etc. this will indicate whether bot was the subject.
	AtBot bool
}

Message for the events channel.

func (*EventMessage) ChannelId

func (message *EventMessage) ChannelId() string

ChannelId will return a channel id that is (most likely) unique.

func (*EventMessage) IsPrivate

func (message *EventMessage) IsPrivate() bool

IsPrivate will tell if an event was triggered by a private chat message.

type Formatting

type Formatting int

Message formatting options.

const (
	FormatPlain Formatting = iota
	FormatIRC
	FormatMarkdown
)

Jump to

Keyboard shortcuts

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