irckit

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

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

Go to latest
Published: Oct 26, 2018 License: MIT Imports: 21 Imported by: 1

README

mm-go-irckit

(forked from go-irckit)

Minimal IRC server in Go, used for matterircd IRC and Mattermost integration.

This project has been archived and moved to matterircd

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHandshakeFailed = errors.New("handshake failed")
View Source
var ErrUnknownCommand = errors.New("unknown command")

The error returned when an invalid command is issued.

View Source
var LogLevel string

Functions

func CmdAway

func CmdAway(s Server, u *User, msg *irc.Message) error

func CmdInvite

func CmdInvite(s Server, u *User, msg *irc.Message) error

func CmdIson

func CmdIson(s Server, u *User, msg *irc.Message) error

CmdIson is a handler for the /ISON command.

func CmdJoin

func CmdJoin(s Server, u *User, msg *irc.Message) error

CmdJoin is a handler for the /JOIN command.

func CmdKick

func CmdKick(s Server, u *User, msg *irc.Message) error

func CmdList

func CmdList(s Server, u *User, msg *irc.Message) error

CmdList is a handler for the /LIST command.

func CmdLusers

func CmdLusers(s Server, u *User, msg *irc.Message) error

CmdLusers is a handler for the /LUSERS command.

func CmdMode

func CmdMode(s Server, u *User, msg *irc.Message) error

CmdMode is a handler for the /MODE command.

func CmdMotd

func CmdMotd(s Server, u *User, _ *irc.Message) error

CmdMotd is a handler for the /MOTD command.

func CmdNames

func CmdNames(s Server, u *User, msg *irc.Message) error

CmdNames is a handler for the /NAMES command.

func CmdNick

func CmdNick(s Server, u *User, msg *irc.Message) error

CmdNick is a handler for the /NICK command.

func CmdPart

func CmdPart(s Server, u *User, msg *irc.Message) error

CmdPart is a handler for the /PART command.

func CmdPing

func CmdPing(s Server, u *User, msg *irc.Message) error

CmdPing is a handler for the /PING command.

func CmdPrivMsg

func CmdPrivMsg(s Server, u *User, msg *irc.Message) error

CmdPrivMsg is a handler for the /PRIVMSG command.

func CmdQuit

func CmdQuit(s Server, u *User, msg *irc.Message) error

CmdQuit is a handler for the /QUIT command.

func CmdTopic

func CmdTopic(s Server, u *User, msg *irc.Message) error

CmdTopic is a handler for the /TOPIC command.

func CmdWho

func CmdWho(s Server, u *User, msg *irc.Message) error

CmdWho is a handler for the /WHO command.

func CmdWhois

func CmdWhois(s Server, u *User, msg *irc.Message) error

CmdWhois is a handler for the /WHOIS command.

func ID

func ID(s string) string

ID will normalize a name to be used as a unique identifier for comparison.

func IsDebugLevel

func IsDebugLevel() bool

func SetLogLevel

func SetLogLevel(level string)

func SetLogger

func SetLogger(l *logrus.Entry)

Types

type Channel

type Channel interface {
	Prefixer

	// ID is a normalized unique identifier for the channel
	ID() string

	// Created returns the time when the Channel was created.
	Created() time.Time

	// Names returns a sorted slice of Nicks in the channel
	Names() []string

	// Users returns a slice of Users in the channel.
	Users() []*User

	// HasUser returns whether a User is in the channel.
	HasUser(*User) bool

	// Invite prompts the User to join the Channel on behalf of Prefixer.
	Invite(from Prefixer, u *User) error

	// SendNamesResponse sends a User messages indicating the current members of the Channel.
	SendNamesResponse(u *User) error

	// Join introduces the User to the channel (handler for JOIN).
	Join(u *User) error

	// Part removes the User from the channel (handler for PART).
	Part(u *User, text string)

	// Message transmits a message from a User to the channel (handler for PRIVMSG).
	Message(u *User, text string)

	// Service returns the service that set the channel
	Service() string

	// Topic sets the topic of the channel (handler for TOPIC).
	Topic(from Prefixer, text string)

	// GetTopic gets the topic of the channel
	GetTopic() string

	// Unlink will disassociate the Channel from its Server.
	Unlink()

	// Len returns the number of Users in the channel.
	Len() int

	// String returns the name of the channel
	String() string

	// Spoof message
	SpoofMessage(from string, text string)

	// Spoof notice
	SpoofNotice(from string, text string)
}

Channel is a representation of a room in our server

func NewChannel

func NewChannel(server Server, channelId string, name string, service string) Channel

NewChannel returns a Channel implementation for a given Server.

type Command

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

type CommandHandler

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

type Commands

type Commands interface {
	Add(Handler)
	Run(Server, *User, *irc.Message) error
}

func DefaultCommands

func DefaultCommands() Commands

type Conn

type Conn interface {
	Close() error
	Encode(*irc.Message) error
	Decode() (*irc.Message, error)

	// ResolveHost returns the resolved host of the RemoteAddr
	ResolveHost() string
}

Conn abstracts the encoding/decoding and sending/receiving when speaking IRC.

type Handler

type Handler struct {
	// Command is the IRC command that Call handles.
	Command string
	// Handler is a function that takes the server, user who sent the message, and a message to perform some command.
	Call func(s Server, u *User, msg *irc.Message) error
	// MinParams is the minimum number of params required on the message.
	MinParams int
	// LoggedIn is true when authenticated (logged in) against mattermost
	LoggedIn bool
}

Handler is a container for an irc.Message handler.

type MmCfg

type MmCfg struct {
	AllowedServers     []string
	SlackSettings      config.Settings
	MattermostSettings config.Settings
	DefaultServer      string
	DefaultTeam        string
	Insecure           bool
	SkipTLSVerify      bool
	JoinExclude        []string
	JoinInclude        []string
	PartFake           bool
	PrefixMainTeam     bool
}

type MmCredentials

type MmCredentials struct {
	Login  string
	Team   string
	Pass   string
	Server string
}

type MmInfo

type MmInfo struct {
	MmGhostUser bool
	Srv         Server
	Credentials *MmCredentials
	Cfg         *MmCfg
	// contains filtered or unexported fields
}

type Prefixer

type Prefixer interface {
	// Prefix returns a prefix configuration for the origin of the message.
	Prefix() *irc.Prefix
}

type Server

type Server interface {
	Prefixer

	// Name of the server (usually hostname).
	Name() string

	// Motd is the Message of the Day for the server.
	Motd() []string

	// Connect starts the handshake for a new user, blocks until it's completed or failed with an error.
	Connect(*User) error

	// Quit removes the user from all the channels and disconnects.
	Quit(*User, string)

	// HasUser returns an existing User with a given Nick.
	HasUser(string) (*User, bool)

	// RenameUser changes the Nick of a User if the new name is available.
	// Returns whether the rename was was successful.
	RenameUser(*User, string) bool

	// Channel gets or creates a new channel with the given name and Id.
	Channel(string) Channel

	// HasChannel returns an existing Channel with a given name.
	HasChannel(string) (Channel, bool)

	// UnlinkChannel removes the channel from the server's storage if it
	// exists. Once removed, the server is free to create a fresh channel with
	// the same ID. The server is not responsible for evicting members of an
	// unlinked channel.
	UnlinkChannel(Channel)

	Add(u *User) bool
	Handle(u *User)
	Logout(u *User)
	ChannelCount() int
	UserCount() int
	EncodeMessage(u *User, cmd string, params []string, trailing string) error
}

func NewServer

func NewServer(name string) Server

NewServer creates a server.

type ServerConfig

type ServerConfig struct {
	// Name is used as the prefix for the server.
	Name string
	// Version string of the server (default: go-irckit).
	Version string
	// Motd is the message of the day for the server, list of message lines where each line should be max 80 chars.
	Motd []string
	// InviteOnly prevents regular users from joining and making new channels.
	InviteOnly bool
	// MaxNickLen is the maximum length for a NICK value (default: 32)
	MaxNickLen int

	// DiscardEmpty setting will start a goroutine to discard empty channels.
	DiscardEmpty bool
	// NewChannel overrides the constructor for a new Channel in a given Server and Name.
	NewChannel func(s Server, channelId string, name string, service string) Channel
	// Commands is the handler registry to use (default: DefaultCommands())
	Commands Commands
}

ServerConfig produces a Server setup with configuration options.

func (ServerConfig) Server

func (c ServerConfig) Server() Server

type SlackInfo

type SlackInfo struct {
	Token string

	sync.RWMutex
	// contains filtered or unexported fields
}

type User

type User struct {
	Conn

	sync.RWMutex
	Nick        string   // From NICK command
	User        string   // From USER command
	Real        string   // From USER command
	Pass        []string // From PASS command
	Host        string
	Roles       string
	DisplayName string

	MmInfo
	SlackInfo
	// contains filtered or unexported fields
}

func NewUser

func NewUser(c Conn) *User

NewUser creates a *User, wrapping a connection with metadata we need for our server.

func NewUserMM

func NewUserMM(c net.Conn, srv Server, cfg *MmCfg) *User

func NewUserNet

func NewUserNet(c net.Conn) *User

NewUserNet creates a *User from a net.Conn connection.

func (*User) Channels

func (u *User) Channels() []Channel

func (*User) Close

func (u *User) Close() error

func (*User) Decode

func (user *User) Decode() (*irc.Message, error)

Decode will receive and return a decoded message, or an error.

func (*User) Encode

func (user *User) Encode(msgs ...*irc.Message) (err error)

Encode and send each msg until an error occurs, then returns.

func (*User) ID

func (u *User) ID() string

func (*User) MsgSpoofUser

func (u *User) MsgSpoofUser(rcvuser string, msg string)

func (*User) MsgUser

func (u *User) MsgUser(toUser *User, msg string)

func (*User) NumChannels

func (u *User) NumChannels() int

func (*User) Prefix

func (u *User) Prefix() *irc.Prefix

func (*User) String

func (u *User) String() string

func (*User) VisibleTo

func (u *User) VisibleTo() []*User

Jump to

Keyboard shortcuts

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