Commits

Konstantine Rybnikov committed 4f0564f

CMD @username+

  • Participants
  • Parent commits ca1dad7

Comments (0)

Files changed (6)

     - reply to message (ok)
     - @username (ok, basic support)
     - S @username (ok)
-    - #
-    - @username+
-    - NICK
+    - # (ok)
+    - @username+ (ok)
 
 #. @username to show his friends
 #. Message posting to tell about it to subscribers
 #. Catch ``MultipleObjectsReturned`` and ``DoesNotExist`` and say "message #msg not found"
 #. Bot named @users
 #. Bot named @top
+#. CMD NICK
+#. CMD DISCOVER that finds users you may want to be your friend

openju/bl/user.py

     return user
 
 def get_user(nick):
+    """ Get user by nick """
     return User.objects.get(
         nick = nick)
 

openju/controllers/message.py

     else:
         return _(u'There are no messages from friends yet.')
 
+def last_user_messages(user_nick):
+    user = bl.user.get_user(user_nick)
+    messages = user.last_messages()
+
+    if len(messages):
+        return render_messages_list(reversed(list(messages)))
+    else:
+        return _(u'This user have not posted any messages yet.')
+
 def post_reply(message_id, body):
     message = bl.message.get_message(message_id)
     new_message = message.post_reply(g.auth_user, body)

openju/message_bus.py

             cmd_read_message_with_replies,
             cmd_post_reply,
             cmd_user_info,
+            cmd_user_messages,
             cmd_subscribe,
             cmd_post_message,
             )
         from openju.bl.message import get_last_messages
         return get_last_messages(q=lambda q: q & Q(user__in = self.friends))
 
+    def last_messages(self):
+        from openju.bl.message import get_last_messages
+        return get_last_messages(q=lambda q: q & Q(user = self))
+
 class Message(Document):
     user = ReferenceField(User, required=True)
     body = StringField(required=True)
         d = m.groupdict()
         return controllers.user.info(d['nick'])
 
+def cmd_user_messages(text):
+    pattern = re.compile(ur'@%(p_nick)s\+\s*$' % {
+            'p_nick': PATTERNS['NICK'],
+            })
+    m = pattern.match(text)
+    if m is not None:
+        d = m.groupdict()
+        return controllers.message.last_user_messages(d['nick'])
+
 def cmd_subscribe(text):
     pattern = re.compile(ur'S\s+@%(p_nick)s\s*' % {
             'p_nick': PATTERNS['NICK']