Use YowStackBuilder and the default stack
This commit is contained in:
parent
926aa9a6c9
commit
ebed803984
28
session.py
28
session.py
|
@ -27,7 +27,7 @@ import logging
|
||||||
import urllib
|
import urllib
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from yowsup.stacks import YowStack
|
from yowsup.stacks import YowStack, YowStackBuilder
|
||||||
from yowsup.layers import YowLayerEvent, YowParallelLayer
|
from yowsup.layers import YowLayerEvent, YowParallelLayer
|
||||||
from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
|
from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
|
||||||
from yowsup.layers.auth import (YowCryptLayer, YowAuthenticationProtocolLayer,
|
from yowsup.layers.auth import (YowCryptLayer, YowAuthenticationProtocolLayer,
|
||||||
|
@ -82,18 +82,10 @@ class Session():
|
||||||
self.bot = Bot(self)
|
self.bot = Bot(self)
|
||||||
|
|
||||||
env.CURRENT_ENV = env.S40YowsupEnv()
|
env.CURRENT_ENV = env.S40YowsupEnv()
|
||||||
layers = (SpectrumLayer,
|
self.stack = YowStackBuilder()\
|
||||||
YowParallelLayer((YowAuthenticationProtocolLayer,
|
.pushDefaultLayers(False)\
|
||||||
YowMessagesProtocolLayer,
|
.push(SpectrumLayer)\
|
||||||
YowReceiptProtocolLayer,
|
.build()
|
||||||
YowAckProtocolLayer,
|
|
||||||
YowMediaProtocolLayer)),
|
|
||||||
YowCoderLayer,
|
|
||||||
YowCryptLayer,
|
|
||||||
YowStanzaRegulator,
|
|
||||||
YowNetworkLayer
|
|
||||||
)
|
|
||||||
self.stack = YowStack(layers)
|
|
||||||
self.stack.broadcastEvent(
|
self.stack.broadcastEvent(
|
||||||
YowLayerEvent(SpectrumLayer.EVENT_START,
|
YowLayerEvent(SpectrumLayer.EVENT_START,
|
||||||
backend = self.backend,
|
backend = self.backend,
|
||||||
|
@ -163,13 +155,14 @@ class Session():
|
||||||
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.call("message_send", (buddy + "@s.whatsapp.net", message))
|
self.call("message_send", to = buddy + "@s.whatsapp.net",
|
||||||
|
message = 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.call("message_send", (room + "@g.us", message))
|
self.call("message_send", to = room + "@g.us", message = message)
|
||||||
else: # private msg
|
else: # private msg
|
||||||
buddy = sender
|
buddy = sender
|
||||||
if message == "\\lastseen":
|
if message == "\\lastseen":
|
||||||
|
@ -451,18 +444,21 @@ class SpectrumLayer(YowInterfaceLayer):
|
||||||
message = layerEvent.getArg('message')
|
message = layerEvent.getArg('message')
|
||||||
messageEntity = TextMessageProtocolEntity(message, to = to)
|
messageEntity = TextMessageProtocolEntity(message, to = to)
|
||||||
self.toLower(messageEntity)
|
self.toLower(messageEntity)
|
||||||
|
retval = True
|
||||||
elif layerEvent.getName() == 'typing_send':
|
elif layerEvent.getName() == 'typing_send':
|
||||||
buddy = layerEvent.getArg('buddy')
|
buddy = layerEvent.getArg('buddy')
|
||||||
state = OutgoingChatstateProtocolEntity(
|
state = OutgoingChatstateProtocolEntity(
|
||||||
ChatstateProtocolEntity.STATE_TYPING, buddy
|
ChatstateProtocolEntity.STATE_TYPING, buddy
|
||||||
)
|
)
|
||||||
self.toLower(state)
|
self.toLower(state)
|
||||||
elif layerEvent.getName() == 'typing_pause':
|
retval = True
|
||||||
|
elif layerEvent.getName() == 'typing_paused':
|
||||||
buddy = layerEvent.getArg('buddy')
|
buddy = layerEvent.getArg('buddy')
|
||||||
state = OutgoingChatstateProtocolEntity(
|
state = OutgoingChatstateProtocolEntity(
|
||||||
ChatstateProtocolEntity.STATE_PAUSE, buddy
|
ChatstateProtocolEntity.STATE_PAUSE, buddy
|
||||||
)
|
)
|
||||||
self.toLower(state)
|
self.toLower(state)
|
||||||
|
retval = True
|
||||||
|
|
||||||
self.logger.debug("EVENT %s", layerEvent.getName())
|
self.logger.debug("EVENT %s", layerEvent.getName())
|
||||||
return retval
|
return retval
|
||||||
|
|
Loading…
Reference in a new issue