Skip to content

osm/irc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

20d6074 · Jun 2, 2023

History

16 Commits
Jan 5, 2018
Jan 5, 2018
Jun 2, 2023
Jan 5, 2018
Jan 8, 2021
Jan 8, 2021
Jun 2, 2023
Jan 6, 2021
Jan 6, 2021
Jan 5, 2018
Jan 5, 2018
Jan 5, 2018
Jun 2, 2023

Repository files navigation

About

Event driven IRC library for go

Features

  • Easy to use
  • Async event handlers
  • Nick reclaim
  • Reconnect on disconnect

Handlers

An event handler receives a pointer to the message that was sent to the client from the server. See godoc github.com/osm/irc Message for a complete description of the Message struct.

Example:

c.Handle("PRIVMSG", func(m *Message) {
	fmt.Println(m.Raw)
})

Complete example

package main

import (
	"fmt"
	"log"
	"os"
	"sync"

	"github.com/osm/irc"
)

func main() {
	// Create a new IRC client
	c := irc.NewClient(
		irc.WithAddr("localhost:6667"),
		irc.WithNick("foo"),
		irc.WithUser("bar"),
		irc.WithRealName("foo bar"),
		irc.WithChannel("#dev"),
		irc.WithDebug(),
		irc.WithLogger(log.New(os.Stdout, "IRC: ", log.LstdFlags)))

	// Setup an event handler for PRIVMSG
	c.Handle("PRIVMSG", func(m *irc.Message) {
		if m.Params == "#dev :hello" {
			c.Privmsg(m.ParamsArray[0], "world")
		}
	})

	// Create a wait group
	var wg sync.WaitGroup
	wg.Add(1)

	// Connect is blocking, so we need to run it in a goroutine
	go func() {
		if err := c.Connect(); err != nil {
			fmt.Println(err)
		}

		wg.Done()
	}()

	// Wait for the client to end
	wg.Wait()
}

Docs

godoc github.com/osm/irc

About

Event driven IRC library for go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages