Browse Source

initial commit

master
Brett Langdon 13 years ago
commit
676ae9e104
2 changed files with 79 additions and 0 deletions
  1. +12
    -0
      README.md
  2. +67
    -0
      awayemail.py

+ 12
- 0
README.md View File

@ -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 `<ZNC DIR>/modules/` (<ZNC DIR> is probably `/var/lib/znc/` unless you set it elsewhere)
* enable `awayemail` module

+ 67
- 0
awayemail.py View File

@ -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: <email:required> <interval:default=60 sec>'
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

Loading…
Cancel
Save