irc

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMalformedIRCMessage = errors.New("malformed IRC message")

ErrMalformedIRCMessage represents the error returned when parsing an incoming IRC line fails due to invalid message syntax

Functions

This section is empty.

Types

type ChannelTopic

type ChannelTopic struct {
	Topic string
	SetBy string
	SetAt time.Time
}

ChannelTopic represents a channel's set topic and metadata

type Command

type Command int

Command represents an IRC command

const (
	NickCmd Command = iota
	UserCmd

	PrivmsgCmd
	JoinCmd
	PartCmd
	ModeCmd
	TopicCmd
	WhoCmd

	PingCmd
	PongCmd

	NumericReplyCmd
)

Constants corresponding to message types

type Config

type Config struct {
	ServerName string
	ListenAddr string

	MOTD string
}

Config holds configurable parameters for the IRC server

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults overwrites config entries with their default values

type Join

type Join struct {
	User    User
	Channel string
}

Join is a JOIN message

func (*Join) ToMessage

func (j *Join) ToMessage() *Message

ToMessage turns a Join into a Message

type Messagable

type Messagable interface {
	ToMessage() *Message
}

Messagable is a type that can be converted to an IRC message

func ParseMessage

func ParseMessage(m *Message) (Messagable, error)

ParseMessage parses an IRC Message into a higher-level IRC type

type Message

type Message struct {
	Prefix string
	Cmd    Command
	Params []string
}

Message corresponds to an IRC message

func StringToMessage

func StringToMessage(str string) (*Message, error)

StringToMessage takes a string with a line of input and returns a Message corresponding to the line

func (*Message) String

func (m *Message) String() string

type Nick

type Nick struct {
	From    User
	NewNick string
}

Nick represents a IRC user nick change event

func (*Nick) ToMessage

func (n *Nick) ToMessage() *Message

ToMessage turns a Nick into a Message

type NumericCommand

type NumericCommand int

NumericCommand represents a numbered server reply

const (
	RPL_WELCOME  NumericCommand = 001
	RPL_YOURHOST NumericCommand = 002
	RPL_CREATED  NumericCommand = 003
	RPL_ISUPPORT NumericCommand = 005

	RPL_CHANNELMODEIS NumericCommand = 324
	RPL_CREATIONTIME  NumericCommand = 329
	RPL_TOPIC         NumericCommand = 332
	RPL_TOPIC_WHOTIME NumericCommand = 333

	RPL_WHOREPLY   NumericCommand = 352
	RPL_ENDOFWHO   NumericCommand = 315
	RPL_NAMREPLY   NumericCommand = 353
	RPL_ENDOFNAMES NumericCommand = 366
	RPL_MOTD       NumericCommand = 372
	RPL_MOTDSTART  NumericCommand = 375
	RPL_ENDOFMOTD  NumericCommand = 376

	ERR_UNKNOWNCOMMAND NumericCommand = 421
	ERR_NEEDMOREPARAMS NumericCommand = 461
)

nolint: golint noinspection GoSnakeCaseUsage

type NumericReply

type NumericReply struct {
	Code   NumericCommand
	Params []string

	ServerName string
	Target     string
}

A NumericReply is a numbered reply generated by the server

func ErrNeedMoreParams

func ErrNeedMoreParams(command string) *NumericReply

ErrNeedMoreParams is the numeric reply to a command that requires more params

func ErrUnknownCommand

func ErrUnknownCommand(command string) *NumericReply

ErrUnknownCommand is the numeric reply to an unknown or invalid command

func MOTDAsNumerics

func MOTDAsNumerics(motd string) []*NumericReply

MOTDAsNumerics formats a MOTD into a series of numeric replies

func NamelistAsNumerics

func NamelistAsNumerics(users []User, channelName string) []*NumericReply

NamelistAsNumerics formats a list of Users into a series of NAMES replies

func WholistAsNumerics

func WholistAsNumerics(users []User, channelName, serverName string) []*NumericReply

WholistAsNumerics formats a list of Users into a series of WHO replies

func (*NumericReply) Error

func (n *NumericReply) Error() string

func (*NumericReply) String

func (n *NumericReply) String() string

func (*NumericReply) ToMessage

func (n *NumericReply) ToMessage() *Message

ToMessage turns a NumericReply into a message

type Part

type Part struct {
	User    User
	Channel string
	Message string
}

Part is a PART message

func (*Part) ToMessage

func (j *Part) ToMessage() *Message

ToMessage turns a Join into a Message

type Pong

type Pong struct {
	ServerName string
	Token      string
}

Pong is a PONG message

func (*Pong) ToMessage

func (p *Pong) ToMessage() *Message

ToMessage turns a Pong into a Message

type Privmsg

type Privmsg struct {
	From    User
	Target  string
	Message string
}

Privmsg represents a line in an IRC conversation

func (*Privmsg) IsFromSelf

func (p *Privmsg) IsFromSelf() bool

IsFromSelf returns whether the private message originated from self

func (*Privmsg) IsTargetChannel

func (p *Privmsg) IsTargetChannel() bool

IsTargetChannel returns whether the target for this PrivMsg is a channel

func (*Privmsg) IsValidTarget

func (p *Privmsg) IsValidTarget() bool

IsValidTarget returns whether the private message target is legal or not

func (*Privmsg) ToMessage

func (p *Privmsg) ToMessage() *Message

ToMessage turns a Privmsg into a Message

type Server

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

Server represents the IRC server listener for bridging IRC clients to Slack and fanning out Slack events as necessary

func NewServer

func NewServer(config *Config, stopChan <-chan interface{}, stateProvider ServerStateProvider) *Server

NewServer creates a new IRC server

func (*Server) HandleChannelJoined added in v0.1.4

func (s *Server) HandleChannelJoined(channelName string)

HandleChannelJoined handles a Slack-initiated channel membership change event. This special signalling is necessary due to the extra data (NAMES/topic) which needs to be sent by the IRC server on join.

func (*Server) HandleConnectBurst

func (s *Server) HandleConnectBurst(selfUser User)

HandleConnectBurst handles the initial burst of data from a freshly established Slack connection.

Sets the IRC user info for the gateway user and informs clients.

func (*Server) HandleOutgoingMessageRouting

func (s *Server) HandleOutgoingMessageRouting(outgoingMessages <-chan *Message)

HandleOutgoingMessageRouting handles fanning out IRC messages generated from Slack events

func (*Server) Listen

func (s *Server) Listen()

Listen for and accept incoming connections on the configured address.

type ServerMessage

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

ServerMessage is a message from a client to the server, indexed by the remote address of the connection

type ServerStateProvider

type ServerStateProvider interface {
	GetChannelUsers(channelName string) []User

	GetChannelTopic(channelName string) ChannelTopic

	GetChannelCTime(channelName string) time.Time

	GetChannelPrivate(channelName string) bool

	GetJoinedChannels() []string

	SendPrivmsg(privMsg *Privmsg)

	GetUserFromNick(nick string) User
}

ServerStateProvider contains methods used by the IRC server to answer client queries about channels and their members.

type Topic

type Topic struct {
	From    User
	Channel string
	Topic   string
}

Topic is a TOPIC message

func (*Topic) ToMessage

func (t *Topic) ToMessage() *Message

ToMessage turns a Topic into a Message

type User

type User struct {
	Nick     string
	Ident    string
	Host     string
	RealName string

	Away bool
}

User represents a user identified by a nick and an ident

func ParseUserString

func ParseUserString(s string) User

ParseUserString pares a string into an IRC User

func (User) String

func (u User) String() string

Jump to

Keyboard shortcuts

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