예제 #1
0
    def privmsg(self, nick, chan, msg):
        actual_nick = nick.split("!")[0]
        contact_channel = self.channel_cache.get(chan, None)
        
        if not contact_channel or not msg.startswith("PanoptaOutage"): return
        try: msg = msg.split(" ", 1)[1]
        except: return

        
        contact = contact_channel.contact
        customer = contact.customer
        outages = list(customer.active_outages)
        
        self.log.info("received message from contact:customer %d:%d" % (contact.id, customer.id))
        
        # reset the timeout so they stay connected 60 seconds longer
        self.client.started = time.time()
        msg = msg.encode("utf-8")
        
        action, responses, extra = CS.outage_respond(chan, msg, outages=outages)
        if action == "outage_log":
            self.log.info("writing to outage log")
            log_msg, outages = extra
            
            log_msg = "%s from irc %s: \"%s\"" % (actual_nick, self.server, log_msg)
            for outage in outages: outage.log(log_msg)
        
        for response in responses:
            helpers.msg(self.client, chan, response)
            time.sleep(1)
예제 #2
0
 def message(self, msg):
     if msg['type'] != "chat":
         body = str(msg.get("body", "")).strip()
         self.log.info("unhandled message of type %s: %s, %r" % (msg['type'], body, msg))
         return
     
     body = str(msg["body"]).strip()
     sender = str(msg["from"]).split("/")[0]
     self.log.info("received message from %s: \"%s\"" % (sender, body))
     
     channel = self.handle_cache.get(sender, None)
     if not channel:
         channel = masterdb.ContactChannel.selectBy(contact_info=sender)
         if not channel.count(): return
         channel = channel[0]
     
     contact = channel.contact
     customer = contact.customer
     outages = list(customer.active_outages)
     
     action, responses, extra = CS.outage_respond(sender, body, outages=outages)
     
     if action == "outage_log":
         self.log.info("writing to outage log")
         log_msg, outages = extra
         
         log_msg = "%s from gchat: \"%s\"" % (contact.fullname, log_msg)
         for outage in outages: outage.log(log_msg)
         
     response = "\n".join(responses)
     msg.reply(response).send()