IRCの発言をnotify-sendでポップアップ表示する

以前Rieceで似たよなことをやろうと記事を書いた気がするが、ゆとり世代の僕はRieceじゃなくてLoquiで生活しているのでした!残念!*1


IRCnadokatiarraと言ったproxy clientを通して接続しているので、ポップアップ用にproxy clientさんに別に接続したらええやん、と気付いたのでちょっとコード書いてみた。


ちなみにUbuntu9.04でnotify-sendするとデフォルトでは連続表示できなくなってたのは、
http://d.hatena.ne.jp/voidy21/20091106/1257528008 を参考にした。

#!/usr/bin/python
# -*- coding: utf-8 -*-

from subprocess import call

from twisted.words.protocols import irc
from twisted.internet import reactor, protocol

class IRCNotifier(irc.IRCClient):

    nickname = 'nick'
    realname = 'name'
    password = 'pass'

    encoding = 'iso-2022-jp-ext'
    ignore_names = ['backlogbot']

    def privmsg(self, user, channel, msg):
        user = user.split('!', 1)[0]
        if user in self.ignore_names:
            return
        call(['notify-send', channel, user+' '+msg.decode(self.encoding)])

if __name__ == '__main__':
    f = protocol.ReconnectingClientFactory()
    f.protocol = IRCNotifier
    reactor.connectTCP("localhost", 6667, f)
    reactor.run()

*1:本当残念な人間ですね