lots of whitespace cleanups
This commit is contained in:
parent
c005c31afa
commit
22725c042f
|
@ -283,8 +283,6 @@ class SpectrumBackend:
|
||||||
return
|
return
|
||||||
self.handleMessageAckRequest(payload.userName, payload.buddyName, payload.id)
|
self.handleMessageAckRequest(payload.userName, payload.buddyName, payload.id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def handleAttentionPayload(self, data):
|
def handleAttentionPayload(self, data):
|
||||||
payload = protocol_pb2.ConversationMessage()
|
payload = protocol_pb2.ConversationMessage()
|
||||||
if (payload.ParseFromString(data) == False):
|
if (payload.ParseFromString(data) == False):
|
||||||
|
|
50
session.py
50
session.py
|
@ -50,9 +50,6 @@ class MsgIDs:
|
||||||
self.waId = waId
|
self.waId = waId
|
||||||
self.cnt = 0
|
self.cnt = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Session(YowsupApp):
|
class Session(YowsupApp):
|
||||||
broadcast_prefix = u'\U0001F4E2 '
|
broadcast_prefix = u'\U0001F4E2 '
|
||||||
|
|
||||||
|
@ -378,9 +375,7 @@ class Session(YowsupApp):
|
||||||
participant = location.participant
|
participant = location.participant
|
||||||
latlong = 'geo:' + latitude + ',' + longitude
|
latlong = 'geo:' + latitude + ',' + longitude
|
||||||
|
|
||||||
self.logger.debug("Location received from %s: %s, %s",
|
self.logger.debug("Location received from %s: %s, %s", buddy, latitude, longitude)
|
||||||
buddy, latitude, longitude)
|
|
||||||
|
|
||||||
|
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split('@')[0]
|
||||||
|
@ -563,8 +558,6 @@ class Session(YowsupApp):
|
||||||
else:
|
else:
|
||||||
self.onPresenceAvailable(buddy)
|
self.onPresenceAvailable(buddy)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def onPresenceAvailable(self, buddy):
|
def onPresenceAvailable(self, buddy):
|
||||||
self.logger.info("Is available: %s", buddy)
|
self.logger.info("Is available: %s", buddy)
|
||||||
self.buddies.updateSpectrum(buddy)
|
self.buddies.updateSpectrum(buddy)
|
||||||
|
@ -674,61 +667,47 @@ class Session(YowsupApp):
|
||||||
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":
|
|
||||||
# self.call("presence_request", buddy = (buddy + "@s.whatsapp.net",))
|
|
||||||
# else:
|
|
||||||
if message.split(" ").pop(0) == "\\lastseen":
|
if message.split(" ").pop(0) == "\\lastseen":
|
||||||
self.presenceRequested.append(buddy)
|
self.presenceRequested.append(buddy)
|
||||||
#self.call("presence_request", (buddy + "@s.whatsapp.net",))
|
|
||||||
self._requestLastSeen(buddy)
|
self._requestLastSeen(buddy)
|
||||||
elif message.split(" ").pop(0) == "\\gpp":
|
elif message.split(" ").pop(0) == "\\gpp":
|
||||||
self.logger.info("Get Profile Picture! ")
|
|
||||||
self.sendMessageToXMPP(buddy, "Fetching Profile Picture")
|
self.sendMessageToXMPP(buddy, "Fetching Profile Picture")
|
||||||
#self.call("contact_getProfilePicture", (buddy + "@s.whatsapp.net",))
|
|
||||||
self.requestVCard(buddy)
|
self.requestVCard(buddy)
|
||||||
else:
|
elif (".jpg" in message.lower()) or (".webp" in message.lower()):
|
||||||
if (".jpg" in message.lower()) or (".webp" in message.lower()):
|
|
||||||
self.sendImage(message, ID, buddy + "@s.whatsapp.net")
|
self.sendImage(message, ID, buddy + "@s.whatsapp.net")
|
||||||
elif "geo:" in message.lower():
|
elif "geo:" in message.lower():
|
||||||
self._sendLocation(buddy + "@s.whatsapp.net", message, ID)
|
self._sendLocation(buddy + "@s.whatsapp.net", message, ID)
|
||||||
else:
|
else:
|
||||||
waId = self.sendTextMessage(sender + '@s.whatsapp.net', message)
|
waId = self.sendTextMessage(sender + '@s.whatsapp.net', message)
|
||||||
self.msgIDs[waId] = MsgIDs( ID, waId)
|
self.msgIDs[waId] = MsgIDs(ID, waId)
|
||||||
|
|
||||||
self.logger.info("WA Message send to %s with ID %s", buddy, waId)
|
self.logger.info("WA Message send to %s with ID %s", buddy, waId)
|
||||||
#self.sendTextMessage(sender + '@s.whatsapp.net', message)
|
|
||||||
|
|
||||||
def executeCommand(self, command, room):
|
def executeCommand(self, command, room):
|
||||||
if command == '\\leave':
|
if command == '\\leave':
|
||||||
self.logger.debug("Leaving room %s", room)
|
self.logger.debug("Leaving room %s", room)
|
||||||
# Leave group on whatsapp side
|
self.leaveGroup(room) # Leave group on whatsapp side
|
||||||
self.leaveGroup(room)
|
|
||||||
# Delete Room on spectrum side
|
|
||||||
group = self.groups[room]
|
group = self.groups[room]
|
||||||
group.leaveRoom()
|
group.leaveRoom() # Delete Room on spectrum side
|
||||||
del self.groups[room]
|
del self.groups[room]
|
||||||
|
|
||||||
def _requestLastSeen(self, buddy):
|
def _requestLastSeen(self, buddy):
|
||||||
|
|
||||||
def onSuccess(buddy, lastseen):
|
def onSuccess(buddy, lastseen):
|
||||||
timestamp = time.localtime(time.localtime()-lastseen)
|
timestamp = time.localtime(time.localtime()-lastseen)
|
||||||
timestring = time.strftime("%a, %d %b %Y %H:%M:%S", timestamp)
|
timestring = time.strftime("%a, %d %b %Y %H:%M:%S", timestamp)
|
||||||
self.sendMessageToXMPP(buddy, "%s (%s) %s" % (timestring, utils.ago(lastseen),str(lastseen)))
|
self.sendMessageToXMPP(buddy, "%s (%s) %s" % (timestring, utils.ago(lastseen),str(lastseen)))
|
||||||
|
|
||||||
def onError(errorIqEntity, originalIqEntity):
|
def onError(errorIqEntity, originalIqEntity):
|
||||||
self.sendMessageToXMPP(errorIqEntity.getFrom(), "LastSeen Error")
|
self.sendMessageToXMPP(errorIqEntity.getFrom(), "LastSeen Error")
|
||||||
|
|
||||||
self.requestLastSeen(buddy, onSuccess, onError)
|
self.requestLastSeen(buddy, onSuccess, onError)
|
||||||
|
|
||||||
def _sendLocation(self, buddy, message, ID):
|
def _sendLocation(self, buddy, message, ID):
|
||||||
#with open('/opt/transwhat/map.jpg', 'rb') as imageFile:
|
|
||||||
# raw = base64.b64encode(imageFile.read())
|
|
||||||
latitude,longitude = message.split(':')[1].split(',')
|
latitude,longitude = message.split(':')[1].split(',')
|
||||||
waId = self.sendLocation(buddy, float(latitude), float(longitude))
|
waId = self.sendLocation(buddy, float(latitude), float(longitude))
|
||||||
self.msgIDs[waId] = MsgIDs( ID, waId)
|
self.msgIDs[waId] = MsgIDs( ID, waId)
|
||||||
self.logger.info("WA Location Message send to %s with ID %s", buddy, waId)
|
self.logger.info("WA Location Message send to %s with ID %s", buddy, waId)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def sendMessageToXMPP(self, buddy, messageContent, timestamp = "", nickname = ""):
|
def sendMessageToXMPP(self, buddy, messageContent, timestamp = "", nickname = ""):
|
||||||
if timestamp:
|
if timestamp:
|
||||||
timestamp = time.strftime("%Y%m%dT%H%M%S", time.gmtime(timestamp))
|
timestamp = time.strftime("%Y%m%dT%H%M%S", time.gmtime(timestamp))
|
||||||
|
@ -857,15 +836,16 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
url = "http://maps.google.de?%s" % urllib.urlencode({ "q": "%s %s" % (latitude, longitude) })
|
url = "http://maps.google.de?%s" % urllib.urlencode({ "q": "%s %s" % (latitude, longitude) })
|
||||||
self.sendMessageToXMPP(buddy, utils.shorten(url))
|
self.sendMessageToXMPP(buddy, utils.shorten(url))
|
||||||
if receiptRequested: self.call("message_ack", (jid, messageId))
|
if receiptRequested:
|
||||||
|
self.call("message_ack", (jid, messageId))
|
||||||
|
|
||||||
def onGroupSubjectReceived(self, messageId, gjid, jid, subject, timestamp, receiptRequested):
|
def onGroupSubjectReceived(self, messageId, gjid, jid, subject, timestamp, receiptRequested):
|
||||||
room = gjid.split("@")[0]
|
room = gjid.split("@")[0]
|
||||||
buddy = jid.split("@")[0]
|
buddy = jid.split("@")[0]
|
||||||
|
|
||||||
self.backend.handleSubject(self.user, room, subject, buddy)
|
self.backend.handleSubject(self.user, room, subject, buddy)
|
||||||
if receiptRequested: self.call("subject_ack", (gjid, messageId))
|
if receiptRequested:
|
||||||
|
self.call("subject_ack", (gjid, messageId))
|
||||||
|
|
||||||
# Yowsup Notifications
|
# Yowsup Notifications
|
||||||
def onGroupParticipantRemoved(self, gjid, jid, author, timestamp, messageId, receiptRequested):
|
def onGroupParticipantRemoved(self, gjid, jid, author, timestamp, messageId, receiptRequested):
|
||||||
|
@ -875,15 +855,15 @@ class Session(YowsupApp):
|
||||||
self.logger.info("Removed %s from room %s", buddy, room)
|
self.logger.info("Removed %s from room %s", buddy, room)
|
||||||
|
|
||||||
self.backend.handleParticipantChanged(self.user, buddy, room, protocol_pb2.PARTICIPANT_FLAG_NONE, protocol_pb2.STATUS_NONE) # TODO
|
self.backend.handleParticipantChanged(self.user, buddy, room, protocol_pb2.PARTICIPANT_FLAG_NONE, protocol_pb2.STATUS_NONE) # TODO
|
||||||
|
|
||||||
if receiptRequested: self.call("notification_ack", (gjid, messageId))
|
if receiptRequested: self.call("notification_ack", (gjid, messageId))
|
||||||
|
|
||||||
def onContactProfilePictureUpdated(self, jid, timestamp, messageId, pictureId, receiptRequested):
|
def onContactProfilePictureUpdated(self, jid, timestamp, messageId, pictureId, receiptRequested):
|
||||||
# TODO
|
# TODO
|
||||||
if receiptRequested: self.call("notification_ack", (jid, messageId))
|
if receiptRequested:
|
||||||
|
self.call("notification_ack", (jid, messageId))
|
||||||
|
|
||||||
def onGroupPictureUpdated(self, jid, author, timestamp, messageId, pictureId, receiptRequested):
|
def onGroupPictureUpdated(self, jid, author, timestamp, messageId, pictureId, receiptRequested):
|
||||||
# TODO
|
# TODO
|
||||||
if receiptRequested: self.call("notification_ack", (jid, messageId))
|
if receiptRequested:
|
||||||
|
self.call("notification_ack", (jid, messageId))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,7 @@ class YowsupApp(object):
|
||||||
def sendLocation(self, to, latitude, longitude):
|
def sendLocation(self, to, latitude, longitude):
|
||||||
messageEntity = LocationMediaMessageProtocolEntity(latitude,longitude, None, None, "raw", to = to)
|
messageEntity = LocationMediaMessageProtocolEntity(latitude,longitude, None, None, "raw", to = to)
|
||||||
self.sendEntity(messageEntity)
|
self.sendEntity(messageEntity)
|
||||||
|
|
||||||
return messageEntity.getId()
|
return messageEntity.getId()
|
||||||
|
|
||||||
def sendImage(self, jid, path, caption = None, onSuccess = None, onFailure = None):
|
def sendImage(self, jid, path, caption = None, onSuccess = None, onFailure = None):
|
||||||
|
@ -195,7 +196,6 @@ class YowsupApp(object):
|
||||||
self.sendIq(entity, successFn, errorFn)
|
self.sendIq(entity, successFn, errorFn)
|
||||||
|
|
||||||
def onRequestUploadResult(self, jid, filePath, resultRequestUploadIqProtocolEntity, requestUploadIqProtocolEntity, caption = None, onSuccess=None, onFailure=None):
|
def onRequestUploadResult(self, jid, filePath, resultRequestUploadIqProtocolEntity, requestUploadIqProtocolEntity, caption = None, onSuccess=None, onFailure=None):
|
||||||
|
|
||||||
if requestUploadIqProtocolEntity.mediaType == RequestUploadIqProtocolEntity.MEDIA_TYPE_AUDIO:
|
if requestUploadIqProtocolEntity.mediaType == RequestUploadIqProtocolEntity.MEDIA_TYPE_AUDIO:
|
||||||
doSendFn = self.doSendAudio
|
doSendFn = self.doSendAudio
|
||||||
else:
|
else:
|
||||||
|
@ -206,19 +206,21 @@ class YowsupApp(object):
|
||||||
resultRequestUploadIqProtocolEntity.getIp(), caption)
|
resultRequestUploadIqProtocolEntity.getIp(), caption)
|
||||||
else:
|
else:
|
||||||
successFn = lambda filePath, jid, url: doSendFn(filePath, url, jid, resultRequestUploadIqProtocolEntity.getIp(), caption, onSuccess, onFailure)
|
successFn = lambda filePath, jid, url: doSendFn(filePath, url, jid, resultRequestUploadIqProtocolEntity.getIp(), caption, onSuccess, onFailure)
|
||||||
|
|
||||||
ownNumber = self.stack.getLayerInterface(YowAuthenticationProtocolLayer).getUsername(full=False)
|
ownNumber = self.stack.getLayerInterface(YowAuthenticationProtocolLayer).getUsername(full=False)
|
||||||
|
|
||||||
mediaUploader = MediaUploader(jid, ownNumber, filePath,
|
mediaUploader = MediaUploader(jid, ownNumber, filePath,
|
||||||
resultRequestUploadIqProtocolEntity.getUrl(),
|
resultRequestUploadIqProtocolEntity.getUrl(),
|
||||||
resultRequestUploadIqProtocolEntity.getResumeOffset(),
|
resultRequestUploadIqProtocolEntity.getResumeOffset(),
|
||||||
successFn, self.onUploadError, self.onUploadProgress, async=False)
|
successFn, self.onUploadError, self.onUploadProgress, async=False)
|
||||||
|
|
||||||
mediaUploader.start()
|
mediaUploader.start()
|
||||||
|
|
||||||
def onRequestUploadError(self, jid, path, errorRequestUploadIqProtocolEntity, requestUploadIqProtocolEntity):
|
def onRequestUploadError(self, jid, path, errorRequestUploadIqProtocolEntity, requestUploadIqProtocolEntity):
|
||||||
self.logger.error("Request upload for file %s for %s failed" % (path, jid))
|
self.logger.error("Request upload for file %s for %s failed" % (path, jid))
|
||||||
|
|
||||||
def onUploadError(self, filePath, jid, url):
|
def onUploadError(self, filePath, jid, url):
|
||||||
#logger.error("Upload file %s to %s for %s failed!" % (filePath, url, jid))
|
self.logger.error("Upload file %s to %s for %s failed!" % (filePath, url, jid))
|
||||||
self.logger.error("Upload Error!")
|
|
||||||
|
|
||||||
def onUploadProgress(self, filePath, jid, url, progress):
|
def onUploadProgress(self, filePath, jid, url, progress):
|
||||||
#sys.stdout.write("%s => %s, %d%% \r" % (os.path.basename(filePath), jid, progress))
|
#sys.stdout.write("%s => %s, %d%% \r" % (os.path.basename(filePath), jid, progress))
|
||||||
|
@ -233,7 +235,6 @@ class YowsupApp(object):
|
||||||
onSuccess(entity.getId())
|
onSuccess(entity.getId())
|
||||||
return entity.getId()
|
return entity.getId()
|
||||||
|
|
||||||
|
|
||||||
def doSendAudio(self, filePath, url, to, ip = None, caption = None, onSuccess = None, onFailure = None):
|
def doSendAudio(self, filePath, url, to, ip = None, caption = None, onSuccess = None, onFailure = None):
|
||||||
entity = AudioDownloadableMediaMessageProtocolEntity.fromFilePath(filePath, url, ip, to)
|
entity = AudioDownloadableMediaMessageProtocolEntity.fromFilePath(filePath, url, ip, to)
|
||||||
self.sendEntity(entity)
|
self.sendEntity(entity)
|
||||||
|
@ -242,8 +243,6 @@ class YowsupApp(object):
|
||||||
onSuccess(entity.getId())
|
onSuccess(entity.getId())
|
||||||
return entity.getId()
|
return entity.getId()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def sendPresence(self, available):
|
def sendPresence(self, available):
|
||||||
"""
|
"""
|
||||||
Send presence to whatsapp
|
Send presence to whatsapp
|
||||||
|
|
Loading…
Reference in a new issue