Exemplo n.º 1
0
  def stop_command(self, message=None):
    """process /stop command"""
    # message was /stop ...
    # delete from database
    user,trigger,desc=parse_user_command(message)
    stats=Statistics.all().get()
    stats.chats+=1

    if trigger.lower()=='all':
      to_be_deleted=[]
      for result in Trigger.all().filter("user ="******"user ="******"trigger =",trigger).get()
      if result:
        result.delete()
        stats.row-=1
      if not Trigger.all().filter("user ="******"stop_command: %s, [%s]" % (user,trigger))
    message.reply(STOP_MSG % trigger )
    stats.put()
Exemplo n.º 2
0
 def pause_command(self, message=None):
   """process /pause command"""
   #set suspend flag
   user,trigger,desc=parse_user_command(message)
   stats=Statistics.all().get()
   stats.chats+=1;
   if trigger.lower()=='all':
     to_be_paused=[]
     for result in Trigger.all().filter("user ="******"paused =",False):
       result.paused=True
       to_be_paused.append(result)
     db.put(to_be_paused)
   else:
     result=Trigger.all().filter("user ="******"trigger =",trigger).filter("paused =",False).get()
     if result:
       result.paused=True
       result.put()
   logging.info("pause_command: %s, [%s]" % (user,trigger))
   message.reply(PAUSE_MSG % trigger )
   stats.put()
Exemplo n.º 3
0
 def show_command(self, message=None):
   """process /show command"""
   # send back list of current triggers
   user,trigger,desc=parse_user_command(message)
   stats=Statistics.all().get()
   stats.chats+=1;
   results_list="Current Triggers:\n"
   for result in Trigger.all().filter("user ="******"%s:%s\n"%(result.trigger,result.desc)
   logging.info("show_command: %s" % (user))
   message.reply(results_list)
   stats.put()
Exemplo n.º 4
0
  def start_command(self, message=None):
    """process /start command"""
    # add to database and reply
    user,trigger,desc=parse_user_command(message)
    stats=Statistics.all().get()
    stats.chats+=1;
    #total number of allowed rows
    if stats.row_total >= MAX_ROWS:
      message.reply(MAX_ROWS_MSG)
      logging.info("start_command: Max rows reached %s" % (user))
      return
    #check number of triggers user has already
    if Trigger.all().filter("user ="******"start_command: too many triggers %s" % (user))
      return
    #limits on trigger length
    if len(trigger)<TRIGGER_LEN[0] or len(trigger)>TRIGGER_LEN[1]:
      message.reply(TRIGGER_LEN_MSG % (TRIGGER_LEN[0],TRIGGER_LEN[1]))
      return

    # limits on desc length
    desc=desc[0:DESC_LEN]

    result=Trigger.all().filter("user ="******"trigger =",trigger).get()
    if result:
      if result.desc != desc:
        result.desc=desc
        result.put()
    else:
      if not Trigger.all().filter("user ="******"start_command: %s, [%s] %s" % (user,trigger,desc))
    message.reply(START_MSG % (self.request.host_url,trigger,desc,trigger))
    stats.put()
Exemplo n.º 5
0
def trigger_post(trigger='xyz'):
    """Handle POST-ed data to http://<url>/trigger/<trigger_id>"""
# save updated record and put them all at once
#http://googleappengine.blogspot.com.au/2009/06/10-things-you-probably-didnt-know-about.html
    updated=[]
    now=datetime.datetime.fromtimestamp(time.time())
    then=now-NOTIFY_INTERVAL
    n=Statistics.all().get()
    n.triggers+=1
    for result in Trigger.all().filter("trigger =",trigger):
#dont notify user more often than NOTIFY_INTERVAL
      if (result.last_notify<=then) and (not result.paused):
        logging.info("send_message: %s: %s [%s]" % (result.user.address,result.desc,trigger))
        xmpp.send_message(result.user.address, '%s [%s]' %(result.desc,trigger)  )
        result.last_notify=now
        updated.append(result)
        n.notifies+=1
    db.put(updated)
    n.put()
    return ""