Showing posts with label erc. Show all posts
Showing posts with label erc. Show all posts

2012-03-16

social networking with bitlbee and erc

Instant messaging (IM) is one of the great time sinks of our age. Emacs-users, social butterflies as we are, of course want to take part in that -- preferrably from the comfort of our own environment.

There are various ways to use services like MS Live Messenger, Facebook Chat, GTalk, Yahoo etc. from within emacs – the one I use is called BitlBee. BitlBee is a program that presents all the various forms of IM as IRC-channels. In other words, while BitlBee knows all the details about communicating with these networks, all you need is an IRC-client to connect to BitlBee. This IRC-client does not have to be Emacs-based - any client can be used - but I am using ERC. Note, the below assumes you are somewhat familiar with it.

So, let's see how we can set up BitlBee on our system; there are public BitlBee-servers available online, but in the case of IM, I wouldn't necessarily want to trust them with my account data… so I'm using my own.

Setting up Bitlbee

So, how can we set this up? First, install BitlBee – many distributions have ready-made packages, otherwise you can build from source. In the examples below, I am assuming you are using Bitlbee version 3 or higher; if you use a different version, the details will vary a bit.

You can either run Bitlbee as a system-wide daemon, or just use it on your own. I am doing the former (for the latter, bitlbee.el is useful).

To connect ERC to the Bitlbee daemon, you can use something like the following:

(defun i-wanna-be-social ()
  "Connect to IM networks using bitlbee."
  (interactive)
  (erc :server "localhost" :port 6667 :nick "user"))

I'm sure you can come up with a better nick than user… Anyhow, with this function in your ~/.emacs, we can connect to bitlbee with:

M-x i-wanna-be-social RET

This should connect us to BitlBee; when all goes well, this will look something like this:

*** You have joined channel &bitlbee
*** mindcrime has changed mode for &bitlbee to +t
*** Users on &bitlbee: @user @root
*** Topic for &bitlbee: Welcome to the control channel. Type help for help
    information.
<root> Welcome to the BitlBee gateway!
<root>
<root> If you've never used BitlBee before, please do read the help
  information using the help command. Lots of FAQs are answered there.
<root> If you already have an account on this server, just use the identify
  command to identify yourself.
<root> The nick is (probably) not registered
*** &bitlbee modes: +t
<ERC>

Now, this first time, you will need to register yourself (this is only needed once); use the same nick (user in the example) that you used before:

<user> register user secretpassword
<root> Account successfully created

We're registered! This means, that bitlbee knows about you, and will save your settings.

Re-entering bitlbee

Just to complete the bitlbee-connecting part: the next time you want to use bitlbee, use i-wanna-be-social as before. However, now you need to identify yourself (rather than register):

<user> identify user secretpassword
<root> Password accepted, settings and accounts loaded

This can be automated by adding something like the following to your config:

(defun bitlbee-identify ()
  (when (and (string= "localhost" erc-session-server)
          (string= "&bitlbee" (buffer-name)))
    (erc-message "PRIVMSG" (format "%s identify user secretpassword"
                             (erc-default-target)
                             djcb-bitlbee-password))))

(add-hook 'erc-join-hook 'bitlbee-identify)

Modify user and secretpassword as desired. If you don't want write out your passwords in your emacs config files, take a look at keeping your secrets secret.

Adding accounts

Now, let's add some IM-accounts (just some examples here; also see Bitlbee Quickstart. Note, add any point during this, you can see your accounts with the command:

<user> account list

and using the numbers (or the accounts 'tag') you can switch an account on (and off):

<user> account 0 on

There are many other commands – use help command the consult the built-in documentation.

Connecting to IM networks

To connect to IM networks, you have to add the accounts to BitlBee. It will save them, so you only need to do that once. Let's do it - in each case, replace user and password with whatever you use for those.

You can see your combined logged-in buddy list using M-x erc-channel-names (or C-c C-n). Or use the blist command (see help blist).

After adding an account, it's a good idea to issue the save command, to ensure that bitlbee saves it.

Jabber

<user> account add jabber foobar@jabber.org mypassword
<root> Account successfully added with tag jabber
<user> account jabber on
<root> jabber - Logging in: Connecting
<root> jabber - Logging in: Connected to server, logging in
<root> jabber - Logging in: Converting stream to TLS
<root> jabber - Logging in: Connected to server, logging in
<root> jabber - Logging in: Authentication finished
<root> jabber - Logging in: Authenticated, requesting buddy list
<root> jabber - Logging in: Logged in

(and of course, you can use other servers beside jabber.org)

GoogleTalk

GoogleTalk (gtalk) is implemented using XMPP (jabber), and it's recommended to use oauth for authentication. Note, the foobar below is just a placeholder (for a password); bitlbee wants us to put something there, but since we'll be using oauth, it's not actually used.

<user> account add jabber myaccount@gmail.com foobar
<root> Account successfully added with tag gtalk
<user> account gtalk set oauth on
<root> oauth = `on'
<user> account gtalk set nick_source full_name
<root> nick_source = `full_name'
<user> account gtalk on
<root> gtalk - Logging in: Starting OAuth authentication

Now, a second window will open with a URL:

<jabber_oauth> Open this URL in your browser to authenticate:
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.\
com/auth/googletalk&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_i\
d=78312399893489.apps.googleusercontent.com

<jabber_oauth> Respond to this message with the returned authorization
token.

Follow this URL in your browser, and it will take you to some Google page for authentication. When that is completed, you will receive some string cookie, which you paste back into the newly opened window.

<user> 4/sIns904fdlkP5nudjCF4mBHF7Go_-E0g8
*** jabber_oauth is AWAY: Offline

Et voilĂ ! We're connected to Gtalk (don't worry about the Offline-warning).

Facebook

Apart from being a social website, Facebook can also be used for IM. You can do this through the website, or you can use its jabber interface. It works very similar to gtalk; only important thing is that you get yourself a Facebook username:

<user> account add jabber myusername0@chat.facebook.com
<root> Account successfully added with tag fb
<root> You can now use the /OPER command to enter the password
<root> Alternatively, enable OAuth if the account supports it: account
  fb set oauth on
<user> account fb set oauth on
<root> oauth = `on'
<user> account gtalk set nick_source full_name
<root> nick_source = `full_name'
<user> account fb on
<root> fb - Logging in: Starting OAuth authentication

Then, go through the oath-authentication steps (see the discussion about adding Gtalk accounts above).

Once authenticated, you'll get something like this:

<root> fb - Logging in: Requesting OAuth access token
<root> fb - Logging in: Connecting
<root> fb - Logging in: Connected to server, logging in
<root> fb - Logging in: Converting stream to TLS
<root> fb - Logging in: Connected to server, logging in
<root> fb - Logging in: Authentication finished
<root> fb - Logging in: Server claims your JID is
  `-748234518@chat.facebook.com' instead of
  `myusername0@chat.facebook.com'. This mismatch may cause problems with
  groupchats and possibly other things.
<root> fb - Logging in: Authenticated, requesting buddy list
<root> fb - Logging in: Logged in

It's to now act upon the warning, so, we log out, change the user name and long back in:

<user> account fb off
<root> fb - Signing off..
<user> account fb set username -748234518@chat.facebook.com
<root> username = `-748234518@chat.facebook.com'
<user> account fb on

MSN / Live Messenger

MSN uses its own protocol (although apparently they're also supporting XMPP ("jabber") now). Suppose you have an account there, user partygirl89@hotmail.com with password iamcute:

<user> account add msn partygirl89@hotmail.com iamcute
<root> Account successfully added
<user> account msn on
<root> msn - Logging in: Connecting
<root> msn - Logging in: Connected to server, waiting for reply
<root> msn - Logging in: Transferring to other server
<root> msn - Logging in: Connected to server, waiting for reply
<root> msn - Logging in: Authenticated, getting buddy list
<root> msn - Login error: Error reported by MSN server: Invalid
       (non-existent) handle                                      [12:17]
<root> msn - Logging in: Logged in

The 'Error reported' does not seem to matter.

Other accounts

It's similarly easy to setup Twitter-accounts and Identi.ca-accounts; I've stopped using those though, as it turned out to be a little too easy for some typing in the wrong window to end op as a tweet… The risk is less with twittering-mode and identica-mode.

For ICQ/Yahoo/AIM see below – replace the username/password with your own.

  • ICQ
    <user> account add oscar ICQ-ID PASSWORD login.icq.com
    <root> ...
    
  • AIM
    <user> account add oscar AIM-NICK PASSWORD login.aol.oscar.com
    <root> ...
    
  • Yahoo!
    <user> account add yahoo YAHOO-NICK PASSWORD
    <root> ...
    

    And I'm not even talking about combining bitlbee and Skype – yes, that is possible, too.

Chatting

Now, chatting is easy, following the normal ERC conventions (and settings). When people talk to you, a window opens (or a frame – see erc-auto-query. And you can initiate conversations with people by using /msg nick, with nick of course being the nickname of the person you want to talk to.

ERC/Bitlbee also work together nicely with Sauron, the emacs event tracker.

Have fun! I have only scratched the surface here - you now have the full arsenal of Elisp and ERC power available for your chatting.

2011-12-22

sauron: keeping an eye on what's going on

I'm a fairly busy person, and need to keep track of a lot of things. That includes following a bunch of internal IRC channels, attending meetings, meeting deadlines and so on. But I don't want to stare at my org-mode calendar, or flip through ERC buffers all the time.

Instead, I'd like to have one little emacs frame (window) that gathers these ('events'), and transfers me to wherever the event came from when I click it - some IRC-channel in ERC, my org-calendar etc. and other inputs. Note, using Bitlbee, you can include Facebook-contacts, GoogleTalk-buddies and Twitter-tweets, … in ERC - so, you can track just about anything.

In addition, with so many inputs, I'd also like the possibility to filter out unwanted events, and generate various light/sound effects and fireworks, proportional to the priority of the event.

For all this, I wrote a little emacs-tool called Sauron that does just that. M-x sauron-start pops up a frame that receives events, and M-x sauron-stop hides it and stops listening. It works with ERC, org, and listens for D-Bus messages; so it's pretty easy to get events from all over the place.

It's a bit of a balancing act to get all the important information while not being swamped in noise, but Sauron allows you to fine-tune it to whatever works the best for you. I've tried to have sane defaults though, so things should mostly work without too much configuration - but if you need the power, it's there. I also added some convenience functions to make it easy to get sounds and other special effects.

So - it's brand new, it is of seems-to-work-for-me-quality, and I'd like to invite others to try it out, hack it, give feedback, add new back-ends and so on – what better Christmas present to ask for!

There's documentation, examples etc. to be found in Sauron's github repository.

2011-02-02

extending ERC with your own commands

ERC is the leading Emacs-based IRC-client; I already discussed ERC before. I have been using ERC a lot in recent times, as it's an essential way to communicate at work with team members in remote locations. There are other IRC-clients – most people around me seem to use either irssi or xchat, but these don't integrate so well with my emacs-based workflow, the easy with which it can be extended to do exactly what I want; in this although they have their own strenghts. One of the great strengths of ERC is article I give some examples.

Apart from chatting, you can send commands (long list) to the IRC-server, for example to request information about other users, change your 'nick', leave the channel, and so on. As in most IRC-clients, you can send these commands with ERC by prefixing them with /, so you'd type:

/nick ninjaturtle

to change your nickname.

The nice thing about ERC is how easy it to add your own commands to this. In your .emacs (after loading ERC), you can add something like:

(defun erc-cmd-MYSYSTEM ()
  "show some information about my system"
  (let ((str (shell-command-to-string "uname -a")))
    (when str (erc-send-message str))))

Or, add add a function called erc-cmd-XXXX (with the XXXX being the command name in capitals, will add command XXXX, which you can invoke with /XXXX or /xxxx). So, with the above function, I can now do something like:

ERC> /mysystem
<djcb> Linux cthulhu 2.6.35-25-generic #44 SMP Fri Jan 21 17:40:48 UTC
       2011 i686 GNU/Linux

Let's look at some other (somewhat) useful command: /calc; again, just a small example, I'm sure something can come up with something a bit more elegant - perhaps using emacs' built-in calc.

(defun erc-cmd-CALC (&rest args)
  "calculate value of some expression using bc"
  (let ((expr (mapconcat 'identity args " ")))
    (when (length expr)
      (let ((result (shell-command-to-string (concat "echo '" expr "' | bc "))))
        (when result (erc-send-message (concat expr " = " result)))))))
ERC> /calc 2 * (3 + 4) / 7
<djcb> 2 * (3 + 4) / 7  = 2

Now, a small warning, just because it's easy to dump the output of, say, cowsay in an IRC-channel using your own /cowsay command, does not mean it is a good idea – in fact, using something like that is guaranteed to get you kicked out fairly quickly from many channels.

That being said, I'm sure many people have come up with much more clever things than the examples here; feel free to share your inventions in the comments!

2009-06-13

ERC: the emacs IRC client

ERC: IRC with emacs

I am migrating more and more of my computer tasks to emacs; I already discussed Twitter and e-mail (with Wanderlust); I'm also using emacs-w3m for some of my web browsing (more about that some other time).

Reason for this ongoing emacsication is to get some return on investment for those countless hours spent on mastering the One True Editor. And it pays off - I can manipulate and glue all these programs together so they fit my workflow like a glove.

Recently, I have also started use emacs for IRC, another great Finnish invention. I am not really an IRC power-user, but I do use; before, I used irssi for that, in a ansi-term console (as explained). But now I have switched to ERC, the emacs IRC-client. You can do just about anything with ERC – I have only barely scratched the surface. But let me share my basic setup.

There first step is getting ERC; it's bundled with any recent emacs, so all you need to do is to add it to your .emacs:

(require 'erc)

That was not too hard, was it?

Now, the thing this is to determine what irc-servers / channels you'd like to join (of course you can do that later manually, but automate what we can). So, we define erc-autojoin-channels-alist:

;; joining && autojoing

;; make sure to use wildcards for e.g. freenode as the actual server
;; name can be be a bit different, which would screw up autoconnect
(erc-autojoin-mode t)
(setq erc-autojoin-channels-alist
  '((".*\\.freenode.net" "#emacs" "#gnu" "#gcc" "#modest" "#maemo")
     (".*\\.gimp.org" "#unix" "#gtk+")))

So, the first element is the IRC-server (with appropriate wildcards), the other elements are channels. This will make ERC automatically join the channels when it notices you're connected to the IRC-server.

And read the comment – it took me some time to figure out why things weren't working. Also, you might want to change these IRC-channels to your own favorites.

The next thing is tracking: ERC can track the various channels you're in, and notify you when there is something new in the channel (it will colorize the channelname in your modeline). This is generally useful, but I don't really care about when people join or leave, or other IRC-meta spam. So:

;; check channels
(erc-track-mode t)
(setq erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE"

                                 "324" "329" "332" "333" "353" "477"))
;; don't show any of this
(setq erc-hide-list '("JOIN" "PART" "QUIT" "NICK"))

Note, the last line has nothing to do with this tracking, that's just telling ERC that I am not interested in those things at all, so it should hide them.

Almost there. Now, I have some function to actually start ERC; it's based on some code in found somewhere, but cannot find right now. The function will start ERC, or switch to it if it's already running – it will actually switch to the most recently active ERC-buffer, which makes things a bit easier to manage.

(defun djcb-erc-start-or-switch ()
  "Connect to ERC, or switch to last active buffer"
  (interactive)
  (if (get-buffer "irc.freenode.net:6667") ;; ERC already active?

    (erc-track-switch-buffer 1) ;; yes: switch to last active
    (when (y-or-n-p "Start ERC? ") ;; no: maybe start ERC
      (erc :server "irc.freenode.net" :port 6667 :nick "foo" :full-name "bar")
      (erc :server "irc.gimp.org" :port 6667 :nick "foo" :full-name "bar"))))

Note: don't forget to replace the :server-value as well as foo and bar with your own preferences. It should be clear what they mean…

You can bind this function to some easy key, and things get really convenient; for example:

;; switch to ERC with Ctrl+c e
(global-set-key (kbd "C-c e") 'djcb-erc-start-or-switch) ;; ERC

Once you have started ERC and are connected to some channels, things work pretty much as in any IRC-client. For each channel, a buffer is opened, and from their on it is up to you to have enlightening conversations with other people around the globe…

Once more, I have only barely scratched the surface of ERC. These are just some basic instructions for getting things working. After that, there are a million things you can do; EmacsWiki has an extensive section on it, with more information and customization then you'll probably ever need.