Merge branch 'master' into 'master'
Your mother was a hamster and your father smelt of elder berries. See merge request !4
This commit is contained in:
commit
5830ed1059
|
@ -1,5 +1,19 @@
|
|||
{
|
||||
"email-addr":"5555555555@carrier.com.com",
|
||||
"people": {
|
||||
|
||||
"one": {
|
||||
"email-addr": "5555555555@vtext.com"
|
||||
},
|
||||
"two": {
|
||||
"email-addr": "5555555555@vtext.com"
|
||||
},
|
||||
"three": {
|
||||
"email-addr": "5555555555@vtext.com"
|
||||
},
|
||||
"four": {
|
||||
"email-addr": "5555555555@txt.att.net"
|
||||
}
|
||||
},
|
||||
"output-channels":["#yourchannel"],
|
||||
"interval": 30,
|
||||
"account": {
|
||||
|
@ -8,6 +22,12 @@
|
|||
"password": "Password"
|
||||
},
|
||||
|
||||
"pop": {
|
||||
"host": "pop.gmail.com",
|
||||
"ssl": true,
|
||||
"port": 995
|
||||
},
|
||||
|
||||
"imap": {
|
||||
"host": "imap.gmail.com",
|
||||
"ssl": true,
|
||||
|
|
|
@ -11,11 +11,14 @@ import imaplib
|
|||
from threading import Timer
|
||||
from pyircbot.modulebase import ModuleBase, ModuleHook
|
||||
|
||||
COMMAND_PREFIX = ".text-"
|
||||
|
||||
class TextCDC(ModuleBase):
|
||||
def __init__(self, bot, moduleName):
|
||||
ModuleBase.__init__(self, bot, moduleName)
|
||||
self.hooks.append(ModuleHook("PRIVMSG",self.handleMessage))
|
||||
self.loadConfig()
|
||||
self.prefixes = [person for person in self.config["people"]]
|
||||
self.bot = bot
|
||||
self.timer = None
|
||||
self.setupTimer()
|
||||
|
@ -26,20 +29,22 @@ class TextCDC(ModuleBase):
|
|||
|
||||
def handleMessage(self, args, prefix, trailing):
|
||||
channel = args[0]
|
||||
prefix = self.bot.decodePrefix(prefix)
|
||||
p = self.bot.decodePrefix(prefix)
|
||||
if self.bot.messageHasCommand(".textstatus", trailing):
|
||||
#self.bot.act_PRIVMSG(channel, "POP: %s" % "Good" if setupPop() != None else "Failed.")
|
||||
self.bot.act_PRIVMSG(channel, "SMTP: %s" % "Good" if setupSMTP() != None else "Failed.")
|
||||
if self.bot.messageHasCommand(".text-cdc", trailing):
|
||||
message = ' '.join(trailing.split(" ")[1:])
|
||||
smtp = self.setupSMTP()
|
||||
try:
|
||||
smtp.sendmail(self.config["account"]["auth"]["username"], self.config["email-addr"], "Subject:\n\n%s -%s" % (message, prefix.nick))
|
||||
smtp.quit()
|
||||
self.bot.act_PRIVMSG(channel, "Message sent.")
|
||||
except Exception as e:
|
||||
self.bot.log.error(str(e))
|
||||
self.bot.act_PRIVMSG(channel, "An SMTP Error has Occured")
|
||||
for prefix in self.prefixes:
|
||||
if self.bot.messageHasCommand(COMMAND_PREFIX + prefix, trailing):
|
||||
email = self.config["people"][prefix]["email-addr"]
|
||||
message = ' '.join(trailing.split(" ")[1:])
|
||||
smtp = self.setupSMTP()
|
||||
try:
|
||||
smtp.sendmail(self.config["account"]["auth"]["username"], email, "Subject:\n\n%s -%s" % (message, p.nick))
|
||||
smtp.quit()
|
||||
self.bot.act_PRIVMSG(channel, "Message sent.")
|
||||
except Exception as e:
|
||||
self.bot.log.error(str(e))
|
||||
self.bot.act_PRIVMSG(channel, "An SMTP Error has Occured")
|
||||
|
||||
def setupIMAP(self):
|
||||
imapObj = None
|
||||
|
@ -74,29 +79,31 @@ class TextCDC(ModuleBase):
|
|||
return None
|
||||
|
||||
def setupTimer(self):
|
||||
self.timer = Timer(self.config["interval"], self.checkMail, [self.bot, self.config["email-addr"], self.config["output-channels"]],{})
|
||||
self.timer.start()
|
||||
self.timer = Timer(self.config["interval"], self.checkMail, [self.bot, self.config["people"], self.config["output-channels"]],{})
|
||||
self.timer.start()
|
||||
|
||||
def checkMail(self, bot, emailAddr, channels, imapObj = None):
|
||||
def checkMail(self, bot, people, channels, imapObj = None):
|
||||
try:
|
||||
if imapObj == None:
|
||||
imapObj = self.setupIMAP()
|
||||
result = imapObj.search(None, "(FROM \"%s\")" % emailAddr)
|
||||
if (result[0] == "OK"):
|
||||
messageIds = result[1][0].decode("utf-8")
|
||||
if len(messageIds) > 0:
|
||||
messageIds = messageIds.split(" ")
|
||||
for messageId in messageIds:
|
||||
message = imapObj.fetch(messageId, "BODY[TEXT]")
|
||||
if (message[0] == "OK"):
|
||||
messageText = message[1][0][1].decode("utf-8").split("-----Original Message-----")[0].rstrip()
|
||||
for channel in channels:
|
||||
bot.act_PRIVMSG(channel, "Message from CDC: %s" % messageText)
|
||||
imapObj.store(messageId, "+FLAGS", "\\Deleted")
|
||||
else:
|
||||
raise Exception("SMTP Error. Status was %s, expected OK" % message[0])
|
||||
imapObj.logout()
|
||||
self.setupTimer()
|
||||
for person in people:
|
||||
emailAddr = people[person]["email-addr"]
|
||||
result = imapObj.search(None, "(FROM \"%s\")" % emailAddr)
|
||||
if (result[0] == "OK"):
|
||||
messageIds = result[1][0].decode("utf-8")
|
||||
if len(messageIds) > 0:
|
||||
messageIds = messageIds.split(" ")
|
||||
for messageId in messageIds:
|
||||
message = imapObj.fetch(messageId, "BODY[TEXT]")
|
||||
if (message[0] == "OK"):
|
||||
messageText = message[1][0][1].decode("utf-8").split("-----Original Message-----")[0].rstrip()
|
||||
for channel in channels:
|
||||
bot.act_PRIVMSG(channel, "Message from %s: %s" % (person, messageText))
|
||||
imapObj.store(messageId, "+FLAGS", "\\Deleted")
|
||||
else:
|
||||
raise Exception("SMTP Error. Status was %s, expected OK" % message[0])
|
||||
imapObj.logout()
|
||||
self.setupTimer()
|
||||
except Exception as e:
|
||||
if imapObj != None:
|
||||
imapObj.logout()
|
||||
|
|
Loading…
Reference in New Issue