Есть вот такой код:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ICQ bot
import os
import re
import sys
import urllib2
import feedparser
from twisted.words.protocols import oscar
from twisted.internet import protocol, reactor
# UIN
UIN = "658127246"
PASS = "p@$$w0rd"
# Server
host = ("login.icq.com", 5190)
icqMode = 1
# Status message
AMSG = "I'm here +)"
class Echo(protocol.Protocol):
def dataReceived(self, data):
print data
try:
finded = re.findall(r"(?P<name>.*?): '(?P<value>.*?)'; ", data)
data2 = dict(finded)
sendTo = data2['SendTo']
msg = data2['MSG']
except:
sendTo = '881129'
msg = '=> error receive data message <='
response = 'Send to UIN: %s\r\nMessage: %s\r\n\r\n' % (sendTo, msg)
self.transport.write(response)
# Как от сюда вызвать sendMessage(sendTo, msg) ?????
class B(oscar.BOSConnection):
capabilities = [oscar.CAP_CHAT]
def initDone(self):
print "Connect ",UIN," to server", host[0], host[1]
self.requestSelfInfo().addCallback(self.gotSelfInfo)
self.requestSSI().addCallback(self.gotBuddyList)
self.setAway(AMSG)
factory = protocol.ServerFactory()
factory.protocol = Echo
reactor.listenTCP(8007, factory)
def gotSelfInfo(self, user):
print user.__dict__
self.name = user.name
def gotBuddyList(self, l):
print l
self.activateSSI()
self.setProfile("""ICQBot""")
self.setIdleTime(0)
self.clientReady()
# self.sendICQMessage()
def gotAway(self, away, user):
if away:
print "User ", user,": ",away
class OA(oscar.OscarAuthenticator):
print 'Start ICQ connection'
print 'pid: ', os.getpid()
BOSClass = B
if __name__ == '__main__':
protocol.ClientCreator(reactor, OA, UIN, PASS, icq=icqMode).connectTCP(*host)
# reactor.callLater(10, reactor.stop)
reactor.run()
sys.exit()
Я не знаю как вызвать метод
sendMessage
. Банальное
B().sendMessage()
вываливает ошибку:
exceptions.TypeError: __init__() takes exactly 3 arguments (1 given)