示例#1
0
 def getMsgs(self, account_name, protocol_name, other_user=None, timerange=None,type=None,count=50):
     """-> list of message, in order of time"""
     account_id_internal = self._get_account_id_internal(account_name, protocol_name)
     if not account_id_internal:
         return
     where_params = { "account_id_internal" : account_id_internal }
     if other_user:
         conv_id = self._getConvId(account_id_internal, other_user)
         if not conv_id:
             return
         where_params["conv_id"] = conv_id
     
     query_string = "SELECT timestamp, who, body, type, other_user FROM messages WHERE "
     value_l = []
     ands = []
     for k, v in where_params.items():
         ands.append(k + "=? ")
         value_l.append(v)
         
     query_string += " AND ".join(ands)
     
     if timerange:
         start, end = timerange
         query_string += " AND timestamp BETWEEN ? AND ? "
         value_l += [int(start), int(end)]
     
     query_string += "ORDER BY timestamp "
     if count:
         query_string += "LIMIT ? "
         value_l.append(count)
         
     log_warn(query_string, value_l)
     del ands
     for res in self._cursor.execute(query_string, value_l):
         msg = YobotMessage()
         msg.time = int(res["timestamp"])
         msg.name = res["other_user"]
         msg.who = res["who"]
         msg.txt = res["body"]
         type = res["type"]
         msg.yprotoflags |= yobotproto.YOBOT_MSG_TYPE_CHAT if type == CONV_TYPE_CHAT else yobotproto.YOBOT_MSG_TYPE_IM
         msg.prplmsgflags |= yobotproto.PURPLE_MESSAGE_SEND if msg.who == account_name else yobotproto.PURPLE_MESSAGE_RECV
         yield msg
示例#2
0
 def sendmsg(self, to, txt, chat=False):
     msg = YobotMessage()
     if chat:
         msg.yprotoflags = yobotproto.YOBOT_MSG_TYPE_CHAT
     else:
         msg.yprotoflags = yobotproto.YOBOT_MSG_TYPE_IM
     msg.yprotoflags |= yobotproto.YOBOT_MSG_TO_SERVER
     msg.txt = txt
     msg.acctid = self.id
     msg.time = time()
     msg.name = to
     self.svc.sendMsg(msg)