irc-go/ircevent
kayos@tcp.direct fd5da7ee1a
fix go module path
2023-10-14 23:58:14 -07:00
..
examples fix go module path 2023-10-14 23:58:14 -07:00
LICENSE initial fixes and refactoring 2021-02-19 03:55:06 -05:00
README.markdown update ircevent readme 2022-04-06 21:42:06 -04:00
irc.go fix go module path 2023-10-14 23:58:14 -07:00
irc_callback.go fix go module path 2023-10-14 23:58:14 -07:00
irc_ctcp.go fix go module path 2023-10-14 23:58:14 -07:00
irc_labeledresponse_test.go fix go module path 2023-10-14 23:58:14 -07:00
irc_parse_test.go rename to Message and Reader; remove Event 2021-03-10 18:08:37 -05:00
irc_sasl.go fix go module path 2023-10-14 23:58:14 -07:00
irc_sasl_test.go fix go module path 2023-10-14 23:58:14 -07:00
irc_struct.go fix go module path 2023-10-14 23:58:14 -07:00
irc_test.go fix go module path 2023-10-14 23:58:14 -07:00
numerics.go add additional numeric definitions 2022-05-23 22:01:39 -04:00

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.