Adding a ERC Command
Today I was trying to count the users on #emacs channel. Since I couldn’t find an already available command at this great IRC client I added one to do this.
At first I thought it would give me some headaches, but it ended being a pretty easy task.
The first thing is that the users on a channel are recorded at a hash table, called erc-channel-users. So, in order to count the users on a channel I just have to maphash it and do the counting, I did it like this:
"Count the users in current channel"
(interactive)
(let ((n 0))
(maphash '(lambda (nick data) (incf n)) erc-channel-users)
(message (format "%d users on this Channel." n))))
After evaluating this function I just go to a channel and type “M-x rsw/erc-count-users” and a message will appear at the minibuffer. Now, in order to make a command named COUNT out of this function I just have to create a function like:
"Count command just counts how many users are on the channel
showing the results on minibuffer"
(rsw/erc-count-users))
And that’s it, erc internally knows that erc-cmd-COUNT is the the function representing the COUNT command (it builds the name of the function to be called dynamically).
