irc-client_test.go 968 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package ircclient_test
  2. import (
  3. "fmt"
  4. ircclient "git.red-green.com/RedGreen/irc-client"
  5. )
  6. func ExampleIRCClient_Connect() {
  7. var FromIRC chan ircclient.IRCMsg = make(chan ircclient.IRCMsg)
  8. var config ircclient.IRCConfig = ircclient.IRCConfig{Port: 6667,
  9. Hostname: "irc.libera.chat",
  10. Nick: "go-bot-test",
  11. Username: "gobot",
  12. Realname: "Bot Testing",
  13. AutoJoin: []string{"##bugz"},
  14. }
  15. var irc ircclient.IRCClient = ircclient.IRCClient{IRCConfig: config,
  16. ReadChannel: FromIRC}
  17. irc.Connect()
  18. defer irc.Close()
  19. var Msg ircclient.IRCMsg
  20. for Msg = range irc.ReadChannel {
  21. // View all the commands:
  22. // fmt.Printf("%#v\n", Msg)
  23. switch Msg.Cmd {
  24. case "EndMOTD":
  25. // Ok! we're connected.
  26. fmt.Println("Connected")
  27. break
  28. case "333":
  29. // Joined channel, say something and quit.
  30. irc.Msg("##bugz", "Hello!")
  31. irc.WriteTo("", "QUIT")
  32. break
  33. case "PRIVMSG":
  34. break
  35. }
  36. }
  37. // Uncomment to test connection // Output: Connected
  38. }