Giter Site home page Giter Site logo

irc's Introduction

IRC

Simple irc client.

See examples for full usage.

Connecting

To connect to an irc server, instantiate a Client, passing the irc server address as an argument, and call `Connect.

  client := irc.NewClient("localhost:6667")

  if err := client.Connect(); err != nil {
    log.Fatal(err)
  }
  defer client.Close()

Commands

To send a command, call the CMD function on a connected `Client.

  if err := client.Cmd(irc.NICK, "my_nickname"); err != nil {
    log.Fatal(err)
  }

Handlers

There are two types of handler:

  • Reply - handles a response to a command sent by the client.
  • Command - handles a command sent from the server.

To register a handler, call the respective handler registration function.

  client.HandleCommand(irc.PING, func(e *irc.Event) {
    client.Cmd(irc.PONG, "I'm here!")
  })

  client.HandleReply(irc.RPL_WELCOME, func(e *irc.Event) {
    client.Cmd(irc.JOIN, "#channel")
  })

Note in order for handlers to be called, the client must be writing server output. See Writing.

Writing

To write output from the server, call the WriteTo function passing an io.Writer as an argument.

If nil is passed as an argument the server output will be read but not written to an output destination.

  if err := client.WriteTo(os.Stdout); err != nil {
    log.Fatal(err)
  }

Reading

To read input to send to the server, call the ReadFrom function passing an io.Reader as an argument.

  if err := client.ReadFrom(os.Stdin); err != nil {
    log.Fatal(err)
  }

Constants

All irc response codes and commands, as defined in RFC 2812, are exposed by this package.

irc's People

Contributors

eggsbenjamin avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.