mcevent.py
changeset 4 da4bef36c34f
parent 2 7c4faaacd5c7
child 5 1400a0fa01d4
equal deleted inserted replaced
3:7e59e32f2402 4:da4bef36c34f
    18         'use_notify': 0,
    18         'use_notify': 0,
    19         'use_voice':  0,
    19         'use_voice':  0,
    20         'use_sound':  1,
    20         'use_sound':  1,
    21         'short_nick': 1,
    21         'short_nick': 1,
    22         'unread_file': '',
    22         'unread_file': '',
       
    23         'snd_cmd_msg_in': '/usr/bin/play -V0 -v3 sound.wav',
    23 }
    24 }
    24 
    25 
    25 NOTIFY_TIMEOUT=4000
    26 NOTIFY_TIMEOUT=4000
    26 
    27 
    27 contact_map = { }
    28 contact_map = { }
    34 # Specify the name pronounced by espeak
    35 # Specify the name pronounced by espeak
    35 
    36 
    36 blacklist = { }
    37 blacklist = { }
    37 # No notification for these JIDs
    38 # No notification for these JIDs
    38 
    39 
    39 CMD_MSG_IN="/usr/bin/play -V0 -v3 sound.wav"
       
    40 CMD_ESPEAK="/usr/bin/espeak"
    40 CMD_ESPEAK="/usr/bin/espeak"
    41 
    41 
    42 def init_notify():
    42 def init_notify():
    43     import locale
    43     import locale
    44     global encoding
    44     global encoding
    47     encoding = (locale.getdefaultlocale())[1]
    47     encoding = (locale.getdefaultlocale())[1]
    48     NOTIFY_LOADED = True
    48     NOTIFY_LOADED = True
    49 
    49 
    50 def read_conf_from_file():
    50 def read_conf_from_file():
    51     import ConfigParser
    51     import ConfigParser
       
    52 
       
    53     # TODO: Do not re-read file if it hasn't been touched
    52 
    54 
    53     config = ConfigParser.ConfigParser()
    55     config = ConfigParser.ConfigParser()
    54     config.read(CONFFILE)
    56     config.read(CONFFILE)
    55 
    57 
    56     contact_map.clear()
    58     contact_map.clear()
    66         opt['use_sound']  = int(config.get("Notifications", "sound"))
    68         opt['use_sound']  = int(config.get("Notifications", "sound"))
    67     if config.has_option("Notifications", "short_nick"):
    69     if config.has_option("Notifications", "short_nick"):
    68         opt['short_nick'] = int(config.get("Notifications", "short_nick"))
    70         opt['short_nick'] = int(config.get("Notifications", "short_nick"))
    69     if config.has_option("Notifications", "unread_file"):
    71     if config.has_option("Notifications", "unread_file"):
    70         opt['unread_file'] = config.get("Notifications", "unread_file")
    72         opt['unread_file'] = config.get("Notifications", "unread_file")
       
    73     if config.has_option("Notifications", "snd_cmd_msg_in"):
       
    74         opt['snd_cmd_msg_in'] = config.get("Notifications", "snd_cmd_msg_in")
    71 
    75 
    72     for id in config.options("Contacts"):
    76     for id in config.options("Contacts"):
    73         contact_map[id] = config.get("Contacts", id)
    77         contact_map[id] = config.get("Contacts", id)
    74 
    78 
    75     for id in config.options("Alerts"):
    79     for id in config.options("Alerts"):
   149                 if not textmsg:
   153                 if not textmsg:
   150                     textmsg = msg
   154                     textmsg = msg
   151                 notify(buddy, textmsg, NOTIFY_TIMEOUT)
   155                 notify(buddy, textmsg, NOTIFY_TIMEOUT)
   152 
   156 
   153             if opt['use_sound']:
   157             if opt['use_sound']:
   154                 os.system(CMD_MSG_IN + '> /dev/null 2>&1')
   158                 os.system(opt['snd_cmd_msg_in'] + '> /dev/null 2>&1')
   155 
   159 
   156             if opt['use_voice'] and not is_blacklisted(jid):
   160             if opt['use_voice'] and not is_blacklisted(jid):
   157                 if jid in voicemap:
   161                 if jid in voicemap:
   158                     buddy = voicemap[jid]
   162                     buddy = voicemap[jid]
   159                 say(buddy, msg)
   163                 say(buddy, msg)
   167             import os
   171             import os
   168 
   172 
   169             type = online_alerts[jid]
   173             type = online_alerts[jid]
   170             if type > 0:
   174             if type > 0:
   171                 if opt['use_sound']:
   175                 if opt['use_sound']:
   172                     os.system(CMD_MSG_IN + '> /dev/null 2>&1')
   176                     os.system(opt['snd_cmd_msg_in'] + '> /dev/null 2>&1')
   173 
   177 
   174                 buddy = get_nick(jid)
   178                 buddy = get_nick(jid)
   175 
   179 
   176                 if opt['use_notify']:
   180                 if opt['use_notify']:
   177                     if type == 1:
   181                     if type == 1: