irc

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package irc contains a Bot implementation that works over the IRC protocol

Index

Constants

This section is empty.

Variables

View Source
var ErrNotConnected = errors.New("cannot send a message when not connected")

ErrNotConnected returned from Write when the IRC instance is not connected to a server

View Source
var (
	ErrorIRCAlreadyConnected = errors.New("IRC is already connected")
)

Various Errors

Functions

This section is empty.

Types

type Admin

type Admin struct {
	Mask  string `xml:"mask,attr"`
	Level int    `xml:"level,attr"`
}

Admin holds a mask level pair, for use in commands

type Conf

type Conf struct {
	VerifyCerts bool   `toml:"verify_certs" default:"true" comment:"verify TLS certs when connecting (default: true)"`
	SSL         bool   `toml:"ssl" default:"true" comment:"Use SSL/TLS (really TLS) for connection (default: true)"`
	CmdPfx      string `toml:"command_prefix" default:"~" comment:"Command prefix to respond to (default: '~')"`

	Host          string   `toml:"host"`
	Port          string   `toml:"port"`
	HostPasswd    string   `toml:"host_password"`
	Admins        []Admin  `toml:"admins"`
	AdminChannels []string `toml:"admin_channels"`

	Nick  string `toml:"nick"`
	Ident string `toml:"ident"`
	Gecos string `toml:"gecos"`

	// TODO: Cert based auth? (via SASL)
	Authenticate bool   `toml:"authenticate" comment:"Should we authenticate with the IRC network"`
	SASL         bool   `toml:"sasl" comment:"Should authentication use SASL for negotiation (this is faster and more secure)"` //nolint:lll // Cant be made shorter
	AuthUser     string `toml:"auth_user" comment:"User account to authenticate for"`
	AuthPasswd   string `toml:"auth_passwd" comment:"Password for account authentication"`

	SuppressMOTD bool `toml:"suppress_motd" comment:"Suppress logging of IRC MOTD messages being logged"`
	SuppressPing bool `toml:"suppress_ping" comment:"Suppress logging of internal PING messages being logged"`
}

Conf holds the configuration for an IRC instance

type IRC

type IRC struct {
	*Conf

	Connected     mutexTypes.Bool
	StopRequested mutexTypes.Bool

	RawEvents    *event.Manager
	ParsedEvents *event.Manager
	// contains filtered or unexported fields
}

IRC Represents a connection to an IRC server

func New

func New(conf tomlconf.ConfigHolder, logger *log.Logger) (*IRC, error)

New creates a new IRC instance ready for use

func (*IRC) AdminLevel

func (i *IRC) AdminLevel(source string) int

AdminLevel returns what admin level the given mask has, 0 means no admin access

func (*IRC) Connect

func (i *IRC) Connect() error

Connect connects to IRC and does the required negotiation for registering on the network and any capabilities that have been requested

func (*IRC) Disconnect

func (i *IRC) Disconnect(msg string)

Disconnect disconnects the bot from IRC either with the given message. If no message is passed, it defaults to "Disconnecting"

func (*IRC) HookJoin

func (i *IRC) HookJoin(f func(source, channel string))

HookJoin hooks on users joining a channel

func (*IRC) HookKick

func (i *IRC) HookKick(f func(source, channel, target, message string))

HookKick hooks on a user being kicked from a channel

func (*IRC) HookMessage

func (i *IRC) HookMessage(f func(source, channel, message string, isAction bool))

HookMessage hooks on messages to a channel

func (*IRC) HookNick

func (i *IRC) HookNick(f func(source, newNick string))

HookNick hoops on a user changing their nickname

func (*IRC) HookPart

func (i *IRC) HookPart(f func(source, channel, message string))

HookPart hooks on users leaving a channel

func (*IRC) HookPrivateMessage

func (i *IRC) HookPrivateMessage(f func(source, channel, message string))

HookPrivateMessage hooks on messages to us directly

func (*IRC) HookQuit

func (i *IRC) HookQuit(f func(source, message string))

HookQuit hooks on users disconnecting

func (*IRC) HumanReadableSource

func (i *IRC) HumanReadableSource(source string) string

HumanReadableSource takes an IRC userhost and returns just the nick

func (*IRC) IsCommandPrefix

func (i *IRC) IsCommandPrefix(line string) (string, bool)

IsCommandPrefix returns whether or not the given string contains any dynamic command prefixes

func (*IRC) JoinChannel

func (i *IRC) JoinChannel(name string)

JoinChannel joins the bot to the named channel and adds it to the channel list for later autojoins

func (*IRC) Reload

func (i *IRC) Reload(tree interfaces.Unmarshaler) error

Reload parses and reloads the config on the IRC instance

func (*IRC) Run

func (i *IRC) Run() error

Run connects the bot and blocks until it disconnects

func (*IRC) SendAdminMessage

func (i *IRC) SendAdminMessage(msg string)

SendAdminMessage sends the given message to all AdminChannels defined on the bot

func (*IRC) SendMessage

func (i *IRC) SendMessage(target, message string)

SendMessage sends a message to the given target

func (*IRC) SendNotice

func (i *IRC) SendNotice(target, message string)

SendNotice sends a notice to the given notice

func (*IRC) SendRaw

func (i *IRC) SendRaw(raw string)

SendRaw sends a raw IRC line to the server

func (*IRC) StaticCommandPrefixes

func (i *IRC) StaticCommandPrefixes() []string

StaticCommandPrefixes returns the valid static command prefixes. This means any prefixes that will never change at runtime (for IRC, none)

func (*IRC) Status

func (i *IRC) Status() string

Status returns a human readable status string

func (*IRC) String

func (i *IRC) String() string

type JoinEvent

type JoinEvent struct {
	*RawEvent
	Source  ircutils.UserHost
	Channel string
}

JoinEvent represents an IRC channel JOIN

func NewJoinEvent

func NewJoinEvent(name string, line ircmsg.IrcMessage, tme time.Time) *JoinEvent

NewJoinEvent creates a JoinEvent with the given data

type KickEvent

type KickEvent struct {
	*RawEvent
	Source     ircutils.UserHost
	Channel    string
	KickedNick string
	Message    string
}

KickEvent represents a channel KICK

func NewKickEvent

func NewKickEvent(name string, line ircmsg.IrcMessage, tme time.Time) *KickEvent

NewKickEvent creates a KickEvent from the given data

type LineHandler

type LineHandler func(message *ircmsg.IrcMessage, irc *IRC)

LineHandler is a function that is called on every raw Line

type MessageEvent

type MessageEvent struct {
	*RawEvent
	IsNotice bool
	Source   ircutils.UserHost
	Channel  string
	Message  string
}

MessageEvent represents an IRC authUser message, both NOTICE and PRIVMSGs

func NewMessageEvent

func NewMessageEvent(name string, line ircmsg.IrcMessage, tme time.Time) *MessageEvent

NewMessageEvent creates a MessageEvent with the given data.

type NickEvent

type NickEvent struct {
	*RawEvent
	Source  ircutils.UserHost
	NewNick string
}

NickEvent represents an IRC NICK command

func NewNickEvent

func NewNickEvent(name string, line ircmsg.IrcMessage, tme time.Time) *NickEvent

NewNickEvent creates a NickEvent from the given data

type PartEvent

type PartEvent struct {
	*JoinEvent
	Message string
}

PartEvent represents an IRC channel PART

func NewPartEvent

func NewPartEvent(name string, line ircmsg.IrcMessage, tme time.Time) *PartEvent

NewPartEvent creates a PartEvent with the given data

type QuitEvent

type QuitEvent struct {
	*RawEvent
	Source  ircutils.UserHost
	Message string
}

QuitEvent represents an IRC QUIT

func NewQuitEvent

func NewQuitEvent(name string, line ircmsg.IrcMessage, tme time.Time) *QuitEvent

NewQuitEvent creates a QuitEvent from the given data

type RawEvent

type RawEvent struct {
	event.BaseEvent
	Line ircmsg.IrcMessage
	Time time.Time
}

RawEvent represents an incoming raw IRC Line that needs to be handled

func NewRawEvent

func NewRawEvent(name string, line ircmsg.IrcMessage, tme time.Time) *RawEvent

NewRawEvent creates a RawEvent with the given name and Line

func (*RawEvent) CommandIs

func (r *RawEvent) CommandIs(names ...string) bool

CommandIs returns whether or not the command on the Line contained in the RawEvent matches any of the passed command names

type Transformer

type Transformer struct{}

Transformer is a dummy struct that holds methods for IRCs implementation of format/transformer's transformer interface

func (Transformer) MakeIntermediate

func (Transformer) MakeIntermediate(in string) string

MakeIntermediate implements Transformer.MakeIntermediate

func (Transformer) Transform

func (Transformer) Transform(in string) string

Transform implements Transformer.Transform, colours are converted via a palette to the 15 IRC colours

Directories

Path Synopsis
Package ctcp implements helpers for IRC Client-To-Client messages
Package ctcp implements helpers for IRC Client-To-Client messages

Jump to

Keyboard shortcuts

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