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.user = user
|
||||
self.legacyName = legacyName
|
||||
self.buddies = BuddyList(self.legacyName, self.db)
|
||||
self.bot = Bot(self)
|
||||
|
||||
self.status = protocol_pb2.STATUS_NONE
|
||||
self.statusMessage = ''
|
||||
|
@ -191,7 +193,7 @@ class Session(YowsupApp):
|
|||
)
|
||||
|
||||
# Called by superclass
|
||||
def onMessageReceived(self, messageEntity):
|
||||
def onMessage(self, messageEntity):
|
||||
self.logger.debug(str(messageEntity))
|
||||
buddy = messageEntity.getFrom().split('@')[0]
|
||||
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)
|
||||
message = message.encode("utf-8")
|
||||
|
||||
if sender == "bot":
|
||||
self.bot.parse(message)
|
||||
elif "-" in sender: # group msg
|
||||
if "/" in sender:
|
||||
room, buddy = sender.split("/")
|
||||
self.sendTextMessage(buddy + '@s.whatsapp.net', message)
|
||||
else:
|
||||
room = sender
|
||||
group = self.groups[room]
|
||||
|
||||
self.backend.handleMessage(self.user, room, message, group.nick)
|
||||
self.sendTextMessage(room + '@g.us', message)
|
||||
|
||||
else: # private msg
|
||||
buddy = sender
|
||||
if message == "\\lastseen":
|
||||
self.presenceRequested.append(buddy)
|
||||
self.call("presence_request", buddy = (buddy + "@s.whatsapp.net",))
|
||||
else:
|
||||
self.sendTextMessage(buddy + '@s.whatsapp.net', message)
|
||||
# if sender == "bot":
|
||||
# self.bot.parse(message)
|
||||
# elif "-" in sender: # group msg
|
||||
# if "/" in sender:
|
||||
# room, buddy = sender.split("/")
|
||||
# self.sendTextMessage(buddy + '@s.whatsapp.net', message)
|
||||
# else:
|
||||
# room = sender
|
||||
# group = self.groups[room]
|
||||
#
|
||||
# self.backend.handleMessage(self.user, room, message, group.nick)
|
||||
# self.sendTextMessage(room + '@g.us', message)
|
||||
#
|
||||
# else: # private msg
|
||||
# buddy = sender
|
||||
# if message == "\\lastseen":
|
||||
# self.presenceRequested.append(buddy)
|
||||
# self.call("presence_request", buddy = (buddy + "@s.whatsapp.net",))
|
||||
# else:
|
||||
self.sendTextMessage(sender + '@s.whatsapp.net', message)
|
||||
|
||||
def sendMessageToXMPP(self, buddy, messageContent, timestamp = ""):
|
||||
if timestamp:
|
||||
|
|
|
@ -3,8 +3,10 @@ from yowsup import env
|
|||
from yowsup.stacks import YowStack
|
||||
from yowsup.common import YowConstants
|
||||
from yowsup.layers import YowLayerEvent, YowParallelLayer
|
||||
from yowsup.layers.auth import AuthError
|
||||
|
||||
# Layers
|
||||
from yowsup.layers.axolotl import YowAxolotlLayer
|
||||
from yowsup.layers.auth import YowCryptLayer, YowAuthenticationProtocolLayer
|
||||
from yowsup.layers.coder import YowCoderLayer
|
||||
from yowsup.layers.logger import YowLoggerLayer
|
||||
|
@ -36,7 +38,7 @@ class YowsupApp(object):
|
|||
def __init__(self):
|
||||
env.CURRENT_ENV = env.S40YowsupEnv()
|
||||
|
||||
layers = (SpectrumLayer,
|
||||
layers = (YowsupAppLayer,
|
||||
YowParallelLayer((YowAuthenticationProtocolLayer,
|
||||
YowMessagesProtocolLayer,
|
||||
YowReceiptProtocolLayer,
|
||||
|
@ -123,7 +125,7 @@ class YowsupApp(object):
|
|||
- message: (str) the body of the message
|
||||
"""
|
||||
messageEntity = TextMessageProtocolEntity(message, to = to)
|
||||
self.stack.toLower(messageEntity)
|
||||
self.sendEntity(messageEntity)
|
||||
|
||||
def onAuthSuccess(self, status, kind, creation, expiration, props, nonce, t):
|
||||
"""
|
||||
|
@ -181,11 +183,18 @@ class YowsupApp(object):
|
|||
"""
|
||||
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
|
||||
|
||||
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):
|
||||
# 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:
|
||||
self.caller.onDisconnect()
|
||||
return True
|
||||
elif layerEvent.getName() == YowsupAppLayer.TO_LOWER_EVENT:
|
||||
self.toLower(layerEvent.getArg('entity'))
|
||||
return True
|
||||
|
||||
@ProtocolEntityCallback('success')
|
||||
def onAuthSuccess(self, entity):
|
||||
|
|
Loading…
Reference in a new issue