rcircFacebook

Using Facebook chat is easy using BitlBee. Just add a jabber account for nick@chat.facebook.com!

The only drawback is that all your friends will have silly names like u123456. The following code will send an info request whenever a user with such a silly name joins the &bitlbee channel. The response to this request will be used to issue a rename command based on the user’s real name.

I guess you could issue a save command every now and then to save the new names.

This will fail if the real names contain invalid characters such as points or commas. Feel free to improve the code. Just replace it with something better.

(defvar rcirc-facebook-name-from nil)
(defvar rcirc-facebook-name-to nil)

(defadvice rcirc-handler-PRIVMSG (after rcirc-handler-facebook-1 activate)
  "If &bitlbee mentions a user called u<number>,
this advice sets up a listener to get his real name and rename the user."
  ;; (when (string= sender "root")
  ;;  (message "%s %s %s" sender (nth 0 args) (nth 1 args)))
  (when (= 2 (length args))
    (cond ((and (string= "root" sender)
		(or (string= "&bitlbee" (nth 0 args))
		    (string= rcirc-nick (nth 0 args)))
		(string-match "\\(u[0-9]+\\)@chat.facebook.com"
			      (nth 1 args)))
	   (setq rcirc-facebook-name-from (match-string 1 (nth 1 args))))
	  ((and (string= "root" sender)
		(or (string= "&bitlbee" (nth 0 args))
		    (string= rcirc-nick (nth 0 args)))
		(string-match "^Name: \\(.*\\)"
			      (nth 1 args)))
	   (setq rcirc-facebook-name-to
		 (mapconcat 'identity
			    (split-string (match-string 1 (nth 1 args)))
			    ""))
	   (when rcirc-facebook-name-from
	     (rcirc-send-message process sender
				 (format "rename %s %s"
					 rcirc-facebook-name-from
					 rcirc-facebook-name-to))))
	  ((and (string= "root" sender)
		(string= rcirc-nick (nth 0 args))
		(string-match "^Nick `\\(.*\\)' already exists$"
			      (nth 1 args)))
	   (setq to (concat (match-string 1 (nth 1 args)) "_"))
	   (when rcirc-facebook-name-from
	     (rcirc-send-message process sender
				 (format "rename %s %s"
					 rcirc-facebook-name-from
					 to)))))))

(defadvice rcirc-handler-JOIN (after rcirc-handler-facebook-2 activate)
  "If a user named u<number> joins channel &bitlbee,
call info on it. This will automatically rename him.
See advice on `rcirc-handler-PRIVMSG'."
  (when (and (string-match "^u[0-9]+$" sender)
	     (string= (car args) "&bitlbee"))
    (rcirc-send-message process "root"
			(format "info %s" sender))))