From 676ae9e10400041b8fe498033ec7e9ed55f4a652 Mon Sep 17 00:00:00 2001 From: Brett Langdon Date: Tue, 4 Jun 2013 06:42:11 -0400 Subject: [PATCH] initial commit --- README.md | 12 ++++++++++ awayemail.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 README.md create mode 100644 awayemail.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..71a31de --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +awayemail +========= + +awayemail is a [python3 module](http://wiki.znc.in/Modpython) for [znc](http://wiki.znc.in/ZNC "ZNC") +which will send you missed mentions or private messages by e-mail when you are not connected. + + +## Installation + +* You must have ZNC setup with [Modpython enabled](http://wiki.znc.in/Modpython). +* place [awayemail.py](awayemail.py) in `/modules/` ( is probably `/var/lib/znc/` unless you set it elsewhere) +* enable `awayemail` module diff --git a/awayemail.py b/awayemail.py new file mode 100644 index 0000000..718c006 --- /dev/null +++ b/awayemail.py @@ -0,0 +1,67 @@ +import re +import time + +import znc + +email_regex = re.compile(r'^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$') +space_regex = re.compile(r'\s+') + + +class emailtimer(znc.Timer): + def RunJob(self): + pass + + +class awayemail(znc.Module): + description = "Send mentions and private messages to e-mail when your away" + module_types = [znc.CModInfo.UserModule] + + def OnLoad(self, args, message): + args = space_regex.split(args) + self.interval = 60 + + # make sure we have at least 1 arg + if not args: + message = 'Must provide arguments: ' + return False + # make sure first arg is an e-mail address + if not email_regex.match(args[0]): + message = 'Invalid E-Mail Address: %s' % args + return False + # is we have a second argument, make sure it is a digit + if len(args) >= 2: + if not args[1].isdigit(): + message = 'Interval must be a digit not %s' % args[1] + return False + self.interval = int(args[1]) + + self.email = args + self.timer = znc.CreateTimer(emailtimer, interval=self.interval, cycles=0) + self.timer.msg = '' + return True + + def _queue_msg(self, channel, nick, message): + user = self.GetUser() + # is there is no message then we probably + if self.timer.msg: + self.timer.msg += '\r\n' + ts_format = user.GetTimestampFormat() + now = time.time() + self.timer.msg += '[%s] %s %s: %s' % (time.strftime(ts_format, now), + channel, nick, message) + + def OnPrivMsg(self, nick, message): + user = self.GetUser() + + # private message and user is not connected + if not user.IsUserAttached(): + self._queue_msg('PRIVMSG', nick, message) + return znc.CONTINUE + + def OnChanMsg(self, nick, channel, message): + user = self.GetUser() + if not user.IsUserAttached(): + # user is not connected and user was mentioned + if user.GetNick().lower() in message.lower(): + self._queue_msg(channel, nick, message) + return znc.CONTINUE