1 # vim:fileencoding=utf-8
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Copyright (c) 2009 by Paweł Tomak <satherot (at) gmail (dot) com>
29 text = reg.sub("&", text)
31 text = reg.sub("<", text)
33 text = reg.sub(">", text)
36 def transStatus(status):
39 'away': 'zaraz wracam',
40 'blocking': 'BLOKUJE',
41 'error': 'BLAD STATUSU!!',
42 'ffc': 'chetny do rozmowy',
43 'chat': 'chetny do rozmowy',
44 'dnd': 'nie przeszkadzac',
45 'xa': 'bardzo zajety',
46 'notavail': 'niedostepny',
49 def displayNotify(title, text, timeout, type):
50 if not pynotify.init("EkgNotif"):
51 ekg.echo("you don't seem to have pynotify installed")
53 n = pynotify.Notification(title, text, type)
54 n.set_timeout(timeout)
58 def notifyStatus(session, uid, status, descr):
59 regexp = re.compile('irc:*')
60 regexp = regexp.findall(session)
63 regexp = re.compile('.*' + session + '.*')
64 regexp = regexp.findall(uid)
66 ekg.echo("Zmienil sie status sesji: %s. Nie zostal on zmieniony przez ten program. Sprawdz to, jesli nie zmieniales statusu jakims innym programem" % session)
68 sesja = ekg.session_get(session)
69 regexp = re.compile('([a-z]{2,4}:[^/]+)')
70 regexp = regexp.match(uid)
71 regexp = regexp.group()
73 user = sesja.user_get(regexp)
75 ekg.echo("Nie znalazlem uzytkownika %s." % uid)
77 status = transStatus(status)
78 nick = user.nickname or user.uid or "Empty"
81 text = "<b>" + nick + "</b> zmienil status na <b>" + s + "</b>"
83 descr = removeHTML(descr)
84 text = text + ":\n" + descr + "\n"
85 return displayNotify(session, text, TIMEOUT_STATUS, ekg.config["notify:icon_status"])
87 def notifyMessage(session, uid, type, text, stime, ignore_level):
88 regexp = re.compile('irc:*')
89 regexp = regexp.findall(session)
92 text = removeHTML(text)
93 sesja = ekg.session_get(session)
95 user = sesja.user_get(uid)
97 ekg.echo("Nie znalazlem uzytkownika %s." % uid)
99 t = time.strftime("%H:%M:%S", time.gmtime(stime))
100 title = t + " " + user.nickname
102 text = text[0:199] + "... >>>\n\n"
103 return displayNotify(title, text, TIMEOUT_MSG, ekg.config["notify:icon_msg"])
105 def timeCheck(name, args):
107 global TIMEOUT_STATUS
108 rexp = re.compile('^[0-9]{4,4}')
109 rexp = rexp.findall(args)
111 if name == "notify:message_timeout":
112 TIMEOUT_MSG = int(rexp[0])
114 if name == "notify:status_timeout":
115 TIMEOUT_STATUS = int(rexp[0])
118 if name == "notify:message_timeout":
119 ekg.echo("Zmienna %s bedzie pomijana do czasu, az zostanie ustawiona wartosc z zakresu od 1000ms do 9999ms. Jej obecna wartosc to: %i" % (name,TIMEOUT_MSG))
120 elif name == "notify:status_timeout":
121 ekg.echo("Zmienna %s bedzie pomijana do czasu, az zostanie ustawiona wartosc z zakresu od 1000ms do 9999ms. Jej obecna wartosc to: %i" % (name,TIMEOUT_STATUS))
124 ekg.handler_bind('protocol-status', notifyStatus)
125 ekg.handler_bind("protocol-message-received", notifyMessage)
126 ekg.variable_add("notify:icon_status", "dialog-warning")
127 ekg.variable_add("notify:icon_msg", "dialog-warning")
128 ekg.variable_add("notify:message_timeout", "3500", timeCheck)
129 ekg.variable_add("notify:status_timeout", "3500", timeCheck)
131 if int(ekg.config["notify:message_timeout"]) < 1000 or int(ekg.config["notify:message_timeout"]) > 9999:
132 timeCheck("notify:message_timeout", ekg.config["notify:message_timeout"])
133 if int(ekg.config["notify:status_timeout"]) < 1000 or int(ekg.config["notify:status_timeout"]) > 9999:
134 timeCheck("notify:status_timeout", ekg.config["notify:status_timeout"])