def doSend(con, txt): global Who if Who != '': msg = chupycabra.Message(Who, txt.strip()) msg.setType('chat') #pg_log("<%s> %s" % (JID, msg.getBody())) con.send(msg) buddy = getBuddy(Who) buddy.log({'from': JID, 'to': Who, 'body': txt.strip()}) else: pg_log(colorize('Nobody selected', 'red'))
def test_messagae_build_reply(): msg = chupycabra.Message(frm='[email protected]/venice') msg_reply = msg.build_reply(reply_txt='Where for art thou, Romeo?') assert msg_reply.__str__( ) == "<message to='[email protected]/venice'><body>Where for art thou, Romeo?</body></message>"
def test_message_set_timestamp(): msg = chupycabra.Message() val = time.strftime('%Y%m%dT%H:%M:%S', time.gmtime(time.time())) msg.setTimestamp(val) assert msg.time_stamp == val
def test_message_get_timestamp(): msg = chupycabra.Message() assert msg.time_stamp
def test_message_create_thread(): msg = chupycabra.Message() msg.setThread('thread-1') assert msg.getThread() == 'thread-1'
def test_message_create_subject_twice(): msg = chupycabra.Message(subject=subject_text) msg.setSubject(subject_text_2) assert msg.getSubject() == subject_text + subject_text_2
def test_message_create_subject_during(): msg = chupycabra.Message(subject=subject_text) assert msg.getSubject() == subject_text
def test_message_create_subject_after(): msg = chupycabra.Message() msg.setSubject(subject_text) assert msg.getSubject() == subject_text
def test_message_create_body_twice(): msg = chupycabra.Message(body=body_text) msg.setBody(body_text_2) assert msg.getBody() == body_text + body_text_2
def test_message_create_body_during(): msg = chupycabra.Message(body=body_text) assert msg.getBody() == body_text
def test_message_create_body_after(): msg = chupycabra.Message() msg.setBody(body_text) assert msg.getBody() == body_text
def test_create_message(): msg = chupycabra.Message() assert msg.__str__() == '<message />'
def doCmd(con, txt): global Who if txt[0] == '/': cmd = split(txt) if cmd[0] == '/select': Who = cmd[1] print "%s selected" % cmd[1] elif cmd[0] == '/presence': to = cmd[1] type = cmd[2] con.send(chupycabra.Presence(to, type)) elif cmd[0] == '/status': p = chupycabra.Presence() MyStatus = ' '.join(cmd[1:]) p.setStatus(MyStatus) con.send(p) elif cmd[0] == '/show': p = chupycabra.Presence() MyShow = ' '.join(cmd[1:]) p.setShow(MyShow) con.send(p) elif cmd[0] == '/subscribe': to = cmd[1] con.send(chupycabra.Presence(to, 'subscribe')) elif cmd[0] == '/unsubscribe': to = cmd[1] con.send(chupycabra.Presence(to, 'unsubscribe')) elif cmd[0] == '/roster': con.requestRoster() _roster = con.getRoster() for jid in _roster.getJIDs(): print colorize( u"%s :: %s (%s/%s)" % ( jid, _roster.getOnline(jid), _roster.getStatus(jid), _roster.getShow(jid), ), 'blue') elif cmd[0] == '/agents': print con.requestAgents() elif cmd[0] == '/register': agent = '' if len(cmd) > 1: agent = cmd[1] con.requestRegInfo(agent) print con.getRegInfo() elif cmd[0] == '/exit': con.disconnect() print colorize("Bye!", 'red') sys.exit(0) elif cmd[0] == '/help': print('commands are:') print(" /select <jabberid>") print(" - selects who to send messages to") print(" /subscribe <jid>") print(" - subscribe to jid's presence") print(" /unsubscribe <jid>") print(" - unsubscribe to jid's presence") print(" /presence <jabberid> <type>") print(" - sends a presence of <type> type to the jabber id") print(" /status <status>") print(" - set your presence status message") print(" /show <status>") print(" - set your presence show message") print(" /roster") print(" - requests roster from the server and ") print(" display a basic dump of it.") print(" /exit") print(" - exit cleanly") else: print colorize("uh?", 'red') else: if Who != '': msg = chupycabra.Message(Who, strip(txt)) msg.setType('chat') print "<%s> %s" % (JID, msg.getBody()) con.send(msg) else: print colorize('Nobody selected', 'red')
def sendMessage (self, con, to, msg): msg = chupycabra.Message(to, msg) msg.setType('chat') print 'send ->', msg con.send(msg)
def messageSend(self, *args): tab = args[-1] msg = tab.getData() msg_obj = chupycabra.Message(tab._id, msg) msg_obj.setType('chat') self.send(msg_obj)