irc

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

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

Go to latest
Published: Aug 28, 2015 License: MIT Imports: 10 Imported by: 0

README

irc

IRC is a library that can be used to create IRC servers or clients.

Based on RFCs 1459, 2810, 2811, 2812, and 2813.

Documentation

Index

Constants

This section is empty.

Variables

UserModes contains the supported User UserMode types

Functions

func AwayHandler

func AwayHandler(message *irc.Message, client *Client)

AwayHandler is a CommandHandler to respond to IRC AWAY commands from a client Implemented according to RFC 1459 Section 5.1 and RFC 2812 Section 4.1

func ChannelModeHandler

func ChannelModeHandler(message *irc.Message, client *Client)

ChannelModeHandler is a specialized CommandHandler to respond to channel IRC MODE commands from a client Implemented according to RFC 1459 Section 4.2.3.1 and RFC 2811

func InviteHandler

func InviteHandler(message *irc.Message, client *Client)

InviteHandler is a specialized CommandHandler to respond to channel IRC INVITE commands from a client Implemented according to RFC 1459 Section 4.2.7 and RFC 2812 Section 3.2.7

func IsonHandler

func IsonHandler(message *irc.Message, client *Client)

IsonHandler is a specialized CommandHandler to respond to channel IRC ISON commands from a client Implemented according to RFC 1459 Section 5.8 and RFC 2812 Section 4.9

func JoinHandler

func JoinHandler(message *irc.Message, client *Client)

JoinHandler is a CommandHandler to respond to IRC JOIN commands from a client Implemented according to RFC 1459 Section 4.2.1 and RFC 2812 Section 3.2.1

func KickHandler

func KickHandler(message *irc.Message, client *Client)

KickHandler is a specialized CommandHandler to respond to channel IRC KICK commands from a client Implemented according to RFC 1459 Section 4.2.8 and RFC 2812 Section 3.2.8

func LinksHandler

func LinksHandler(message *irc.Message, client *Client)

LinksHandler is a specialized CommandHandler to respond to channel IRC LINKS commands from a client Implemented according to RFC 1459 Section 4.3.3 and RFC 2812 Section 3.4.5

func ListHandler

func ListHandler(message *irc.Message, client *Client)

ListHandler is a specialized CommandHandler to respond to channel IRC LIST commands from a client Implemented according to RFC 1459 Section 4.2.6 and RFC 2812 Section 3.2.6

func MOTDHandler

func MOTDHandler(message *irc.Message, client *Client)

MOTDHandler is a specialized CommandHandler to respond to channel IRC MOTD commands from a client Implemented according to RFC 1459 Section 8.5 and RFC 2812 Section 3.4.1

func ModeHandler

func ModeHandler(message *irc.Message, client *Client)

ModeHandler is a CommandHandler to respond to IRC MODE commands from a client Implemented according to RFC 1459 Section 4.2.3 and RFC 2812 Section 3.1.5 and RFC 2811

func NamesHandler

func NamesHandler(message *irc.Message, client *Client)

NamesHandler is a specialized CommandHandler to respond to channel IRC NAMES commands from a client Implemented according to RFC 1459 Section 4.2.5 and RFC 2812 Section 3.2.5

func NickHandler

func NickHandler(message *irc.Message, client *Client)

NickHandler is a CommandHandler to respond to IRC NICK commands from a client Implemented according to RFC 1459 Section 4.1.2 and RFC 2812 Section 3.1.2

func NoticeHandler

func NoticeHandler(message *irc.Message, client *Client)

NoticeHandler is a CommandHandler to respond to IRC NOTICE commands from a client Implemented according to RFC 1459 Section 4.4.2 and RFC 2812 Section 3.3.2

func OperHandler

func OperHandler(message *irc.Message, client *Client)

OperHandler is a specialized CommandHandler to respond to channel IRC OPER commands from a client Implemented according to RFC 1459 Section 4.1.5 and RFC 2812 Section 3.1.4

func PartHandler

func PartHandler(message *irc.Message, client *Client)

PartHandler is a CommandHandler to respond to IRC PART commands from a client Implemented according to RFC 1459 Section 4.2.2 and RFC 2812 Section 3.2.2

func PassHandler

func PassHandler(message *irc.Message, client *Client)

PassHandler is a CommandHandler to respond to IRC PASS commands from a client Implemented according to RFC 1459 Section 4.1.1 and RFC 2812 Section 3.1.1

func PingHandler

func PingHandler(message *irc.Message, client *Client)

PingHandler is a CommandHandler to respond to IRC PING commands from a client Implemented according to RFC 1459 Section 4.6.2 and RFC 2812 Section 3.7.2

func PongHandler

func PongHandler(message *irc.Message, client *Client)

PongHandler is a CommandHandler to respond to IRC PONG commands from a client Implemented according to RFC 1459 Section 4.6.3 and RFC 2812 Section 3.7.3

func PrivMsgHandler

func PrivMsgHandler(message *irc.Message, client *Client)

PrivMsgHandler is a CommandHandler to respond to IRC PRIVMSG commands from a client Implemented according to RFC 1459 Section 4.4.1 and RFC 2812 Section 3.3.1

func QuitHandler

func QuitHandler(message *irc.Message, client *Client)

QuitHandler is a CommandHandler to respond to IRC QUIT commands from a client Implemented according to RFC 1459 Section 4.1.6 and RFC 2812 Section 3.1.7

func SendInvite

func SendInvite(inviter *Client, invitee *Client, channel *Channel)

SendInvite handles sending the invite messages to both parties

func TimeHandler

func TimeHandler(message *irc.Message, client *Client)

TimeHandler is a specialized CommandHandler to respond to channel IRC TIME commands from a client Implemented according to RFC 1459 Section 4.3.4 and RFC 2812 Section 3.4.6

func TopicHandler

func TopicHandler(message *irc.Message, client *Client)

TopicHandler is a CommandHandler to respond to IRC TOPIC commands from a client Implemented according to RFC 1459 Section 4.2.4 and RFC 2812 Section 3.2.4

func UserHandler

func UserHandler(message *irc.Message, client *Client)

UserHandler is a CommandHandler to respond to IRC USER commands from a client Implemented according to RFC 1459 Section 4.1.3 and RFC 2812 Section 3.1.3

func UserModeHandler

func UserModeHandler(message *irc.Message, client *Client)

UserModeHandler is a specialized CommandHandler to respond to global or user IRC MODE commands from a client Implemented according to RFC 1459 Section 4.2.3.2 and RFC 2812 Section 3.1.5

func VersionHandler

func VersionHandler(message *irc.Message, client *Client)

VersionHandler is a specialized CommandHandler to respond to channel IRC VERSION commands from a client Implemented according to RFC 1459 Section 4.3.1 and RFC 2812 Section 3.4.3

func WhoHandler

func WhoHandler(message *irc.Message, client *Client)

WhoHandler is a CommandHandler to respond to IRC WHO commands from a client Implemented according to RFC 1459 Section 4.5.1 and RFC 2812 Section 3.6.1

Types

type BasicOperAuthMethod

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

BasicOperAuthMethod can handle simple username password mappings for operator authentication

func NewBasicOperAuthMethod

func NewBasicOperAuthMethod() *BasicOperAuthMethod

NewBasicOperAuthMethod creates and returns a new BasicOperAuthMethod

func (BasicOperAuthMethod) Add

func (b BasicOperAuthMethod) Add(username, password string)

Add adds a new username and password for an acceptable operator

func (BasicOperAuthMethod) Authenticate

func (b BasicOperAuthMethod) Authenticate(username string, password string, client *Client)

Authenticate locates if an operator of the given username is found, and if so checks if the password matches

func (BasicOperAuthMethod) Get

func (b BasicOperAuthMethod) Get(username string) (password string, ok bool)

Get returns the password if the username was found as a valid operator, if not found, ok will be false

func (BasicOperAuthMethod) Remove

func (b BasicOperAuthMethod) Remove(username string)

Remove removes an operator from being allowed to authenticate

type Channel

type Channel struct {
	Name string
	*ChannelModeSet
	Topic string
	Key   string

	Server *Server
	// contains filtered or unexported fields
}

Channel represents an IRC channel or room

func NewChannel

func NewChannel(s *Server, creator *Client) *Channel

NewChannel creates and returns a new Channel

func (*Channel) AddMember

func (c *Channel) AddMember(client *Client)

AddMember adds a member to the channel

func (*Channel) AddMemberMode

func (c *Channel) AddMemberMode(client *Client, mode ChannelMode)

AddMemberMode adds a mode for the member of the channel

func (*Channel) GetMemberCount

func (c *Channel) GetMemberCount() int

GetMemberCount returns how many users are currently on the channel

func (*Channel) GetMemberModes

func (c *Channel) GetMemberModes(client *Client) *ChannelModeSet

GetMemberModes returns the Channel Modes active for a member

func (*Channel) HasMember

func (c *Channel) HasMember(client *Client) bool

HasMember returns if a client is an existing member of this channel

func (*Channel) Join

func (c *Channel) Join(client *Client, key string)

Join handles a client joining the channel and notifies other channel members

func (*Channel) Kick

func (c *Channel) Kick(client *Client, kicked []string, message string)

Kick provides the capability for operators to kick members out of the channel

func (*Channel) ListMessage

func (c *Channel) ListMessage(client *Client) (m *irc.Message)

ListMessage creates and returns the message that should be sent for an IRC LIST query

func (*Channel) MemberHasMode

func (c *Channel) MemberHasMode(client *Client, mode ChannelMode) bool

MemberHasMode returns whether the given client has the requested mode

func (*Channel) Message

func (c *Channel) Message(client *Client, message string)

Message is when a Private Message is directed for this channel - forward the message to each member

func (*Channel) Names

func (c *Channel) Names(client *Client) []string

Names responds to to IRC NAMES command for the channel

func (*Channel) Notice

func (c *Channel) Notice(client *Client, message string)

Notice is when a Notice is directed for this channel - forward the notice to each member

func (*Channel) Part

func (c *Channel) Part(client *Client, message string)

Part handles when a client leaves a channel

func (*Channel) Quit

func (c *Channel) Quit(client *Client, message string)

Quit is when a client quits the server - at channel level, similar to part

func (*Channel) RemoveMember

func (c *Channel) RemoveMember(client *Client)

RemoveMember removes a member from the channel

func (*Channel) RemoveMemberMode

func (c *Channel) RemoveMemberMode(client *Client, mode ChannelMode)

RemoveMemberMode removes a mode from the member of the channel

func (*Channel) SendMessage

func (c *Channel) SendMessage(m *irc.Message)

SendMessage allows sending an IRC message to all channel members

func (*Channel) SendMessageToOthers

func (c *Channel) SendMessageToOthers(m *irc.Message, client *Client)

SendMessageToOthers allows sending an IRC message to all other channel members

func (*Channel) TopicCommand

func (c *Channel) TopicCommand(client *Client, topic string)

TopicCommand handles querying or modifying the channels topic

func (*Channel) UpdateMemberNick

func (c *Channel) UpdateMemberNick(client *Client, oldNick string)

UpdateMemberNick updates the listing of the client from the old nickname to what the client actually has

type ChannelMode

type ChannelMode rune

ChannelMode - RFC 1459 Section 4.2.3.1 and RFC 2812 Section 3.2.3 and RFC 2811 Section 4

const (
	ChannelModeCreator  ChannelMode = 'O'
	ChannelModeOperator ChannelMode = 'o'
	ChannelModeVoice    ChannelMode = 'v'

	ChannelModeAnonymous         ChannelMode = 'a'
	ChannelModeInviteOnly        ChannelMode = 'i'
	ChannelModeModerated         ChannelMode = 'm'
	ChannelModeNoOutsideMessages ChannelMode = 'n'
	ChannelModeQuiet             ChannelMode = 'q'
	ChannelModePrivate           ChannelMode = 'p'
	ChannelModeSecret            ChannelMode = 's'
	ChannelModeReOp              ChannelMode = 'r'
	ChannelModeTopic             ChannelMode = 't'

	ChannelModeKey   ChannelMode = 'k'
	ChannelModeLimit ChannelMode = 'l'

	ChannelModeBan            ChannelMode = 'b'
	ChannelModeExceptionMask  ChannelMode = 'e'
	ChannelModeInvitationMask ChannelMode = 'I'
)

type ChannelModeSet

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

ChannelModeSet represents a set of active ChannelModes

func NewChannelModeSet

func NewChannelModeSet() *ChannelModeSet

NewChannelModeSet creates and returns a new ChannelModeSet

func (*ChannelModeSet) AddBanMask

func (c *ChannelModeSet) AddBanMask(mask string)

AddBanMask sets the channel ban mask

func (*ChannelModeSet) AddExceptionMask

func (c *ChannelModeSet) AddExceptionMask(mask string)

AddExceptionMask sets the channel exception mask

func (*ChannelModeSet) AddInvitationMask

func (c *ChannelModeSet) AddInvitationMask(mask string)

AddInvitationMask sets the channel invitation mask

func (*ChannelModeSet) AddMode

func (c *ChannelModeSet) AddMode(mode ChannelMode)

AddMode adds a ChannelMode as active

func (*ChannelModeSet) AddModeWithValue

func (c *ChannelModeSet) AddModeWithValue(mode ChannelMode, value interface{})

AddModeWithValue adds a ChannelMode as active with a value

func (*ChannelModeSet) Copy

func (c *ChannelModeSet) Copy() *ChannelModeSet

Copy creates and returns a deep copy of a ChannelModeSet

func (*ChannelModeSet) GetBanMasks

func (c *ChannelModeSet) GetBanMasks() map[string]interface{}

GetBanMasks gets the ban masks for the channel

func (*ChannelModeSet) GetExceptionMasks

func (c *ChannelModeSet) GetExceptionMasks() map[string]interface{}

GetExceptionMasks gets the exception masks for the channel

func (*ChannelModeSet) GetInvitationMasks

func (c *ChannelModeSet) GetInvitationMasks() map[string]interface{}

GetInvitationMasks gets the invitation masks for the channel

func (*ChannelModeSet) GetKey

func (c *ChannelModeSet) GetKey() string

GetKey gets the key if stored in the ChannelModeSet

func (*ChannelModeSet) GetLimit

func (c *ChannelModeSet) GetLimit() int

GetLimit gets the member limit for the channel

func (*ChannelModeSet) GetMode

func (c *ChannelModeSet) GetMode(mode ChannelMode) interface{}

GetMode determines if the ChannelModeSet contains the given ChannelMode

func (*ChannelModeSet) HasMode

func (c *ChannelModeSet) HasMode(mode ChannelMode) bool

HasMode determines if the ChannelModeSet contains the given ChannelMode

func (*ChannelModeSet) RemoveMode

func (c *ChannelModeSet) RemoveMode(mode ChannelMode)

RemoveMode removes the given mode from the active set

func (*ChannelModeSet) SetKey

func (c *ChannelModeSet) SetKey(key string)

SetKey sets the channel key

func (*ChannelModeSet) SetLimit

func (c *ChannelModeSet) SetLimit(limit int)

SetLimit sets the channel member limit

func (*ChannelModeSet) String

func (c *ChannelModeSet) String() string

String returns the ChannelModeSet formatted for the MODE queries

type Client

type Client struct {
	*irc.Conn

	Nickname string
	Name     string
	Host     string
	Username string
	RealName string

	Prefix *irc.Prefix

	Server     *Server
	Authorized bool
	Registered bool

	AwayMessage string

	*UserModeSet
	// contains filtered or unexported fields
}

Client represents an IRC Client connection to the server

func (*Client) AddChannel

func (c *Client) AddChannel(channel *Channel)

AddChannel adds a channel to the client's active list

func (*Client) Close

func (c *Client) Close() error

Close cleans up the IRC client and closes the connection

func (*Client) GetChannels

func (c *Client) GetChannels() map[string]*Channel

GetChannels gets a list of channels this client is joined to

func (*Client) GetVisible

func (c *Client) GetVisible() map[string]*Client

GetVisible returns a map of clients visible to this client

func (*Client) MOTD

func (c *Client) MOTD()

MOTD returns the Message of the Day of the server to the client

func (*Client) MakeOper

func (c *Client) MakeOper()

MakeOper makes this client a server operator

func (*Client) Ping

func (c *Client) Ping()

Ping sends an IRC PING command to a client

func (*Client) Pong

func (c *Client) Pong()

Pong sends an IRC PONG command to the client

func (*Client) Quit

func (c *Client) Quit()

Quit sends the IRC Quit command and closes the connection

func (*Client) RemoveChannel

func (c *Client) RemoveChannel(channel *Channel)

RemoveChannel removes a channel to the client's active list

func (*Client) SendMessagetoVisible

func (c *Client) SendMessagetoVisible(m *irc.Message)

SendMessagetoVisible sends a message to all other visible clients

func (*Client) UpdateNick

func (c *Client) UpdateNick(newNick string)

UpdateNick updates the clients nicknamae to a new nickname

func (*Client) Welcome

func (c *Client) Welcome()

Welcome handles initial client connection IRC protocols for a client. Welcome procedure includes IRC WELCOME, Host Info, and MOTD

func (*Client) Who

func (c *Client) Who()

Who rmanages responding to the WHO request for all visible clients of this client

type CommandHandler

type CommandHandler interface {
	ServeIRC(message *irc.Message, client *Client)
}

CommandHandler allows objects implementing this interface to be registered to serve a particular IRC command

func RegisteredHandler

func RegisteredHandler(h CommandHandler) CommandHandler

RegisteredHandler is a CommandHandler middleware to check that a user/client is properly registered

type CommandHandlerFunc

type CommandHandlerFunc func(message *irc.Message, client *Client)

CommandHandlerFunc is a wrapper to to use regular functions as a CommandHandler

func (CommandHandlerFunc) ServeIRC

func (f CommandHandlerFunc) ServeIRC(message *irc.Message, client *Client)

ServeIRC services a given IRC message from the given client

type CommandsMux

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

CommandsMux multiplexes incoming IRC commands

func NewCommandsMux

func NewCommandsMux() CommandsMux

NewCommandsMux creates and returns a new CommandsMux

func (*CommandsMux) Handle

func (c *CommandsMux) Handle(command string, handler CommandHandler)

Handle registers the given CommandHandler for a given IRC command

func (*CommandsMux) HandleFunc

func (c *CommandsMux) HandleFunc(command string, handler CommandHandlerFunc)

HandleFunc registers the given handler function for a given IRC command

func (*CommandsMux) ServeIRC

func (c *CommandsMux) ServeIRC(message *irc.Message, client *Client)

ServeIRC dispatches the incoming IRC command to the appropriate handler

type ModeModifier

type ModeModifier rune

ModeModifier - RFC 1459 Section 4.2.3 and RFC 2812 Section 3.1.5

const (
	ModeModifierAdd    ModeModifier = '+'
	ModeModifierRemove ModeModifier = '-'
)

type OperAuthMethod

type OperAuthMethod interface {
	Authenticate(username string, password string, conn *Client)
}

OperAuthMethod is an interface for authenticating server level operators

type OperAuthMethodFunc

type OperAuthMethodFunc func(username string, password string, conn *Client)

OperAuthMethodFunc is a wrapper so regular functions can be an OperAuthMethod

func (OperAuthMethodFunc) Authenticate

func (o OperAuthMethodFunc) Authenticate(username string, password string, conn *Client)

Authenticate attempts to authenticate a given user

type Server

type Server struct {
	Config ServerConfig

	Prefix      *irc.Prefix
	CommandsMux CommandsMux

	OperAuthMethod
	// contains filtered or unexported fields
}

Server represents an IRC server

func NewServer

func NewServer(config ServerConfig) *Server

NewServer creates and returns a new Server based on the provided config

func (*Server) AddChannel

func (s *Server) AddChannel(channel *Channel)

AddChannel adds an active channel

func (*Server) AddClient

func (s *Server) AddClient(client *Client)

AddClient adds a new Client

func (*Server) AddClientNick

func (s *Server) AddClientNick(client *Client)

AddClientNick adds a client based on its nickname

func (*Server) GetChannel

func (s *Server) GetChannel(channelName string) (*Channel, bool)

GetChannel finds and returns an active channel with a matching name if it exists

func (*Server) GetClient

func (s *Server) GetClient(addr net.Addr) *Client

GetClient finds a client by its address and returns it

func (*Server) GetClientByNick

func (s *Server) GetClientByNick(nick string) (*Client, bool)

GetClientByNick returns a client with the corresponding nickname

func (*Server) RemoveChannel

func (s *Server) RemoveChannel(channel *Channel)

RemoveChannel removes a channel from the active listing

func (*Server) RemoveClient

func (s *Server) RemoveClient(client *Client)

RemoveClient removes a client

func (*Server) RemoveClientNick

func (s *Server) RemoveClientNick(client *Client)

RemoveClientNick removes a client based on its nickname

func (*Server) Start

func (s *Server) Start()

Start the server listening on the configured port

func (*Server) UpdateClientNick

func (s *Server) UpdateClientNick(client *Client, oldNick string)

UpdateClientNick updates the nickname of a client as it is stored by the server

type ServerConfig

type ServerConfig struct {
	Name      string
	MOTD      string
	Version   string
	TLSConfig *tls.Config
	Addr      string

	Password string
}

ServerConfig contains configuration data for seeding a server

type UserMode

type UserMode rune

UserMode - RFC 1459 Section 4.2.3.2 and RFC 2812 Section 3.1.5

const (
	UserModeAway          UserMode = 'a'
	UserModeInvisible     UserMode = 'i'
	UserModeWallOps       UserMode = 'w'
	UserModeRestricted    UserMode = 'r'
	UserModeOperator      UserMode = 'o'
	UserModeLocalOperator UserMode = 'O'
	UserModeServerNotice  UserMode = 's' //obsolete
)

type UserModeSet

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

UserModeSet provides means for storing and checking UserModes

func NewUserModeSet

func NewUserModeSet() *UserModeSet

NewUserModeSet creates and returns a new UserModeSet

func (*UserModeSet) AddMode

func (u *UserModeSet) AddMode(mode UserMode)

AddMode adds a mode to the UserModeSet

func (*UserModeSet) HasMode

func (u *UserModeSet) HasMode(mode UserMode) bool

HasMode detects if a UserMode is contained in the UserModeSet

func (*UserModeSet) RemoveMode

func (u *UserModeSet) RemoveMode(mode UserMode)

RemoveMode removes a mode from the UserModeSet

func (*UserModeSet) String

func (u *UserModeSet) String() string

String formats the UserModeString to be returned for MODE queries

Jump to

Keyboard shortcuts

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