emiln / clojirc Goto Github PK
View Code? Open in Web Editor NEWA simple event-based IRC library.
License: Eclipse Public License 1.0
A simple event-based IRC library.
License: Eclipse Public License 1.0
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.The officially supported commands should produce output strings adhering to the spec. A simple solution is to test the examples provided by the specs.
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.
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"))
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.
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 declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.