示例#1
0
 def sendMessage(self, to, txt, messageType='chat'):
     print "\n"
     msg = jabber.Message(to, txt.strip())
     msg.setType(messageType)
     print "<%s> %s" % (self.JID, msg.getBody())
     self.con.send(msg)
     print "\n"
示例#2
0
def sendtoone(who, msg):
    if i18n.isobj(msg):
        msg.setlang(get_userlang(getjid(who)))
        msg = msg.getvalue()

    m = jabber.Message(getjid(who), msg)
    m.setFrom(JID)
    m.setType('chat')
    if conf.general.debug > 1:
        print '...Begin....................', who
    con.send(m)
示例#3
0
def doSend(con, txt):
    global Who
    if Who != '':
        msg = jabber.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'))
示例#4
0
    def send_message(self,to='',m='',type='chat',subject='',thread=''):
        # We hold conn_m lock already
        # (if we should need it)

        lock(self.mutex)
        dst = self.alias_to_uid(to)

        if -1 == dst.find("@"):
            kommsgto=self.me
            unlock(self.mutex)

            lock(komsendq_m)                
            komsendq.put(kommessage(kommsgto, l1_e(
                u"Felaktig adress: %s (originaladress %s)" % (dst,to))))
            
            unlock(komsendq_m)
            return

        msg = jabber.Message()

        if m:
            msg.setBody(m)

        if to:
            msg.setTo(dst)
        msg.setFrom( self.sender_adress() )

        if type:
            msg.setType(type)

        if subject:
            msg.setSubject(subject)

        if thread:
            msg.setThread(thread)

        self.jabber.send(msg)
        unlock(self.mutex)
        
        log( "%s sent message to %s." % (msg.getFrom(), msg.getTo()) )
示例#5
0
            con.send(p)
            sendpresence(conf.general['status'])
            last_ping = time.time()

        if time.time() - last_testing > 120:  # every 40 seconds
            #test quality
            if ontesting:  #mean that callback message doesn't be processed, so reconnect again
                print '>>>', time.strftime(
                    '%Y-%m-%d %H:%M:%S'
                ), 'RECONNECT... network delay it too long: %d\'s' % (
                    time.time() - last_testing)
                raise RECONNECT_COMMAND
            else:
                ontesting = True
                m = jabber.Message(to=JID,
                                   body='Q' + str(int(time.time())) + ':' +
                                   time.strftime('%Y-%m-%d %H:%M:%S'))
                con.send(m)
                if conf.general.debug > 1:
                    print '>>> Quality testing...', time.strftime(
                        '%Y-%m-%d %H:%M:%S')
                last_testing = time.time()

        con.process(1)

        #---- Start IRC code ----
        ircMsg = irc.recv_priv_msg()
        if ircMsg:
            sendtoall(ircMsg, sendToIRC=False)
#---- End IRC Code ----
示例#6
0
 def messageSend(self, *args):
     tab = args[-1]
     msg = tab.getData()
     msg_obj = jabber.Message(tab._id, msg)
     msg_obj.setType('chat')
     self.send(msg_obj)
示例#7
0
 def sendJabberMessageTo(self, to, text):
     t = self.stripXML(text.strip().encode("utf-8"))
     msg = jabber.Message(to, t)
     msg.setType('chat')
     self.jc.send(msg)
     self.jc.process()
示例#8
0
 def sendJabberMessage(self, text):
     for r in Config.NOTIFY:
         t = self.stripXML(text.strip())
         msg = jabber.Message(r, t)
         msg.setType('chat')
         self.jc.send(msg)
示例#9
0
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(jabber.Presence(to, type))
        elif cmd[0] == '/status':
            p = jabber.Presence()
            MyStatus = ' '.join(cmd[1:])
            p.setStatus(MyStatus)
            con.send(p)
        elif cmd[0] == '/show':
            p = jabber.Presence()
            MyShow = ' '.join(cmd[1:])
            p.setShow(MyShow)
            con.send(p)
        elif cmd[0] == '/subscribe':
            to = cmd[1]
            con.send(jabber.Presence(to, 'subscribe'))
        elif cmd[0] == '/unsubscribe':
            to = cmd[1]
            con.send(jabber.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 = jabber.Message(Who, strip(txt))
            msg.setType('chat')
            print "<%s> %s" % (JID, msg.getBody())
            con.send(msg)
        else:
            print colorize('Nobody selected', 'red')