irc-go/ircevent
Shivaram Lingamneni a16267c773 ircevent: avoid uses of time.After
"The underlying Timer is not recovered by the garbage collector until the
timer fires. If efficiency is a concern, use NewTimer instead and call
Timer.Stop if the timer is no longer needed."
2021-05-10 09:14:58 -04:00
..
examples rename to Message and Reader; remove Event 2021-03-10 18:08:37 -05:00
irc.go ircevent: avoid uses of time.After 2021-05-10 09:14:58 -04:00
irc_callback.go fix #52 2021-03-17 01:40:03 -04:00
irc_ctcp.go rename to Message and Reader; remove Event 2021-03-10 18:08:37 -05:00
irc_labeledresponse_test.go rename to Message and Reader; remove Event 2021-03-10 18:08:37 -05:00
irc_parse_test.go rename to Message and Reader; remove Event 2021-03-10 18:08:37 -05:00
irc_sasl.go rename to Message and Reader; remove Event 2021-03-10 18:08:37 -05:00
irc_sasl_test.go rename to Message and Reader; remove Event 2021-03-10 18:08:37 -05:00
irc_struct.go ircevent: add AllowTruncation 2021-04-23 11:14:48 -04:00
irc_test.go rename to Message and Reader; remove Event 2021-03-10 18:08:37 -05:00
LICENSE initial fixes and refactoring 2021-02-19 03:55:06 -05:00
numerics.go refactor callback/protocol handling 2021-03-01 01:03:43 -05:00
README.markdown rename to Message and Reader; remove Event 2021-03-10 18:08:37 -05:00

Description

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

Features

  • Event-based: register callbacks for IRC commands
  • Handles reconnections
  • Supports SASL
  • Supports requesting IRCv3 capabilities

Example

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

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

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

irc.AddCallback("PRIVMSG", func(event ircmsg.Message) {
	// event.Prefix 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 will wait for all callbacks to complete before moving on to the next message. If your callback needs to trigger a long-running task, you should spin off a new goroutine for it.

Commands

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

irc.Connect("irc.someserver.com:6667") //Connect to server
irc.Send(command, params...)
irc.SendWithTags(tags, command, params...)
irc.Join(channel)
irc.Privmsg(target, message)
irc.Privmsgf(target, formatString, params...)