Created
January 21, 2009 05:34
-
-
Save rtyler/49865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ __ ___ ___ __ _ | |__ | |__ ___ _ __ _ _ | |_ (_) | | ___ | |
| '_ ` _ \ / __| / _` | | '_ \ | '_ \ / _ \ | '__| _____ | | | | | __| | | | | / __| | |
| | | | | | | (__ | (_| | | |_) | | |_) | | __/ | | |_____| | |_| | | |_ | | | | \__ \ | |
|_| |_| |_| \___| \__,_| |_.__/ |_.__/ \___| |_| \__,_| \__| |_| |_| |___/ | |
---------------------------------------------------------------------------------------------- | |
mcabbernotify.py | |
****************** | |
****************** | |
SETTING UP EVENTS COMMAND | |
============================= | |
In order for mcabbernotify.py to read anything, you will need to set the following | |
options in your mcabberrc file that you use: | |
set events_command = ~/.mcabber/eventcmd | |
set events_ignore_active_window = 1 | |
set eventcmd_use_nickname = 1 | |
Then you'll want to move the "eventcmd" in this directory into ~/.mcabber and make sure it is executable | |
USING IT LOCALLY | |
=================== | |
If you use mcabber on your local machine, you will simply need to run: | |
tail -f ~/.mcabber/last_event | path/to/mcabbernotify.py | |
USING IT REMOTELY | |
=================== | |
In the situation where you run mcabber remotely, and want notifications locally, you can use the following command: | |
ssh hostname -C "tail -f ~/.mcabber/last_event" | path/to/mcabbernotify.py | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "$@" >> ~/.mcabber/last_event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
import time | |
LOW = -1 | |
NORMAL = -2 | |
CRITICAL = -3 | |
def notifier_init(): | |
if sys.platform == 'linux2': | |
import pynotify | |
pynotify.init('mcabber') | |
def notifier_close(): | |
if sys.platform == 'linux2': | |
import pynotify | |
pynotify.uninit() | |
def generateNotification(title, body, urgency=LOW): | |
if sys.platform == 'linux2': | |
import pynotify | |
urg = {LOW : pynotify.URGENCY_LOW, NORMAL : pynotify.URGENCY_NORMAL, CRITICAL : pynotify.URGENCY_CRITICAL} | |
n = pynotify.Notification(title, body) | |
n.set_timeout(4500) | |
n.set_urgency(urg[urgency]) | |
n.show() | |
if sys.platform == 'darwin': | |
pass # import GrowlNotify? | |
class Handlers(object): | |
def STATUS(self, line): | |
status_map = {'O' : 'online', '_' : 'offline', 'A' : 'away', 'I' : 'invisible', 'F' : 'free to chat', 'D' : 'do not disturb', 'N' : 'not available'} | |
parts = line.split(' ') | |
cmd = parts[0] | |
status = parts[1] | |
who = ' '.join(parts[2:]) | |
who = ''.join([f for f in who if f != '\n']) | |
status = status_map.get(status, status) | |
generateNotification('%s is now %s' % (who, status), '') | |
def UNREAD(self, line): | |
parts = line.split(' ') | |
unread = int(parts[1]) | |
if unread > 1: | |
generateNotification('%s unread messages' % unread, '') | |
def MSG(self, line): | |
parts = line.split(' ') | |
cmd = parts[0] | |
kind = parts[1] | |
who = ' '.join(parts[2:]) | |
who = ''.join([f for f in who if f != '\n']) | |
if kind == 'IN': | |
generateNotification('Private message', '%s sent you a message' % who, CRITICAL) | |
if kind == 'MUC': | |
generateNotification('Conference activity in', who, NORMAL) | |
def main(): | |
h = Handlers() | |
notifier_init() | |
while True: | |
line = sys.stdin.readline() | |
if line: | |
cmd = line.split(' ')[0] | |
if hasattr(h, cmd): | |
getattr(h, cmd)(line) | |
else: | |
print line | |
time.sleep(1) | |
notifier_close() | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment