Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clubot

Sean Bryant
February 01, 2012

 Clubot

Clubot an IRC ZMQ bridge for building bots.

Sean Bryant

February 01, 2012
Tweet

More Decks by Sean Bryant

Other Decks in Programming

Transcript

  1. Clubot? IRC “bot” Broadcasts IRC over a ZMQ pub socket.

    Dealer/Router for bot control - more on this later Speaks JSON for easy consumption language agnostic protocol design Written in Lisp for funzies.
  2. The Talk ZeroMQ - Everything you will need to know

    Clubot Protocol Example App A slightly more involved example When Hubot met Clubot Hacking with Clubot
  3. ZeroMQ From the dudes who created AMQP “Super-socket” library Simple

    API - http://api.zeromq.org/ Only 30 functions! Bindings for a many languages.
  4. Context - Handle to IO thread(s) Sockets - Send /

    Recv using these. Dictates message pattern. Endpoints - Where’s stuff coming / going? Messages - The “stuff” Network Topologies - Patterns playing nicely together ZeroMQ Concepts
  5. Sockets REQ/REP - Typical Request/Reply pattern DEALER/ROUTER (was XREP/XREQ) Multiple

    Req / Reply Pattern. PUB/SUB PUSH/PULL - Pipelining pattern PAIR - Inter-thread communication
  6. More Sockets. Bind - When you’re expecting things to connect

    to you. Connect - When you’re connecting to someone else. As many times as it makes sense. Over TCP/UDP/INPROC at the same time.
  7. Messages Sent and received atomically Multipart Still atomic. You send

    4 parts, you will get 4 parts no more and no less. Pub/Sub subscription filters on first part only.
  8. General purpose Think: IRC Bot Apps Data faucet Pub/Sub Control

    Socket Router/Dealer Why Clubot? Router Pub Sub Dealer Clubot Bot App
  9. Example Usage: require 'clubot' client = Clubot::Client.new client.connect # Make

    a blocking request client.request "type" => "nick" do |data| puts "Got data: #{data}" end
  10. Listening for broadcasts loop do ins, out, err = ZMQ.select([client.sub_sock])

    ins.each do |i| # We use multipart messages to make subscriptions easier. header = i.recv json = i.recv puts "Got Header #{header}" puts "Got json #{json}" end end
  11. Protocol JSON Request Messages Broadcast Messages Every messages has a

    type attribute. Examples: speak, error, topic, channels Broadcasts have filters to subscribe to Examples: :BOOT, :PART “who” “#channel”, etc
  12. Request Messages { “type” : “speak”, “target” : “channel or

    person”, “msg” : “Message to speak”} { “type” : “topic”, “channel” : “#somechan” } Reply: { “type” : “topic”, “channel” : “#somechan”, “topic” : “Channel Topic”}
  13. Broadcast Messages :PRIVMSG :CHATTER “#channel” “Origin Nick” { “type” :

    “privmsg”, “time”: 12312312312314, “target” : “channel or person”, “self” : “botnick”, “from” : “message originator”, “msg” : “Message spoken” } First part Second part
  14. Where do we find this amazing technology?!?!? The protocol is

    small and documented in the README https://github.com/hackinggibsons/clubot Ruby Bindings: https://github.com/sbryant/rb-clubot Node bindings exist. Need to be extracted. Sorry :(
  15. A more involved example. Shaky. A Hubot bridge to Clubot.

    Let’s look over the code together
  16. Hacking ideas Integrate clubot into apps Grab metrics from the

    apps Check app status Resque stats App alerts Automate “shit work”. eg: Deployments Ask for new relic data.