irc-go/ircevent/README.markdown
2022-04-06 21:42:06 -04:00

1.9 KiB

Description

This is an event-based IRC client library. It is a fork of thoj/go-ircevent.

Features

Example

See examples/simple.go for a working example, but this illustrates the API:

irc := ircevent.Connection{
	Server:      "testnet.ergo.chat:6697",
	UseTLS:      true,
	Nick:        "ircevent-test",
	Debug:       true,
	RequestCaps: []string{"server-time", "message-tags"},
}

irc.AddConnectCallback(func(e ircmsg.Message) { irc.Join("#ircevent-test") })

irc.AddCallback("PRIVMSG", func(event ircmsg.Message) {
	// event.Source is the source;
	// event.Params[0] is the target (the channel or nickname the message was sent to)
	// and event.Params[1] is the message itself
});

err := irc.Connect()
if err != nil {
	log.Fatal(err)
}
irc.Loop()

The read loop executes all callbacks in serial on a single goroutine, respecting the order in which messages are received from the server. All callbacks must complete before the next message can be processed; if your callback needs to trigger a long-running task, you should spin off a new goroutine for it.

Commands

These methods can be used from inside callbacks, or externally:

irc.Send(command, params...)
irc.SendWithTags(tags, command, params...)
irc.Join(channel)
irc.Privmsg(target, message)
irc.Privmsgf(target, formatString, params...)

The ircevent.Connection object is synchronized internally, so these methods can be run from any goroutine without external locking.