Exemplo n.º 1
0
def user_returned(meta, user):
    from wheelman.core.models import User, Log
    session = Session()
    reply = ["Welcome back",
             "I missed you!"]
    last_seen = session.query(User.last_seen).filter_by(nick = user).first()
    if not last_seen:
        print "WARNING: User has returned, but we've never seen him before."
        session.close()
        return
    else: last_seen = last_seen[0]
    missed = session.query(Log)\
        .filter_by(target = meta.origin.channel)\
        .filter(Log.type.in_(["pubmsg", "ctcp"]))\
        .filter("created_at > :ls").params(ls = last_seen).all()
    missed = ["%s <%s> %s" % (row.created_at.strftime("%m/%d/%y %I:%M:%S%p"),
                              row.source,
                              row.text)
              for row in missed]
    if len(missed):
        reply += ["You missed some things :("] + missed
    else:
        reply.append("You didn't miss anything!")
    session.close()
    User.see_user(user)
    meta.origin.reply(user, reply)
Exemplo n.º 2
0
 def see_user(self, user):
     session = Session()
     user = session.query(self).filter_by(nick=user).first() or self(user)
     user.last_seen = datetime.now()
     session.merge(user)
     session.commit()
     session.close()
     return user
Exemplo n.º 3
0
def first_post(meta):
    from wheelman.core.db import Session
    from wheelman.core.models import Log
    who = "Do you think this is a game?"
    session = Session()
    now = datetime.now()
    today = datetime(year=now.year, month=now.month, day=now.day)
    first_log = session.query(Log)\
        .filter(Log.type.in_(["pubmsg", "ctcp"]))\
        .filter("created_at >= :today").params(today = today)\
        .order_by(Log.created_at.asc()).first()
    if first_log: who = "%s is on first." % first_log.source
    session.close()
    return who
Exemplo n.º 4
0
 def on_endofnames(self, connection, e):
     from wheelman.core.fsm import fsm
     from wheelman.core.fsm.states import Present, Absent
     print "NamReply: [%s](%s => %s):" % (e.eventtype(), e.source(), e.target()), e.arguments()
     print "Getting names"
     print "I am in:", self.channel
     print "I know about:", self.channels
     seen = []
     for user in [n for n in self.channels[self.channel].users() if n != self._nickname]:
         print "Seeing user, adding state: %s => %s" % (user, Present)
         User.see_user(user)
         fsm.add_initial_user_state(user, state=Present)
         seen.append(user)
     session = Session()
     for user in session.query(User).filter(~User.nick.in_(seen)).all():
         fsm.add_initial_user_state(user.nick, state=Absent)
     session.close()
         
     from wheelman.core.handlers.default import user_returned
     meta = ObjDict({'origin': self, 'connection': connection, 'event': None})
     fsm.on_transition(Absent, Present, lambda user: user_returned(meta, user))
     fsm.on_transition(Present, Absent, User.see_user)
     fsm.on_transition(Present, Present, User.see_user)