ircclient

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

An IRC-Client library.

Index

Examples

Constants

This section is empty.

Variables

get client version information from runtime package.

Functions

func Bold

func Bold(input string) string

Set IRC bold

func Color

func Color(color int) string

Color set IRC color

We always output the color code as 2 digits.

func ColorString

func ColorString(color int, input string) string

Format a string with the given color code, and reset.

func GetModuleVersion

func GetModuleVersion() string

func GetModules

func GetModules() map[string]string

Get modules information

Return map of module name and version.

func GetVersion

func GetVersion() (goversion string, gitcommit string, arch string, goos string)

Get Go version, arch, and OS. Get git commit hash.

func IRCNick

func IRCNick(from string) string

IRCNick return just the NICK from :Nick!name@host

func Italics

func Italics(input string) string

Set IRC Italics

func Match

func Match(name1 string, name2 string) bool

Check to see if nicks or channels match according to IRC rules.

func Monospace

func Monospace(input string) string

Set IRC monospace

func NameLower

func NameLower(name string) string

Convert nick to lowercase following IRC capitalization rules.

func RandomNick

func RandomNick(nick string) string

Generate random nick to change to (upon collision/433)

func Reset

func Reset() string

Reset IRC reset color and formatting

func Reverse

func Reverse(input string) string

Set IRC reverse

func ShowVersion

func ShowVersion()

Get build version from BuildInfo

func StrInArray

func StrInArray(strings []string, str string) bool

Is string in slice?

func Strike

func Strike(input string) string

Set IRC strike through

func Stripper

func Stripper(input string) string

Stripper removes IRC color and formatting codes.

func Underline

func Underline(input string) string

Set IRC underline

Types

type FloodTrack

type FloodTrack struct {
	Pos     int // Index to store next item
	Size    int // Max number of Track items
	Timeout int // Timeout in seconds
	Track   []time.Time
}

Track when the client last sent something

func (*FloodTrack) Expire

func (F *FloodTrack) Expire()

Expire Track records older then timeout

func (*FloodTrack) Full

func (F *FloodTrack) Full() bool

Are we full?

Expire records before checking.

func (*FloodTrack) Init

func (F *FloodTrack) Init(size int, timeout int)

Initialize flood tracking

func (*FloodTrack) Save

func (F *FloodTrack) Save()

Save Now() into the tracker.

type IRCClient

type IRCClient struct {
	IRCConfig
	MyNick       string            // Client's current nick
	OnExit       func()            // Called on exit
	Socket       net.Conn          // Connection to IRCD
	Reader       *bufio.Reader     // For reading a line at a time from the IRCD
	ReadChannel  chan IRCMsg       // Channel of parsed IRC Messages
	ReadEvents   []string          //
	WriteChannel chan IRCWrite     // Channel for writing messages to IRCD
	DelChannel   chan string       // For deleting channel or nicks that are missing.
	Registered   bool              // Registered with services?
	ISupport     map[string]string // IRCD capabilities (005)

	Mutex sync.Mutex // Guards MyNick
	// contains filtered or unexported fields
}

func (*IRCClient) Action

func (Config *IRCClient) Action(to string, message string)

Action: Send PRIVMSG CTCP ACTION, uses WriteTo to throttle.

func (*IRCClient) Close

func (Config *IRCClient) Close()

Shutdown the client.

func (*IRCClient) Connect

func (Config *IRCClient) Connect() bool

Connect to IRCD and authenticate.

This starts the ReaderRoutine to handle processing the lines from the IRCD. You must setup ReadChannel if you want to process any messages.

Example
package main

import (
	"fmt"

	ircclient "git.red-green.com/RedGreen/irc-client"
)

func main() {
	var FromIRC chan ircclient.IRCMsg = make(chan ircclient.IRCMsg)
	var config ircclient.IRCConfig = ircclient.IRCConfig{Port: 6667,
		Hostname: "irc.libera.chat",
		Nick:     "go-bot-test",
		Username: "gobot",
		Realname: "Bot Testing",
		AutoJoin: []string{"##bugz"},
	}
	var irc ircclient.IRCClient = ircclient.IRCClient{IRCConfig: config,
		ReadChannel: FromIRC}

	irc.Connect()
	defer irc.Close()

	var Msg ircclient.IRCMsg
	for Msg = range irc.ReadChannel {
		// View all the commands:
		// fmt.Printf("%#v\n", Msg)
		switch Msg.Cmd {
		case "EndMOTD":
			// Ok! we're connected.
			fmt.Println("Connected")
			break
		case "333":
			// Joined channel, say something and quit.
			irc.Msg("##bugz", "Hello!")
			irc.WriteTo("", "QUIT")
			break
		case "PRIVMSG":
			break
		}
	}
	
Output:

func (*IRCClient) GetNick

func (Config *IRCClient) GetNick() string

Get the current nick of the client

func (*IRCClient) IsAuto

func (Config *IRCClient) IsAuto(channel string) bool

Is channel in the AutoJoin list?

func (*IRCClient) Msg

func (Config *IRCClient) Msg(to string, message string)

Msg: Send PRIVMSG, uses WriteTo to throttle.

func (*IRCClient) Notice

func (Config *IRCClient) Notice(to string, message string)

Notice: Send NOTICE, uses WriteTo to throttle.

func (*IRCClient) PriorityWrite

func (Config *IRCClient) PriorityWrite(output string)

PriorityWrite: Send output command to server immediately.

This is never throttled.

func (*IRCClient) ReaderRoutine

func (Config *IRCClient) ReaderRoutine()

Goroutine reader routine

This reads a line at a time, delimited by '\n'.
Auto-replies to server PING.
Converts CTCP & ACTION messages to type CTCP/ACTION.
Automatically answers /VERSION and /TIME.
Handles SASL authentication.
Rejoins AutoJoin channels kicked from.

func (*IRCClient) SetNick

func (Config *IRCClient) SetNick(nick string)

Sets the current nick of the client

func (*IRCClient) WriteTo

func (Config *IRCClient) WriteTo(to string, output string)

WriteTo: Send throttled output command using "to" to throttle.

func (*IRCClient) WriterRoutine

func (Config *IRCClient) WriterRoutine()

WriterRoutine a goroutine that handles flood control

type IRCConfig

type IRCConfig struct {
	Port           int      `json:"Port"`           // IRC Connection port
	Hostname       string   `json:"Hostname"`       // Hostname for connection
	UseTLS         bool     `json:"UseTLS"`         // Use TLS Secure connection
	UseSASL        bool     `json:"UseSASL"`        // Authenticate via SASL
	Insecure       bool     `json:"Insecure"`       // Allow self-signed certificates
	Nick           string   `json:"Nick"`           // Client's nick
	Username       string   `json:"Username"`       // Client's username
	Realname       string   `json:"Realname"`       // Client's realname
	Password       string   `json:"Password"`       // Password for nickserv
	ServerPassword string   `json:"ServerPassword"` // Password for server
	AutoJoin       []string `json:"AutoJoin"`       // Channels to auto-join
	RejoinDelay    int      `json:"RejoinDelay"`    // ms to rejoin
	Version        string   `json:"Version"`        // Version displayed
	Flood_Num      int      `json:"FloodNum"`       // Number of lines sent before considered a flood
	Flood_Time     int      `json:"FloodTime"`      // Number of Seconds to track previous messages
	Flood_Delay    int      `json:"FloodDelay"`     // Delay between sending when flood protection on (Milliseconds)
	Debug_Output   bool     `json:"Debug"`          // Enable debug output
}

Configuration

type IRCMsg

type IRCMsg struct {
	MsgParts []string // Message parts
	From     string   // Message From
	To       string   // Message To
	Cmd      string   // Command
	Msg      string   // Message
}

IRC Message

func IRCParse

func IRCParse(line string) IRCMsg

IRCParse Parse an IRC line into the IRCMsg struct.

type IRCWrite

type IRCWrite struct {
	To     string // Write To
	Output string // Output
}

Sent to writer

The To part allows the writer to throttle messages to a specific target.
When throttled, it delays and alternates between the targets.

type ThrottleBuffer

type ThrottleBuffer struct {
	Life_sucks bool // Is throttle active?
	// contains filtered or unexported fields
}

func (*ThrottleBuffer) Init

func (T *ThrottleBuffer) Init()

Jump to

Keyboard shortcuts

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