Ejemplo n.º 1
0
    def post(self, command):
        logging.info('PresenceHandler: %r' % self.request.POST)

        user_jid = truncate_jid(self.request.POST.get('from'))

        if command == 'available' or command == 'unavailable':
            # Store the user's presence.
            user = ChatUser.get_or_insert(user_jid)
            user.jid = user_jid
            user.is_available = command == 'available'

            show = self.request.POST.get('show')
            if show and show in _PRESENCE_SHOW_OPTIONS:
                user.presence_show = show
            else:
                # The XMPP standard says an omitted show value is
                # equivalent to chat.
                user.presence_show = xmpp.PRESENCE_SHOW_CHAT

            status_message = self.request.POST.get('status')
            if status_message is not None:
                user.status_message = status_message
            
            user.put()

        elif command == 'probe':
            # Respond to the probe by sending the app's presence.
            status = get_status_entity()
            xmpp.send_presence(
                jid,
                presence_type=(xmpp.PRESENCE_TYPE_UNAVAILABLE
                               if status.presence_available
                               else xmpp.PRESENCE_TYPE_AVAILABLE),
                presence_show=status.presence_show)
Ejemplo n.º 2
0
	def check_jid(jid):
		r = Roster.findByJid(jid)
		if r <> None:
			return True
		else:
			xmpp.send_presence(jid,'',settings.BOT_JID,xmpp.PRESENCE_TYPE_UNAVAILABLE,xmpp.PRESENCE_SHOW_NONE)
			return False
Ejemplo n.º 3
0
 def post(self):
     # [START presence]
     # Split the bare XMPP address (e.g., [email protected])
     # from the resource (e.g., gmail), and then add the
     # address to the roster.
     sender = self.request.get("from").split("/")[0]
     xmpp.send_presence(sender, status=self.request.get("status"), presence_show=self.request.get("show"))
Ejemplo n.º 4
0
 def post(self):
     # In the handler for _ah/xmpp/presence/available
     # Split the bare XMPP address (e.g., [email protected])
     # from the resource (e.g., gmail.CD6EBC4A), and then send the
     # application's presence to the user.
     sender = self.request.get('from').split('/')[0]
     xmpp.send_presence(sender, status=self.request.get('status'), presence_show=self.request.get('show'))
Ejemplo n.º 5
0
    def post(self):
        global WANT_TEA
        global NEWBIE_GREETING
        global teacountdown
        global informed

        fromaddr = self.request.get('from').split("/")[0]
        person = Roster.get_or_insert(key_name=fromaddr, jid=fromaddr)

        if (person.newbie):
            xmpp.send_message(fromaddr, NEWBIE_GREETING)
            person.newbie = False
            person.put()

        if (not person.askme):
            xmpp.send_presence(fromaddr,
                               status=":( Haven't heard from " +
                               getSalutation(fromaddr) + " in a while...",
                               presence_type=xmpp.PRESENCE_TYPE_AVAILABLE)
        else:
            xmpp.send_presence(fromaddr,
                               status="",
                               presence_type=xmpp.PRESENCE_TYPE_AVAILABLE)

        if (teacountdown and person.askme and fromaddr not in informed):
            send_random(fromaddr, WANT_TEA)
            informed.add(fromaddr)
	def post(self, status):
		"""
			Receives presence status from users who have added at least one of the application's
			addresses to their friends list. GMail and GVGW will be skipped, as they're not "real clients".
			This is a very important part of the application, because it receives and saves the full JID
			of the user. Without a full JID, the messages may not be delivered properly and be bounced.
		"""
		
		sender = self.request.get('from')
		
		if status == 'probe':
			xmpp.send_presence(sender, None, self.request.get('to'), xmpp.PRESENCE_TYPE_AVAILABLE)
			status = 'available'
		
		logging.info('User %s is now %s.' % (sender, status))
		
		if '/gmail.' in sender or '/GVGW' in sender:
			loc = sender.split('/')[1]
			logging.info('Skipping setting of lastjid due to %s presence.' % (loc))
			return
		
		gacc = sender.split('/')[0]
		user = User.get_by_key_name(gacc)
		if user is None:
			logging.warn('User %s is not in database; not saving presence.' % (gacc))
			return
		
		try:
			if status == 'available':
				user.lastjid = sender
			
			user.status = status
			user.put()
		except Exception, err:
			logging.error('Unable to save lastjid=%s && status=%s for user %s: %s' % (sender, stauts, gacc, str(err)))
Ejemplo n.º 7
0
 def post(self):
     # [START presence]
     # Split the bare XMPP address (e.g., [email protected])
     # from the resource (e.g., gmail), and then add the
     # address to the roster.
     sender = self.request.get('from').split('/')[0]
     xmpp.send_presence(sender, status=self.request.get('status'),
                        presence_show=self.request.get('show'))
Ejemplo n.º 8
0
 def post(self):
     try:
         self.process()
     except CapabilityDisabledError:
         try:
             xmpp.send_presence(self.request.get("from"), presence_type=xmpp.PRESENCE_SHOW_AWAY)
         except xmpp.Error:
             pass
Ejemplo n.º 9
0
 def post(self):
     #sender = self.request.get('from').split('/')[0]
     status = get_calendar_events()
     #xmpp.send_presence("*****@*****.**", status=tt)
     sender = self.request.get('from').split('/')[0]
     xmpp.send_presence(sender, status=status)
     user = Users()
     user.email = sender
     user.put()
Ejemplo n.º 10
0
 def post(self):
     #sender = self.request.get('from').split('/')[0]
     status = get_calendar_events()
     #xmpp.send_presence("*****@*****.**", status=tt)
     sender = self.request.get('from').split('/')[0]
     xmpp.send_presence(sender, status=status)
     user = Users()
     user.email = sender
     user.put()
Ejemplo n.º 11
0
Archivo: chat.py Proyecto: Javran/twig
	def post(self):
		sender = self.request.get('from').split('/')[0]
		acc_entity = twig_db.getAccount( sender )
		if acc_entity is None:
			return
		q = db.GqlQuery( "SELECT * FROM RelationAccountUser "
					"WHERE account = :1 ", acc_entity )
		text = ".h <cmd> for help, %d users available" % q.count()
		xmpp.send_presence(sender, status=text)
Ejemplo n.º 12
0
 def post(self):
     try:
         self.process()
     except CapabilityDisabledError:
         try:
             xmpp.send_presence(self.request.get('from'),
                                presence_type=xmpp.PRESENCE_SHOW_AWAY)
         except xmpp.Error:
             pass
Ejemplo n.º 13
0
 def get(self):
   for friend in Friends.all():
     (show, status) = ResourceFetcher(friend.bare_jid, friend.my_jid).best()
     self.response.out.write('%s, %s, %s, %s<br>' % (friend.bare_jid,
                                                 friend.my_jid,
                                                 show,
                                                 status))
     xmpp.send_presence(friend.bare_jid, from_jid=friend.my_jid,
                        presence_type='probe')
Ejemplo n.º 14
0
 def do_groupstatus(self, arg):
   '''设置群状态'''
   grp = get_group_info()
   if grp is None:
     grp = Group()
   grp.status = self.msg.body[len(self.sender.prefix):].split(None, 1)[-1]
   grp.put()
   for u in User.all():
     xmpp.send_presence(u.jid, status=grp.status)
   self.msg.reply(u'设置成功!')
Ejemplo n.º 15
0
 def post(self):
     jid = self.request.get("from").split("/")[0]
     s = Session.get_by_key_name(jid)
     if not s:
         u = GoogleUser.get_by_jid(jid)
         if u and u.enabled_user and u.display_timeline and u.msg_template.strip():
             try:
                 Db.set_datastore(Session(key_name=jid, shard=u.shard))
             except CapabilityDisabledError:
                 try:
                     xmpp.send_presence(jid, presence_type=xmpp.PRESENCE_SHOW_AWAY)
                 except xmpp.Error:
                     pass
Ejemplo n.º 16
0
    def post(self, operation):
        logging.info('Presence! %s', self.request.POST)
        from_jid, resource = split_jid(self.request.get('from'))
        full_resource = self.request.get('from').split('/')[1]

        xmpp_user = model.XMPPUser.get_by_jid(from_jid)

        if xmpp_user is None:
            logging.debug("Presence from unknown user %s", from_jid)
            return

        if operation == 'probe':
            xmpp.send_presence(from_jid,
                               status="ready for action!",
                               presence_show="available")

            return

        # else operation is 'available' or 'unavailable'
        if not resource: return logging.debug("No resource on %s", from_jid)

        xmpp_user.resources[resource] = operation
        xmpp_user.put()

        # see if we have a device for this resource:
        device = model.Device.from_resource(resource, from_jid)

        if device != None and device.presence != operation:
            device.presence = operation
            device.put()

        elif device is None:
            logging.debug("Presence from unknown device %s/%s", from_jid,
                          resource)

        model.cache_full_resource(from_jid, resource, full_resource)

        # attempt to send presence down to the owner.  If
        # the owner is not online, no error so no problem
        channel_id = xmpp_user.user.user_id()

        msg = {
            "cmd": "presence",
            "data": {
                "jid": from_jid,
                "resource": resource,
                "presence": operation
            }
        }
        channel.send_message(channel_id, json.dumps(msg))
Ejemplo n.º 17
0
  def post(self):
    frm = self.request.form.get('from').split('/')[0]
    to = self.request.form.get("to").split('/')[0]
    board = to.split('@')[0]

    logging.info("sub: %r -> %r" % (frm, to))
    logging.info("sub form: %r" % self.request.form)

    xmpp.send_presence(frm, from_jid=to, status="My app's status")

    #xmpp.send_message(frm, "hello >.<", from_jid=to)

    sub(frm, board)

    return Response("ya")
Ejemplo n.º 18
0
    def get(self):
        user = users.get_current_user()
        if not user:
            return self.unauthorized()

        xmpp_user = model.XMPPUser.get_current_user()

        jid = user.email()
        if xmpp_user is None:
            xmpp_user = model.XMPPUser.new()
            xmpp_user.put()
            xmpp.send_invite(jid)

        xmpp.send_presence(jid, presence_type=xmpp.PRESENCE_TYPE_PROBE)
        self.render_json({"msg":"OK", "resources":xmpp_user.resources})
Ejemplo n.º 19
0
    def get(self):
        user = users.get_current_user()
        if not user:
            return self.unauthorized()

        xmpp_user = model.XMPPUser.get_current_user()

        jid = user.email()
        if xmpp_user is None:
            xmpp_user = model.XMPPUser.new()
            xmpp_user.put()
            xmpp.send_invite(jid)

        xmpp.send_presence(jid, presence_type=xmpp.PRESENCE_TYPE_PROBE)
        self.render_json({"msg": "OK", "resources": xmpp_user.resources})
Ejemplo n.º 20
0
 def post(self):
     jid = self.request.get('from').split('/')[0]
     s = Session.get_by_key_name(jid)
     if not s:
         u = GoogleUser.get_by_jid(jid)
         if u and u.enabled_user and u.display_timeline and u.msg_template.strip(
         ):
             try:
                 Db.set_datastore(Session(key_name=jid, shard=u.shard))
             except CapabilityDisabledError:
                 try:
                     xmpp.send_presence(
                         jid, presence_type=xmpp.PRESENCE_SHOW_AWAY)
                 except xmpp.Error:
                     pass
Ejemplo n.º 21
0
	def post(self):
		jid = self.request.get('from').split('/')[0]
		logging.info("Subskrypcja od: %s", jid)
		allowedUser = False
		for item in settings.ALLOWED_USERS:
			if(item == jid):
				allowedUser = True
				break
		if(allowedUser == True or jid.find('@'+settings.ALLOWED_DOMAIN) > 0):
			if(Roster.findByJid(jid) == None):
				roster = Roster(jid=jid)
				roster.put()
				xmpp.send_message(jid,settings.WELCOME_MESSAGE)
		else:
			logging.warn("Uzytkownik niedozwolony: %s", jid)
			xmpp.send_presence(jid,'',settings.BOT_JID,xmpp.PRESENCE_TYPE_UNAVAILABLE,xmpp.PRESENCE_SHOW_NONE)
Ejemplo n.º 22
0
    def post(self,operation):
        logging.info('Presence! %s', self.request.POST)
        from_jid, resource = split_jid( self.request.get('from') )
        full_resource = self.request.get('from').split('/')[1]

        xmpp_user = model.XMPPUser.get_by_jid( from_jid )

        if xmpp_user is None:
            logging.debug( "Presence from unknown user %s", from_jid )
            return

        if operation == 'probe':
            xmpp.send_presence( from_jid, 
                    status="ready for action!", 
                    presence_show="available")

            return

        # else operation is 'available' or 'unavailable'
        if not resource: return logging.debug("No resource on %s", from_jid)

        xmpp_user.resources[resource] = operation
        xmpp_user.put()
        
        # see if we have a device for this resource:
        device = model.Device.from_resource(resource, from_jid)

        if device != None and device.presence != operation:
            device.presence = operation
            device.put()

        elif device is None:
            logging.debug( "Presence from unknown device %s/%s", from_jid, resource )

        model.cache_full_resource(from_jid, resource, full_resource)

        # attempt to send presence down to the owner.  If 
        # the owner is not online, no error so no problem
        channel_id = xmpp_user.user.user_id()

        msg = { "cmd" : "presence",
                "data" : {
                    "jid" : from_jid,
                    "resource" : resource,
                    "presence" : operation } 
                }
        channel.send_message(channel_id, json.dumps(msg) )
Ejemplo n.º 23
0
 def get(self, cron_id):
   cron_id = int(cron_id)
   data = Session.get_all(shard=cron_id)
   for u in data:
     jid = u.key().name()
     try:
       self.process(u)
     except CapabilityDisabledError:
       try:
         xmpp.send_presence(jid, presence_show=xmpp.PRESENCE_SHOW_AWAY)
       except xmpp.Error:
         pass
     else:
       try:
         xmpp.send_presence(jid)
       except xmpp.Error:
         pass
Ejemplo n.º 24
0
        def txn():
            user = Subscription.get_by_email(from_jid)
            if user:
		if presence == "probe":
			return xmpp.send_presence(from_jid, presence_type=xmpp.PRESENCE_TYPE_PROBE)
		else:
	                user.status = presence
        	        return user.put()
Ejemplo n.º 25
0
    def post(self,operation):
        logging.info("Subscribe! %s", self.request.POST)
        from_jid = split_jid( self.request.get('from') )[0]

        if operation == 'subscribe':
            xmpp.send_presence(from_jid, status="available")
            pass

        elif operation == 'subscribed':
            pass

        elif operation == 'unsubscribe':
            # TODO delete JID?
            pass

        elif operation == 'unsubscribed':
            # TODO delete JID?
            pass
Ejemplo n.º 26
0
 def get(self, cron_id):
     cron_id = int(cron_id)
     data = Session.get_all(shard=cron_id)
     for u in data:
         jid = u.key().name()
         try:
             self.process(u)
         except CapabilityDisabledError:
             try:
                 xmpp.send_presence(jid,
                                    presence_show=xmpp.PRESENCE_SHOW_AWAY)
             except xmpp.Error:
                 pass
         else:
             try:
                 xmpp.send_presence(jid)
             except xmpp.Error:
                 pass
Ejemplo n.º 27
0
    def post(self, operation):
        logging.info("Subscribe! %s", self.request.POST)
        from_jid = split_jid(self.request.get('from'))[0]

        if operation == 'subscribe':
            xmpp.send_presence(from_jid, status="available")
            pass

        elif operation == 'subscribed':
            pass

        elif operation == 'unsubscribe':
            # TODO delete JID?
            pass

        elif operation == 'unsubscribed':
            # TODO delete JID?
            pass
Ejemplo n.º 28
0
    def post(self):
      global WANT_TEA
      global NEWBIE_GREETING
      global teacountdown
      global informed
      
      fromaddr = self.request.get('from').split("/")[0]    
      person = Roster.get_or_insert(key_name=fromaddr, jid=fromaddr)
      
      if(person.newbie):
        xmpp.send_message(fromaddr, NEWBIE_GREETING)
        person.newbie = False
        person.put()

      if(not person.askme):
        xmpp.send_presence(fromaddr, status=":( Haven't heard from " + getSalutation(fromaddr) + " in a while...", presence_type=xmpp.PRESENCE_TYPE_AVAILABLE)
      else:
        xmpp.send_presence(fromaddr, status="", presence_type=xmpp.PRESENCE_TYPE_AVAILABLE)

      if(teacountdown and person.askme and fromaddr not in informed):
        send_random(fromaddr, WANT_TEA)
        informed.add(fromaddr)
Ejemplo n.º 29
0
  def do_block(self, args):
    '''封禁某个 ID,参数为用户昵称或者 ID(如果不是已经加入的 ID 的话),以及封禁原因'''
    if len(args) < 2:
      self.msg.reply(u'请给出要封禁的用户和原因。')
      return

    target = get_user_by_nick(args[0])
    reason = self.msg.body[len(self.sender.prefix):].split(None, 2)[-1]
    if target is None:
      jid = args[0]
      name = jid
      fullname = name
    else:
      jid = target.jid
      name = target.nick
      fullname = '%s (%s)' % (name, jid)
    u = BlockedUser.gql('where jid = :1', jid).get()
    if u is not None:
      self.msg.reply(u'此 JID 已经被封禁。')
      return

    if jid == config.root:
      self.msg.reply('不能封禁 root 用户')
      return

    if target:
      target.delete()
    u = BlockedUser(jid=jid, reason=reason)
    u.put()

    send_to_all_except(self.sender.jid,
                       (u'%s 已被本群封禁,理由为 %s。' % (name, reason)) \
                       .encode('utf-8'))
    self.msg.reply(u'%s 已被本群封禁,理由为 %s。' % (fullname, reason))
    xmpp.send_message(jid, u'你已被本群封禁,理由为 %s。' % reason)
    xmpp.send_presence(jid, status=u'您已经被本群封禁')
    log_admin(self.sender, BLOCK % (fullname, reason))
Ejemplo n.º 30
0
def send_status(jid):
  if get_blocked_user(jid):
    xmpp.send_presence(jid, status=u'您已经被本群封禁')
    return

  grp = get_group_info()
  if grp is None or not grp.status:
    xmpp.send_presence(jid)
  else:
    xmpp.send_presence(jid, status=grp.status)
Ejemplo n.º 31
0
 def post(self):
     # [START send-presence]
     jid = self.request.get('jid')
     xmpp.send_presence(jid, status="My app's status")
Ejemplo n.º 32
0
	def post(self):
		jid = self.request.get('from').split('/')[0]
		if Roster.check_jid(jid) == False:
			return False
		else:
			xmpp.send_presence(jid, status='Online')
def send_sina_msg_gtalkbot(account, msg):
    xmpp.send_presence(account.wb_bot_sina, from_jid=account.wb_bot_mine)
    time.sleep(5)
    xmpp.send_message(account.wb_bot_sina, msg, from_jid=account.wb_bot_mine)
Ejemplo n.º 34
0
    def post(self):
        if not users.is_current_user_admin():
            logging.info("Non-admin user %s attempted to access form handler"
                         % users.get_current_user().email())
            self.error(404)
            return
        
        jid = self.request.POST.get('jid') or self.request.POST.get('jid_other')
        if jid:
            jid = jid.strip()
        command = self.request.POST.get('command')

        if jid and command == 'chat':
            xmpp.send_message(jid, self.request.POST.get('chat_message'))
            msg = 'Chat message sent to JID %s.' % jid

        elif jid and command == 'invite':
            xmpp.send_invite(jid)
            msg = 'JID %s has been invited to chat.' % jid

        elif jid and command == 'probe':
            xmpp.send_presence(jid, presence_type=xmpp.PRESENCE_TYPE_PROBE)
            msg = 'A presence probe has been sent to JID %s.' % jid

        elif command == 'presence':
            # Store the app's presence.
            status = get_status_entity()
            if self.request.POST.get('presence_available') in ('true', 'false'):
                status.presence_available = self.request.POST.get('presence_available') == 'true'
            if self.request.POST.get('presence_show') in _PRESENCE_SHOW_OPTIONS:
                status.presence_show = self.request.POST.get('presence_show')
            status.status_message = self.request.POST.get('status_message')
            status.put()

            # Send presence messages to all subscribed users.  As
            # written, this could be slow or broken for a large number
            # of users.  A more robust solution would use a task queue
            # and a query cursor.  (Unlike send_message(),
            # send_presence() only accepts one JID at a time.)
            for user in ChatUser.all().filter('is_subscribed', True):
                xmpp.send_presence(
                    user.jid,
                    status=status.status_message,
                    presence_type=(xmpp.PRESENCE_TYPE_AVAILABLE
                                   if status.presence_available
                                   else xmpp.PRESENCE_TYPE_UNAVAILABLE),
                    presence_show=status.presence_show)

            msg = ('The app is now %s and "%s" with message "%s", and all subscribed users have been informed.'
                   % ('available' if status.presence_available else 'unavailable',
                      status.presence_show, status.status_message))

        elif command == 'clear_users':
            db.delete(ChatUser.all(keys_only=True))
            msg = 'All user records have been deleted.'
            
        else:
            msg = 'The submitted form was invalid.'

        memcache.set(_ADMIN_MESSAGE_KEY, msg)
        self.redirect('/')
Ejemplo n.º 35
0
 def get(self):
     xmpp.send_presence('*****@*****.**', status="visited page")
     ctx = {'content':'has', 'uri_for':webapp2.uri_for, 'uri_for_static':uri_for_static}
     self.render_response('page.html', ctx)
Ejemplo n.º 36
0
  def text_message(self, message=None):
    global NOBACKOUT
    global GREETING
    global AHGRAND
    global GOOD_IDEA
    global HUH
    global RUDE
    global NO_TEA_TODAY
    global JUST_MISSED
    global ADDPERSON
    global WANT_TEA
    
    global TRIGGER_HELLO
    global TRIGGER_YES
    global TRIGGER_TEA
    global TRIGGER_RUDE
    global TRIGGER_GOAWAY
    global TRIGGER_ADDPERSON
    global TRIGGER_TEAPREFS
    
    global teacountdown
    global drinkers
    global settingprefs
    global lastround
    
    fromaddr = self.request.get('from').split("/")[0]    
    talker = Roster.get_or_insert(key_name=fromaddr, jid=fromaddr)
    
    # If they showed up in the middle of a round, ask them if they want tea in
    # the normal way after we've responded to this message
    if(talker.askme == False and teacountdown):
      send_random(fromaddr, WANT_TEA)
      informed.add(fromaddr)

    talker.askme=True
    talker.put()
    
    # Mrs Doyle takes no crap
    if re.search(base64.b64decode(TRIGGER_RUDE), message.body, re.IGNORECASE):
      send_random(fromaddr, RUDE)
      return
      
    # And sometimes people take no crap.
    if re.search(TRIGGER_GOAWAY, message.body, re.IGNORECASE):
      talker.askme=False
      talker.put()
      send_random(fromaddr, NO_TEA_TODAY)
      xmpp.send_presence(fromaddr, status=":( Leaving " + getSalutation(fromaddr) + " alone. So alone...", presence_type=xmpp.PRESENCE_TYPE_AVAILABLE)
      return
      
    xmpp.send_presence(fromaddr, status="", presence_type=xmpp.PRESENCE_TYPE_AVAILABLE)

    # See if we're expecting an answer as regards tea preferences
    if fromaddr in settingprefs:
      talker.teaprefs = message.body
      talker.put()
      settingprefs.remove(fromaddr)
      xmpp.send_message(fromaddr, "Okay!")
      return
    
    if teacountdown:    
      if fromaddr in drinkers:
        if re.search(TRIGGER_TEAPREFS, message.body, re.IGNORECASE):
          xmpp.send_message(fromaddr, "So you like your tea '" + message.body + "'?")
          talker.teaprefs = message.body
          talker.put()
        elif re.search(TRIGGER_YES, message.body, re.IGNORECASE):
          xmpp.send_message(fromaddr, "Okay!")
        else:
          send_random(fromaddr, NOBACKOUT)
        return        
    
      if re.search(TRIGGER_YES, message.body, re.IGNORECASE):
        drinkers.add(fromaddr)
        send_random(fromaddr, AHGRAND)        
        howTheyLikeItClause(message.body, talker)       
        
      else:
        send_random(fromaddr, AH_GO_ON)
    
    elif re.search(TRIGGER_ADDPERSON, message.body, re.IGNORECASE):
      emailtoinvite = re.search("("+TRIGGER_ADDPERSON+")", message.body, re.IGNORECASE).group(0)
      xmpp.send_invite(emailtoinvite)
      send_random(fromaddr, ADDPERSON)

    elif re.search(TRIGGER_TEA, message.body, re.IGNORECASE):
      send_random(fromaddr, GOOD_IDEA)
      howTheyLikeItClause(message.body, talker)
      
      drinkers.add(fromaddr)
      informed.add(fromaddr)
      
      for person in get_roster():
        if person.askme and not person.jid == fromaddr:
          xmpp.send_presence(jid=person.jid, presence_type = xmpp.PRESENCE_TYPE_PROBE)
          
      doittask = Task(countdown="120", url="/maketea")
      doittask.add()
      teacountdown = True
      
    elif re.search(TRIGGER_HELLO, message.body, re.IGNORECASE):
      send_random(fromaddr, GREETING)
      
    elif re.search(TRIGGER_YES, message.body, re.IGNORECASE) and (datetime.now() - lastround) < timedelta(seconds=120):
      send_random(fromaddr, JUST_MISSED)
      
    else:
      send_random(fromaddr, HUH)
Ejemplo n.º 37
0
 def post(self):
     # [START send-presence]
     jid = self.request.get("jid")
     xmpp.send_presence(jid, status="My app's status")
Ejemplo n.º 38
0
    def post(self, operation):
        logging.info(
            str(datetime.datetime.now()) + ': Presence! %s', self.request.POST
        )  #Presence! MultiDict([('from', u'[email protected]/pi_0:F3861874')
        from_jid, resource = split_jid(
            self.request.get('from')
        )  #[email protected] ....... resource=pi_0
        full_resource = self.request.get('from').split('/')[1]  #pi_0:F3861874

        msg_from = self.request.get('from')

        xmpp_user = model.XMPPUser.get_by_jid(from_jid)

        if xmpp_user is None:
            logging.debug("1: Presence from unknown user %s ... %s", from_jid,
                          resource)
            return
        #------------------------------------------------------------------
        if operation == 'probe':
            xmpp.send_presence(
                from_jid,
                status="ready for action!",
                #                    presence_show="available")
                presence_show="chat")
            logging.debug("operation was probe")
            return
        elif operation == 'available':
            logging.debug("operation was available")
            pass
        elif operation == 'unavailable':
            logging.debug("operation was unavailable")
            pass
        else:
            logging.debug("operation was " + operation)

        if not resource: return logging.debug("No resource on %s", from_jid)
        if resource.startswith("messaging-lcsw_hangouts"):
            return logging.debug("Resource %s ignored", resource)

        # TODO: need to make sure that the connected device has the appropiate full_resource (incl. google_hash)
        # get the full_resource of the currently connected device
        #if the full_resource corresponds to the device broadcasting the presence, then update the status
        #if not, maybe this is a device connecting with a new Google_Hash, and i will need to confirm
        #   for that, send a connection_request message, and if response is ok, then update the device that is connected

        xmpp_user.resources[resource] = operation
        xmpp_user.put()

        # see if we have a device for this resource:
        device = model.Device.from_resource(
            resource, from_jid
        )  ##resource=pi_0 ...... [email protected] .......

        #        logging.info("Current active device's full_jid is %s ; device that is broadcasting presence is %s", full_resource_current_signed_up_device, full_resource)

        if device != None:
            logging.debug("Device identified: %s ", device.full_jid)
            if device.presence != operation:
                device.presence = operation
                device.put()
            this_is_datetime = datetime.datetime.now().strftime(
                "%Y/%m/%d-%H:%M:%S")

            full_resource_current_signed_up_device = model.get_full_resource(
                from_jid, resource
            )  #what is the full_JID in the model for that XMPP_user+resource (could be from a previous xmpp instance)
            logging.debug(
                "full_resource: %s full_resource_current_signed_up_device: %s",
                full_resource, full_resource_current_signed_up_device)

            if full_resource != full_resource_current_signed_up_device:  #the database has a different full_JID: send an auth request to them
                if full_resource_current_signed_up_device == None:
                    logging.warn("Device %s is not previously registered ",
                                 full_resource)
                else:
                    logging.warn(
                        "Current active device(resource)'s full_jid %s is different from device that is broadcasting presence %s",
                        full_resource_current_signed_up_device, full_resource)

                msg = {
                    "cmd": "auth_login",
                    "params": {
                        "currently_signed_up":
                        full_resource_current_signed_up_device
                    }
                }  #TODO use this to ask specific information to authenticate device, before taking ist full_resource address for the active device. Currently, i am sending the full_resource of the device connected
                if operation == 'available':
                    logging.debug(
                        this_is_datetime +
                        ": Sending request to confirm login to %s",
                        self.request.get('from'))
                    logging.debug(this_is_datetime + ": %s", msg)
                    xmpp.send_message(self.request.get('from'),
                                      json.dumps(msg))
            else:
                if operation == 'available':
                    logging.debug(
                        "Presence from the device already logged in, but sending the auth login request anyway for testing"
                    )
                    msg = {
                        "cmd": "auth_login",
                        "params": {
                            "currently_signed_up":
                            full_resource_current_signed_up_device
                        }
                    }  #TODO use this to ask specific information to authenticate device, before taking ist full_resource address for the active device. Currently, i am sending the full_resource of the device connected
                    logging.debug(
                        this_is_datetime +
                        ": Sending request to confirm login to %s",
                        self.request.get('from'))
                    logging.debug(this_is_datetime + ": %s", msg)
                    xmpp.send_message(self.request.get('from'),
                                      json.dumps(msg))
                    pass

        elif device is None:
            logging.debug("2:Presence from unknown device %s/%s", from_jid,
                          resource)

#        model.cache_full_resource(from_jid, resource, full_resource)    #set memcache for that device, NEED TO TWEAK TO ENSURE THAT IT IS UPDATED ONLY WITH THE ACTIVE xmpp_user
#        logging.debug( "YES REMAPPED AT PRESENCE: memcache set for %s/%s/%s", from_jid, resource, full_resource)
#        logging.debug( "NOT DONE AT PRESENCE: memcache set for %s/%s/%s", from_jid, resource, full_resource)

# attempt to send presence down to the owner.  If
# the owner is not online, no error so no problem
        channel_id = xmpp_user.user.user_id()

        msg = {
            "cmd": "presence",
            "from_msg": msg_from,
            "datestamp_msg": this_is_datetime,
            "data": {
                "jid": from_jid,
                "signed_jid": full_resource_current_signed_up_device,
                "resource": resource,
                "full_resource": full_resource,
                "presence": operation
            }
        }
        channel.send_message(
            channel_id, json.dumps(msg)
        )  #webapp sends the information to the channel of the xmpp_user
Ejemplo n.º 39
0
 def post(self):
   sender = self.request.get('from').split('/')[0]
   xmpp.send_presence(sender, status="https://SeriesWala.appspot.com Share with your friends and get torrent updates about all series!")
Ejemplo n.º 40
0
def chat():
    # 1a) Request online status of each subscriber
    for subscriber in ChatSubscriber.query():
        xmpp.send_presence(subscriber, presence_type=xmpp.PRESENCE_TYPE_PROBE)
    return render_template('chat.html')
Ejemplo n.º 41
0
    def text_message(self, message=None):
        global NOBACKOUT
        global GREETING
        global AHGRAND
        global GOOD_IDEA
        global HUH
        global RUDE
        global NO_TEA_TODAY
        global JUST_MISSED
        global ADDPERSON
        global WANT_TEA

        global TRIGGER_HELLO
        global TRIGGER_YES
        global TRIGGER_TEA
        global TRIGGER_RUDE
        global TRIGGER_GOAWAY
        global TRIGGER_ADDPERSON
        global TRIGGER_TEAPREFS

        global teacountdown
        global drinkers
        global settingprefs
        global lastround

        fromaddr = self.request.get('from').split("/")[0]
        talker = Roster.get_or_insert(key_name=fromaddr, jid=fromaddr)

        # If they showed up in the middle of a round, ask them if they want tea in
        # the normal way after we've responded to this message
        if (talker.askme == False and teacountdown):
            send_random(fromaddr, WANT_TEA)
            informed.add(fromaddr)

        talker.askme = True
        talker.put()

        # Mrs Doyle takes no crap
        if re.search(base64.b64decode(TRIGGER_RUDE), message.body,
                     re.IGNORECASE):
            send_random(fromaddr, RUDE)
            return

        # And sometimes people take no crap.
        if re.search(TRIGGER_GOAWAY, message.body, re.IGNORECASE):
            talker.askme = False
            talker.put()
            send_random(fromaddr, NO_TEA_TODAY)
            xmpp.send_presence(fromaddr,
                               status=":( Leaving " + getSalutation(fromaddr) +
                               " alone. So alone...",
                               presence_type=xmpp.PRESENCE_TYPE_AVAILABLE)
            return

        xmpp.send_presence(fromaddr,
                           status="",
                           presence_type=xmpp.PRESENCE_TYPE_AVAILABLE)

        # See if we're expecting an answer as regards tea preferences
        if fromaddr in settingprefs:
            talker.teaprefs = message.body
            talker.put()
            settingprefs.remove(fromaddr)
            xmpp.send_message(fromaddr, "Okay!")
            return

        if teacountdown:
            if fromaddr in drinkers:
                if re.search(TRIGGER_TEAPREFS, message.body, re.IGNORECASE):
                    xmpp.send_message(
                        fromaddr,
                        "So you like your tea '" + message.body + "'?")
                    talker.teaprefs = message.body
                    talker.put()
                elif re.search(TRIGGER_YES, message.body, re.IGNORECASE):
                    xmpp.send_message(fromaddr, "Okay!")
                else:
                    send_random(fromaddr, NOBACKOUT)
                return

            if re.search(TRIGGER_YES, message.body, re.IGNORECASE):
                drinkers.add(fromaddr)
                send_random(fromaddr, AHGRAND)
                howTheyLikeItClause(message.body, talker)

            else:
                send_random(fromaddr, AH_GO_ON)

        elif re.search(TRIGGER_ADDPERSON, message.body, re.IGNORECASE):
            emailtoinvite = re.search("(" + TRIGGER_ADDPERSON + ")",
                                      message.body, re.IGNORECASE).group(0)
            xmpp.send_invite(emailtoinvite)
            send_random(fromaddr, ADDPERSON)

        elif re.search(TRIGGER_TEA, message.body, re.IGNORECASE):
            send_random(fromaddr, GOOD_IDEA)
            howTheyLikeItClause(message.body, talker)

            drinkers.add(fromaddr)
            informed.add(fromaddr)

            for person in get_roster():
                if person.askme and not person.jid == fromaddr:
                    xmpp.send_presence(jid=person.jid,
                                       presence_type=xmpp.PRESENCE_TYPE_PROBE)

            doittask = Task(countdown="120", url="/maketea")
            doittask.add()
            teacountdown = True

        elif re.search(TRIGGER_HELLO, message.body, re.IGNORECASE):
            send_random(fromaddr, GREETING)

        elif re.search(TRIGGER_YES, message.body, re.IGNORECASE) and (
                datetime.now() - lastround) < timedelta(seconds=120):
            send_random(fromaddr, JUST_MISSED)

        else:
            send_random(fromaddr, HUH)