seabird

package module
v0.0.0-...-bafc44e Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: MIT Imports: 25 Imported by: 0

README

seabird-core

Seabird has been an IRC bot for the last 10 years in many different incarnations. This version is a gRPC service which exports a number of functions to easily interact with chat services.

Server Implementations

The official gRPC libraries are used for a server implementation but a semi-custom http Handler is needed in order to support grpc-web without a separate proxy.

Building

The easiest way to build and deploy seabird-core is to use the official docker images. The latest tag points to the master branch.

In order to build these, you can use the following:

docker build -t seabird-core:latest .

If you want to run the server outside of docker, you can use the following:

go generate ./...
go run ./cmd/seabird-core

Configuring

Environment Variables

For production, it is generally recommended that environment variables be configured in the environment, but for dev, any .env file in the working directory of the running service will be loaded.

  • SEABIRD_IRC_HOST - which irc server to connect to. This accepts the irc, ircs, and ircs+unsafe schemes, depending on the connection.
  • SEABIRD_BIND_HOST (optional, defaults to :11235) - which host/port to bind the gRPC service to. Note that it will not be tls encrypted, so you may want to put it behind a reverse proxy.
  • SEABIRD_NICK - nick to use when connecting to IRC
  • SEABIRD_USER (optional, defaults to SEABIRD_NICK) - username to use when connecting to IRC
  • SEABIRD_NAME (optional, defaults to SEABIRD_USER) - name to use when connecting to IRC
  • SEABIRD_PASS (optional) - password to use when connecting to IRC
  • SEABIRD_COMMAND_PREFIX (optional, defaults to !)
  • SEABIRD_TOKEN_FILE - the file to load tokens from. Note that this file will be watched for changes so a token change will not require a bot restart.
  • SEABIRD_ENABLE_WEB (optional, defaults to true) - whether or not to enable grpc-web
Token File

The tokens key is a mapping of tag to auth_token. Each tag will be associated with a given auth token. It is meant as a convenience to make it easier to identify where incoming requests are coming from.

As was mentioned before, this file will be watched for changes so tokens will go into effect without a restart of the service.

As an example, the following tokens file defines the belak tag with an auth_token of hunter2.

{
  "tokens": {
    "belak": "hunter2"
  }
}

Documentation

Index

Constants

View Source
const EVENT_STREAM_BUFFER = 10

Variables

This section is empty.

Functions

func CtxLogger

func CtxLogger(ctx context.Context) *logrus.Entry

func CtxStreamID

func CtxStreamID(ctx context.Context) uuid.UUID

func CtxTag

func CtxTag(ctx context.Context) string

func WithLogger

func WithLogger(ctx context.Context, logger *logrus.Entry) context.Context

func WithStreamID

func WithStreamID(ctx context.Context, id uuid.UUID) context.Context

func WithTag

func WithTag(ctx context.Context, tag string) context.Context

Types

type CommandMetadata

type CommandMetadata struct {
	Name      string
	ShortHelp string
	FullHelp  string
}

type ContextKey

type ContextKey string

func (ContextKey) String

func (key ContextKey) String() string

type EventStream

type EventStream struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewEventStream

func NewEventStream(ctx context.Context, addr net.Addr, meta map[string]*CommandMetadata) *EventStream

func (*EventStream) Close

func (s *EventStream) Close()

func (*EventStream) CommandInfo

func (s *EventStream) CommandInfo(command string) *CommandMetadata

func (*EventStream) Commands

func (s *EventStream) Commands() []string

func (*EventStream) ConnectionTime

func (s *EventStream) ConnectionTime() time.Time

func (*EventStream) ID

func (s *EventStream) ID() uuid.UUID

func (*EventStream) Recv

func (s *EventStream) Recv(ctx context.Context) (*pb.Event, error)

func (*EventStream) RemoteAddr

func (s *EventStream) RemoteAddr() net.Addr

func (*EventStream) Send

func (s *EventStream) Send(e *pb.Event) error

func (*EventStream) Tag

func (s *EventStream) Tag() string

type Server

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

func NewServer

func NewServer(config ServerConfig) (*Server, error)

func (*Server) GetChannelInfo

func (s *Server) GetChannelInfo(ctx context.Context, req *pb.ChannelInfoRequest) (*pb.ChannelInfoResponse, error)

func (*Server) GetCoreInfo

func (s *Server) GetCoreInfo(ctx context.Context, req *pb.CoreInfoRequest) (*pb.CoreInfoResponse, error)

GetCoreInfo implements SeabirdServer.GetCoreInfo

func (*Server) GetStreamInfo

func (s *Server) GetStreamInfo(ctx context.Context, req *pb.StreamInfoRequest) (*pb.StreamInfoResponse, error)

GetStreamInfo implements SeabirdServer.GetStreamInfo

func (*Server) JoinChannel

func (s *Server) JoinChannel(ctx context.Context, req *pb.JoinChannelRequest) (*pb.JoinChannelResponse, error)

func (*Server) LeaveChannel

func (s *Server) LeaveChannel(ctx context.Context, req *pb.LeaveChannelRequest) (*pb.LeaveChannelResponse, error)

func (*Server) ListChannels

func (s *Server) ListChannels(ctx context.Context, req *pb.ListChannelsRequest) (*pb.ListChannelsResponse, error)

func (*Server) ListStreams

func (s *Server) ListStreams(ctx context.Context, req *pb.ListStreamsRequest) (*pb.ListStreamsResponse, error)

ListStreams implements SeabirdServer.ListStreams

func (*Server) NewStream

func (s *Server) NewStream(ctx context.Context, addr net.Addr, meta map[string]*CommandMetadata) (context.Context, *EventStream)

func (*Server) Run

func (s *Server) Run() error

Run will connect to the IRC server and start the listener.

func (*Server) SendMessage

func (s *Server) SendMessage(ctx context.Context, req *pb.SendMessageRequest) (*pb.SendMessageResponse, error)

func (*Server) SetChannelTopic

func (s *Server) SetChannelTopic(ctx context.Context, req *pb.SetChannelTopicRequest) (*pb.SetChannelTopicResponse, error)

SetChannelInfo implements SeabirdServer.SetChannelTopic

func (*Server) SetTokens

func (s *Server) SetTokens(tokens map[string]string)

SetTokens allows an external method to update the tokens of the currently running server to avoid having to restart when they are added.

func (*Server) StreamEvents

func (s *Server) StreamEvents(req *pb.StreamEventsRequest, outputStream pb.Seabird_StreamEventsServer) error

type ServerConfig

type ServerConfig struct {
	IrcHost       string            `json:"irc_host"`
	Nick          string            `json:"irc_nick"`
	User          string            `json:"irc_user"`
	Name          string            `json:"irc_name"`
	Pass          string            `json:"irc_pass"`
	CommandPrefix string            `json:"command_prefix"`
	BindHost      string            `json:"bind_host"`
	EnableWeb     bool              `json:"enable_web"`
	Tokens        map[string]string `json:"tokens"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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