|
1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 # |
|
4 # Copyright (C) 2013 Sharoon Thomas <sharoon.thomas@openlabs.co.in> |
|
5 # |
|
6 # This script is provided under the terms of the GNU General Public License, |
|
7 # see the file COPYING in the root mcabber source directory. |
|
8 # |
|
9 # |
|
10 # This script displays notifications using the new notification center |
|
11 # introduced in OSX 10.8. |
|
12 import sys |
|
13 import os |
|
14 |
|
15 try: |
|
16 from pync import Notifier |
|
17 except ImportError, exc: |
|
18 print "TIP: Use 'pip install pync'" |
|
19 raise exc |
|
20 |
|
21 |
|
22 def handle_msg(type_, source, filename=None): |
|
23 """ |
|
24 Handle a message |
|
25 |
|
26 :param type_: IN, OUT or MUC (Multi User Chat) |
|
27 :type type_: string |
|
28 :param source: Jabber ID or Nickname, or Room ID for MUC |
|
29 :param filename: Filename of message body if event_log_files was set |
|
30 """ |
|
31 if type_ == "IN": |
|
32 if filename: |
|
33 Notifier.notify( |
|
34 open(filename).read(), |
|
35 title=source, group='mcabber', |
|
36 ) |
|
37 else: |
|
38 Notifier.notify( |
|
39 "Sent you a message", |
|
40 title=source, group='mcabber', |
|
41 ) |
|
42 if filename and os.path.exists(filename): |
|
43 os.remove(filename) |
|
44 |
|
45 |
|
46 def parse(event, *args): |
|
47 """ |
|
48 Parses the arguments received and calls the appropriate function |
|
49 |
|
50 MSG IN jabber@id [file] (when receiving a message) |
|
51 MSG OUT jabber@id (when sending a message) |
|
52 MSG MUC room_id [file] (when receiving a MUC message) |
|
53 STATUS X jabber@id (new buddy status is X) |
|
54 UNREAD "N x y z" (number of unread buddy buffers) |
|
55 |
|
56 :param event: Type of event "MSG", "STATUS", "UNREAD" |
|
57 :param args: tuple of arguments |
|
58 """ |
|
59 if event == "MSG": |
|
60 handle_msg(*args) |
|
61 |
|
62 if __name__ == "__main__": |
|
63 parse(*sys.argv[1:]) |
|
64 |