Git Product home page Git Product logo

clojirc's People

Contributors

emiln avatar mikkeren avatar

Stargazers

 avatar

Watchers

 avatar  avatar

clojirc's Issues

Extend API with listener channels

When interacting with IRC, I often want to work in an event-driven manner along the lines of "when one of these events happen, call this function". Furthermore, I don't want to worry about these listeners "consuming" the original event; one event should be able to trigger a multitude of listeners.

A simple example:

(let [messages (events-by-command network :privmsg)
      notices (events-by-command network :notice)]
  (go-loop []
    (when-let [{:keys [trailing]} (alts! messages notices)]
      (println "I just saw:" trailing)
      (recur))))

This should respond to any PRIVMSG or NOTICE and simply print the :trailing part.

The most basic form of the event subscription should be something along the lines of (events-by-predicate network pred?), but I can imagine several useful functions returning channels building upon this:

  • events-on-channel: puts messages onto channel if it happened on the given channel.
  • events-by-command: puts message onto channel if its :command matches. It should take any number of arguments and match if any one of them matches.
  • Etc.

Test commands

The officially supported commands should produce output strings adhering to the spec. A simple solution is to test the examples provided by the specs.

Should accept underscore in hostnames

The command parser for private messages currently will return an error if a message from a nick with an underscore is received. This is a possibility on most networks, and should be rectified.

Simple macro to DRY up the command tests

All command tests in the clojirc.commands-test namespace repeats a bunch of code. I am not usually a big fan of macros for tests, but I think it is warranted here.

(let [channel (async/chan)
      network {:to-network channel}]
  (expect
    "ADMIN tolsun.oulu.fi"
    (do (cmd/admin! network "tolsun.oulu.fi")
      (async/<!! channel))))

could become something like

(command-expect
  "ADMIN tolsun.oulu.fi"
  (cmd/admin! "tolsun.oulu.fi"))

Return a promise instead of the network

For functions like login! it would make sense to return a promise that will be delivered when the server acknowledges having received your message. The current implementation returns the network you fed to the function, which would make sense for a pure function, but much less so for these highly mutating functions. Ideally the promise will be delivered with the server's actual response message.

This will also allow users of the library to await the completion of their commands, which would be great. You'd just deref the returned promise.

Rate-limited channels

It would be nice to be able to specify a rate-limited channel to use as a buffer between your code and the network IO. I can imagine several implementations:

  • A flood-protected channel, which will only send a certain number of messages per second to not ever cause flooding.
  • A "CPM"-based channel, which will delay a message based on how long it would take a human being to type it on the keyboard. A simple strategy could be to count the characters and assume a steady characters-per-minute speed of typing.
  • An "at most k messages per n seconds"-respecting channel, which will never send more than k messages over any period of n seconds, but may reach the k messages as fast as possible.

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.