Minor fixes
This commit is contained in:
parent
47d52ae22c
commit
48313c5475
44
session.py
44
session.py
|
@ -91,6 +91,8 @@ class Session(YowsupApp):
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
self.user = user
|
self.user = user
|
||||||
self.legacyName = legacyName
|
self.legacyName = legacyName
|
||||||
|
self.buddies = BuddyList(self.legacyName, self.db)
|
||||||
|
self.bot = Bot(self)
|
||||||
|
|
||||||
self.status = protocol_pb2.STATUS_NONE
|
self.status = protocol_pb2.STATUS_NONE
|
||||||
self.statusMessage = ''
|
self.statusMessage = ''
|
||||||
|
@ -191,7 +193,7 @@ class Session(YowsupApp):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onMessageReceived(self, messageEntity):
|
def onMessage(self, messageEntity):
|
||||||
self.logger.debug(str(messageEntity))
|
self.logger.debug(str(messageEntity))
|
||||||
buddy = messageEntity.getFrom().split('@')[0]
|
buddy = messageEntity.getFrom().split('@')[0]
|
||||||
messageContent = utils.softToUni(messageEntity.getBody())
|
messageContent = utils.softToUni(messageEntity.getBody())
|
||||||
|
@ -226,26 +228,26 @@ class Session(YowsupApp):
|
||||||
self.logger.info("Message sent from %s to %s: %s", self.legacyName, sender, message)
|
self.logger.info("Message sent from %s to %s: %s", self.legacyName, sender, message)
|
||||||
message = message.encode("utf-8")
|
message = message.encode("utf-8")
|
||||||
|
|
||||||
if sender == "bot":
|
# if sender == "bot":
|
||||||
self.bot.parse(message)
|
# self.bot.parse(message)
|
||||||
elif "-" in sender: # group msg
|
# elif "-" in sender: # group msg
|
||||||
if "/" in sender:
|
# if "/" in sender:
|
||||||
room, buddy = sender.split("/")
|
# room, buddy = sender.split("/")
|
||||||
self.sendTextMessage(buddy + '@s.whatsapp.net', message)
|
# self.sendTextMessage(buddy + '@s.whatsapp.net', message)
|
||||||
else:
|
# else:
|
||||||
room = sender
|
# room = sender
|
||||||
group = self.groups[room]
|
# group = self.groups[room]
|
||||||
|
#
|
||||||
self.backend.handleMessage(self.user, room, message, group.nick)
|
# self.backend.handleMessage(self.user, room, message, group.nick)
|
||||||
self.sendTextMessage(room + '@g.us', message)
|
# self.sendTextMessage(room + '@g.us', message)
|
||||||
|
#
|
||||||
else: # private msg
|
# else: # private msg
|
||||||
buddy = sender
|
# buddy = sender
|
||||||
if message == "\\lastseen":
|
# if message == "\\lastseen":
|
||||||
self.presenceRequested.append(buddy)
|
# self.presenceRequested.append(buddy)
|
||||||
self.call("presence_request", buddy = (buddy + "@s.whatsapp.net",))
|
# self.call("presence_request", buddy = (buddy + "@s.whatsapp.net",))
|
||||||
else:
|
# else:
|
||||||
self.sendTextMessage(buddy + '@s.whatsapp.net', message)
|
self.sendTextMessage(sender + '@s.whatsapp.net', message)
|
||||||
|
|
||||||
def sendMessageToXMPP(self, buddy, messageContent, timestamp = ""):
|
def sendMessageToXMPP(self, buddy, messageContent, timestamp = ""):
|
||||||
if timestamp:
|
if timestamp:
|
||||||
|
|
|
@ -3,8 +3,10 @@ from yowsup import env
|
||||||
from yowsup.stacks import YowStack
|
from yowsup.stacks import YowStack
|
||||||
from yowsup.common import YowConstants
|
from yowsup.common import YowConstants
|
||||||
from yowsup.layers import YowLayerEvent, YowParallelLayer
|
from yowsup.layers import YowLayerEvent, YowParallelLayer
|
||||||
|
from yowsup.layers.auth import AuthError
|
||||||
|
|
||||||
# Layers
|
# Layers
|
||||||
|
from yowsup.layers.axolotl import YowAxolotlLayer
|
||||||
from yowsup.layers.auth import YowCryptLayer, YowAuthenticationProtocolLayer
|
from yowsup.layers.auth import YowCryptLayer, YowAuthenticationProtocolLayer
|
||||||
from yowsup.layers.coder import YowCoderLayer
|
from yowsup.layers.coder import YowCoderLayer
|
||||||
from yowsup.layers.logger import YowLoggerLayer
|
from yowsup.layers.logger import YowLoggerLayer
|
||||||
|
@ -36,7 +38,7 @@ class YowsupApp(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
env.CURRENT_ENV = env.S40YowsupEnv()
|
env.CURRENT_ENV = env.S40YowsupEnv()
|
||||||
|
|
||||||
layers = (SpectrumLayer,
|
layers = (YowsupAppLayer,
|
||||||
YowParallelLayer((YowAuthenticationProtocolLayer,
|
YowParallelLayer((YowAuthenticationProtocolLayer,
|
||||||
YowMessagesProtocolLayer,
|
YowMessagesProtocolLayer,
|
||||||
YowReceiptProtocolLayer,
|
YowReceiptProtocolLayer,
|
||||||
|
@ -123,7 +125,7 @@ class YowsupApp(object):
|
||||||
- message: (str) the body of the message
|
- message: (str) the body of the message
|
||||||
"""
|
"""
|
||||||
messageEntity = TextMessageProtocolEntity(message, to = to)
|
messageEntity = TextMessageProtocolEntity(message, to = to)
|
||||||
self.stack.toLower(messageEntity)
|
self.sendEntity(messageEntity)
|
||||||
|
|
||||||
def onAuthSuccess(self, status, kind, creation, expiration, props, nonce, t):
|
def onAuthSuccess(self, status, kind, creation, expiration, props, nonce, t):
|
||||||
"""
|
"""
|
||||||
|
@ -181,11 +183,18 @@ class YowsupApp(object):
|
||||||
"""
|
"""
|
||||||
Called when disconnected from whatsapp
|
Called when disconnected from whatsapp
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def sendEntity(self, entity):
|
||||||
|
"""Sends an entity down the stack (as if YowsupAppLayer called toLower)"""
|
||||||
|
self.stack.broadcastEvent(YowLayerEvent(YowsupAppLayer.TO_LOWER_EVENT,
|
||||||
|
entity = entity
|
||||||
|
))
|
||||||
|
|
||||||
from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
|
from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
|
||||||
|
|
||||||
class YowsupAppLayer(YowInterfaceLayer):
|
class YowsupAppLayer(YowInterfaceLayer):
|
||||||
EVENT_START = 'transwhat.event.SpectrumLayer.start'
|
EVENT_START = 'transwhat.event.YowsupAppLayer.start'
|
||||||
|
TO_LOWER_EVENT = 'transwhat.event.YowsupAppLayer.to_lower'
|
||||||
|
|
||||||
def onEvent(self, layerEvent):
|
def onEvent(self, layerEvent):
|
||||||
# We cannot pass instance varaibles in through init, so we use an event
|
# We cannot pass instance varaibles in through init, so we use an event
|
||||||
|
@ -198,6 +207,9 @@ class YowsupAppLayer(YowInterfaceLayer):
|
||||||
elif layerEvent.getName() == YowNetworkLayer.EVENT_STATE_DISCONNECTED:
|
elif layerEvent.getName() == YowNetworkLayer.EVENT_STATE_DISCONNECTED:
|
||||||
self.caller.onDisconnect()
|
self.caller.onDisconnect()
|
||||||
return True
|
return True
|
||||||
|
elif layerEvent.getName() == YowsupAppLayer.TO_LOWER_EVENT:
|
||||||
|
self.toLower(layerEvent.getArg('entity'))
|
||||||
|
return True
|
||||||
|
|
||||||
@ProtocolEntityCallback('success')
|
@ProtocolEntityCallback('success')
|
||||||
def onAuthSuccess(self, entity):
|
def onAuthSuccess(self, entity):
|
||||||
|
|
Loading…
Reference in a new issue