irc

package
v4.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: BSD-1-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package irc defines some utility types and functions for an IRC bot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Name string // Channel's name.
	Key  string // Authentication key for protected channel.
}

Channel defines a single IRC channel.

func (*Channel) IsLocal

func (c *Channel) IsLocal() bool

Returns true if the channel is local to the current server. This is the case when its name starts with '&'.

type Profile

type Profile interface {
	// Root defines the root directory with the bot's configuration data.
	Root() string

	// Channels yields all channels the bot should join on startup.
	Channels() []Channel

	// Address defines the host and port of the server/network to connect to.
	Address() string

	// Nickname yields the bot's nickname.
	Nickname() string

	// SetNickname sets the bot's nickname. This is generally only called
	// when the bot logs in and finds its name alredy in use. If the nick
	// can not be regained, this function is used to alter it to something
	// which is still available.
	SetNickname(string)

	// NickservPassword defines the bot's nickserv password. This will be
	// used to register the bot when it logs in. It is only relevant if the
	// bot has a registered nickname and nickserv exists on the server.
	NickservPassword() string

	// SetNickservPassword sets the bot's nickserv password. This is be
	// used to register the bot when it logs in. It is only relevant if the
	// bot has a registered nickname and nickserv exists on the server.
	SetNickservPassword(string)

	// CommandPrefix this is the prefix used for all bot commands. Whenever
	// the bot reads incoming PRIVMSG data, it looks for this prefix to
	// determine if a command call was issued or not.
	CommandPrefix() string

	// Save saves the profile to disk.
	Save() error

	// Load loads the profile from disk.
	Load() error

	// IsWhitelisted returns true if the given hostmask is in the whitelist.
	// This means the user to whom it belongs is allowed to execute restricted
	// commands. This performs a case-insensitive comparison.
	IsWhitelisted(string) bool

	// Whitelist returns a copy of the current whitelist.
	Whitelist() []string

	// WhitelistAdd adds the given hostmask to the whitelist,
	// provided it does not already exist.
	WhitelistAdd(string)

	// WhitelistRemove removes the given hostmask from the whitelist,
	// provided it exists.
	WhitelistRemove(string)

	// IsMe returns true if the given name equals the bot's nickname.
	// This is used in request handlers to quickly check if a request
	// is targeted specifically at this bot or not.
	IsMe(string) bool

	// ForkArgs returns a list of command line arguments which should be
	// passed to a forked child process.
	ForkArgs() []string
}

Profile defines bot configuration data.

func NewProfile

func NewProfile(root string) Profile

NewProfile creates a new profile for the given root directory.

type Request

type Request struct {
	SenderName string // Nick name of sender.
	SenderMask string // Hostmask of sender.
	Type       string // Type of message: "001", "PRIVMSG", "PING", etc.
	Target     string // Receiver of reply.
	Data       string // Message content.
}

Request defines a single incoming message from a server.

func (*Request) Fields

func (r *Request) Fields(n int) []string

Fields returns the message payload, but skips the first n words. The result is returned as a slice of individual words.

func (*Request) FromChannel

func (r *Request) FromChannel() bool

FromChannel returns true if this request came from a channel context instead of a user or service.

func (*Request) IsPrivMsg

func (r *Request) IsPrivMsg() bool

IsPrivMsg returns true if the request comes from either a user or a channel, as a PRIVMSG. This has its own method, because it is a commonly used filter.

func (*Request) String

func (r *Request) String() string

String returns a string representation of the request data.

type RequestFunc

type RequestFunc func(ResponseWriter, *Request)

RequestFunc defines a handler for a request binding.

type ResponseWriter

type ResponseWriter interface {
	io.WriteCloser
}

ResponseWriter repersents a network stream, used to write response data to.

var Connection ResponseWriter

Connection is the stream to write to.

Directories

Path Synopsis
Package cmd allows the definition of command handlers to be called by users from either a channel or a private message.
Package cmd allows the definition of command handlers to be called by users from either a channel or a private message.
Package proto defines convenience functions for IRC protocol requests.
Package proto defines convenience functions for IRC protocol requests.

Jump to

Keyboard shortcuts

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