comparison mcabber/contrib/events/mcnotify.py @ 1147:fcef5d34b7d4

Add a few sample event scripts
author Mikael Berthe <mikael@lilotux.net>
date Sat, 10 Feb 2007 18:42:02 +0100
parents
children
comparison
equal deleted inserted replaced
1146:d9eb7656440f 1147:fcef5d34b7d4
1 #!/usr/bin/python
2 # Version 0.05
3 #
4 # Copyright (C) 2007 Adam Wolk "Mulander" <netprobe@gmail.com>
5 # Slightly updated by Mikael Berthe
6 #
7 # To use this script, set the "events_command" option to the path of
8 # the script (see the mcabberrc.example file for an example)
9 #
10 # This script is provided under the terms of the GNU General Public License,
11 # see the file COPYING in the root mcabber source directory.
12 #
13
14 import sys
15
16 #CMD_MSG_IN="/usr/bin/play /home/mulander/sound/machine_move.ogg"
17 CMD_MSG_IN=""
18 SHORT_NICK=True
19
20 if len(sys.argv) == 5:
21 event,arg1,arg2,filename = sys.argv[1:5]
22 else:
23 event,arg1,arg2 = sys.argv[1:4]
24 filename = None
25
26 if event == 'MSG' and arg1 == 'IN':
27 import pynotify,os,locale
28 encoding = (locale.getdefaultlocale())[1]
29 msg = 'sent you a message.'
30
31 if SHORT_NICK and '@' in arg2:
32 arg2 = arg2[0:arg2.index('@')]
33
34 if filename is not None:
35 f = file(filename)
36 msg = f.read()
37
38 pynotify.init('mcnotify')
39 msgbox = pynotify.Notification(unicode(arg2, encoding),unicode(msg, encoding))
40 msgbox.set_timeout(3000)
41 msgbox.set_urgency(pynotify.URGENCY_LOW)
42 msgbox.show()
43 if (CMD_MSG_IN):
44 os.system(CMD_MSG_IN + '> /dev/null 2>&1')
45
46 if filename is not None and os.path.exists(filename):
47 os.remove(filename)
48 pynotify.uninit()
49
50 # vim:set noet sts=8 sw=8: