Convert str literals to unicode literals
This commit is contained in:
parent
c005c31afa
commit
d9bd18013d
2
buddy.py
2
buddy.py
|
@ -79,7 +79,7 @@ class BuddyList(dict):
|
||||||
self.session.sendSync(contacts, delta=False, interactive=True,
|
self.session.sendSync(contacts, delta=False, interactive=True,
|
||||||
success=self.onSync)
|
success=self.onSync)
|
||||||
|
|
||||||
self.logger.debug("Roster add: %s", str(list(contacts)))
|
self.logger.debug("Roster add: %s",list(contacts))
|
||||||
|
|
||||||
for number in contacts:
|
for number in contacts:
|
||||||
buddy = self[number]
|
buddy = self[number]
|
||||||
|
|
303
session.py
303
session.py
|
@ -1,10 +1,10 @@
|
||||||
__author__ = "Steffen Vogel"
|
__author__ = u"Steffen Vogel"
|
||||||
__copyright__ = "Copyright 2015, Steffen Vogel"
|
__copyright__ = u"Copyright 2015, Steffen Vogel"
|
||||||
__license__ = "GPLv3"
|
__license__ = u"GPLv3"
|
||||||
__maintainer__ = "Steffen Vogel"
|
__maintainer__ = u"Steffen Vogel"
|
||||||
__email__ = "post@steffenvogel.de"
|
__email__ = u"post@steffenvogel.de"
|
||||||
|
|
||||||
"""
|
u"""
|
||||||
This file is part of transWhat
|
This file is part of transWhat
|
||||||
|
|
||||||
transWhat is free software: you can redistribute it and/or modify
|
transWhat is free software: you can redistribute it and/or modify
|
||||||
|
@ -59,14 +59,14 @@ class Session(YowsupApp):
|
||||||
def __init__(self, backend, user, legacyName, extra):
|
def __init__(self, backend, user, legacyName, extra):
|
||||||
super(Session, self).__init__()
|
super(Session, self).__init__()
|
||||||
self.logger = logging.getLogger(self.__class__.__name__)
|
self.logger = logging.getLogger(self.__class__.__name__)
|
||||||
self.logger.info("Created: %s", legacyName)
|
self.logger.info(u"Created: %s", legacyName)
|
||||||
|
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
self.user = user
|
self.user = user
|
||||||
self.legacyName = legacyName
|
self.legacyName = legacyName
|
||||||
|
|
||||||
self.status = protocol_pb2.STATUS_NONE
|
self.status = protocol_pb2.STATUS_NONE
|
||||||
self.statusMessage = ''
|
self.statusMessage = u''
|
||||||
|
|
||||||
self.groups = {}
|
self.groups = {}
|
||||||
self.gotGroupList = False
|
self.gotGroupList = False
|
||||||
|
@ -90,55 +90,45 @@ class Session(YowsupApp):
|
||||||
self.bot = Bot(self)
|
self.bot = Bot(self)
|
||||||
|
|
||||||
self.imgMsgId = None
|
self.imgMsgId = None
|
||||||
self.imgPath = ""
|
self.imgPath = u""
|
||||||
self.imgBuddy = None
|
self.imgBuddy = None
|
||||||
self.imgType = ""
|
self.imgType = u""
|
||||||
|
|
||||||
|
|
||||||
def __del__(self): # handleLogoutRequest
|
def __del__(self): # handleLogoutRequest
|
||||||
self.logout()
|
self.logout()
|
||||||
|
|
||||||
def logout(self):
|
def logout(self):
|
||||||
self.logger.info("%s logged out", self.user)
|
self.logger.info(u"%s logged out", self.user)
|
||||||
super(Session, self).logout()
|
super(Session, self).logout()
|
||||||
self.loggedIn = False
|
self.loggedIn = False
|
||||||
|
|
||||||
def login(self, password):
|
def login(self, password):
|
||||||
self.logger.info("%s attempting login", self.user)
|
self.logger.info(u"%s attempting login", self.user)
|
||||||
self.password = password
|
self.password = password
|
||||||
self.shouldBeConncted = True
|
self.shouldBeConncted = True
|
||||||
super(Session, self).login(self.legacyName, self.password)
|
super(Session, self).login(self.legacyName, self.password)
|
||||||
|
|
||||||
def _shortenGroupId(self, gid):
|
|
||||||
# FIXME: might have problems if number begins with 0
|
|
||||||
return gid
|
|
||||||
# return '-'.join(hex(int(s))[2:] for s in gid.split('-'))
|
|
||||||
|
|
||||||
def _lengthenGroupId(self, gid):
|
|
||||||
return gid
|
|
||||||
# FIXME: might have problems if number begins with 0
|
|
||||||
# return '-'.join(str(int(s, 16)) for s in gid.split('-'))
|
|
||||||
|
|
||||||
def updateRoomList(self):
|
def updateRoomList(self):
|
||||||
rooms = []
|
rooms = []
|
||||||
text = []
|
text = []
|
||||||
for room, group in self.groups.iteritems():
|
for room, group in self.groups.iteritems():
|
||||||
rooms.append([self._shortenGroupId(room), group.subject])
|
rooms.append([room, group.subject])
|
||||||
text.append(self._shortenGroupId(room) + '@' + self.backend.spectrum_jid + ' :' + group.subject)
|
text.append(room.decode('utf-8') + u'@' + self.backend.spectrum_jid.decode('utf-8') + u' :' + group.subject.decode('utf-8'))
|
||||||
|
|
||||||
self.logger.debug("Got rooms: %s", rooms)
|
self.logger.debug(u"Got rooms: %s", rooms)
|
||||||
self.backend.handleRoomList(rooms)
|
self.backend.handleRoomList(rooms)
|
||||||
message = "Note, you are a participant of the following groups:\n" +\
|
message = u"Note, you are a participant of the following groups:\n" +\
|
||||||
'\n'.join(text) + '\nIf you do not join them you will lose messages'
|
u'\n'.join(text) + u'\nIf you do not join them you will lose messages'
|
||||||
#self.bot.send(message)
|
#self.bot.send(message)
|
||||||
|
|
||||||
def _updateGroups(self, response, request):
|
def _updateGroups(self, response, request):
|
||||||
self.logger.debug('Received groups list %s', response)
|
self.logger.debug(u'Received groups list %s', str(response).decode('utf-8'))
|
||||||
groups = response.getGroups()
|
groups = response.getGroups()
|
||||||
for group in groups:
|
for group in groups:
|
||||||
room = group.getId()
|
room = group.getId()
|
||||||
owner = group.getOwner().split('@')[0]
|
owner = group.getOwner().split(u'@')[0]
|
||||||
subjectOwner = group.getSubjectOwner().split('@')[0]
|
subjectOwner = group.getSubjectOwner().split(u'@')[0]
|
||||||
subject = utils.softToUni(group.getSubject())
|
subject = utils.softToUni(group.getSubject())
|
||||||
|
|
||||||
if room in self.groups:
|
if room in self.groups:
|
||||||
|
@ -148,7 +138,7 @@ class Session(YowsupApp):
|
||||||
oroom.subject = subject
|
oroom.subject = subject
|
||||||
else:
|
else:
|
||||||
self.groups[room] = Group(room, owner, subject, subjectOwner, self.backend, self.user)
|
self.groups[room] = Group(room, owner, subject, subjectOwner, self.backend, self.user)
|
||||||
# self.joinRoom(self._shortenGroupId(room), self.user.split("@")[0])
|
# self.joinRoom(self._shortenGroupId(room), self.user.split(u"@")[0])
|
||||||
self.groups[room].addParticipants(group.getParticipants().keys(),
|
self.groups[room].addParticipants(group.getParticipants().keys(),
|
||||||
self.buddies, self.legacyName)
|
self.buddies, self.legacyName)
|
||||||
|
|
||||||
|
@ -158,8 +148,8 @@ class Session(YowsupApp):
|
||||||
while self.groupOfflineQueue[room]:
|
while self.groupOfflineQueue[room]:
|
||||||
msg = self.groupOfflineQueue[room].pop(0)
|
msg = self.groupOfflineQueue[room].pop(0)
|
||||||
self.backend.handleMessage(self.user, room, msg[1],
|
self.backend.handleMessage(self.user, room, msg[1],
|
||||||
msg[0], "", msg[2])
|
msg[0], u"", msg[2])
|
||||||
self.logger.debug("Send queued group message to: %s %s %s",
|
self.logger.debug(u"Send queued group message to: %s %s %s",
|
||||||
msg[0],msg[1], msg[2])
|
msg[0],msg[1], msg[2])
|
||||||
self.gotGroupList = True
|
self.gotGroupList = True
|
||||||
for room, nick in self.joinRoomQueue:
|
for room, nick in self.joinRoomQueue:
|
||||||
|
@ -171,9 +161,9 @@ class Session(YowsupApp):
|
||||||
if not self.gotGroupList:
|
if not self.gotGroupList:
|
||||||
self.joinRoomQueue.append((room, nick))
|
self.joinRoomQueue.append((room, nick))
|
||||||
return
|
return
|
||||||
room = self._lengthenGroupId(room)
|
room = room
|
||||||
if room in self.groups:
|
if room in self.groups:
|
||||||
self.logger.info("Joining room: %s room=%s, nick=%s",
|
self.logger.info(u"Joining room: %s room=%s, nick=%s",
|
||||||
self.legacyName, room, nick)
|
self.legacyName, room, nick)
|
||||||
|
|
||||||
group = self.groups[room]
|
group = self.groups[room]
|
||||||
|
@ -186,52 +176,52 @@ class Session(YowsupApp):
|
||||||
ownerNick = group.subjectOwner
|
ownerNick = group.subjectOwner
|
||||||
|
|
||||||
group.sendParticipantsToSpectrum(self.legacyName)
|
group.sendParticipantsToSpectrum(self.legacyName)
|
||||||
self.backend.handleSubject(self.user, self._shortenGroupId(room),
|
self.backend.handleSubject(self.user, room,
|
||||||
group.subject, ownerNick)
|
group.subject, ownerNick)
|
||||||
self.logger.debug("Room subject: room=%s, subject=%s",
|
self.logger.debug(u"Room subject: room=%s, subject=%s",
|
||||||
room, group.subject)
|
room.decode('utf-8'), group.subject.decode('utf-8'))
|
||||||
self.backend.handleRoomNicknameChanged(
|
self.backend.handleRoomNicknameChanged(
|
||||||
self.user, self._shortenGroupId(room), group.subject
|
self.user, room, group.subject
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.logger.warn("Room doesn't exist: %s", room)
|
self.logger.warn(u"Room doesn't exist: %s", room)
|
||||||
|
|
||||||
def leaveRoom(self, room):
|
def leaveRoom(self, room):
|
||||||
if room in self.groups:
|
if room in self.groups:
|
||||||
self.logger.info("Leaving room: %s room=%s", self.legacyName, room)
|
self.logger.info(u"Leaving room: %s room=%s", self.legacyName, room)
|
||||||
group = self.groups[room]
|
group = self.groups[room]
|
||||||
group.joined = False
|
group.joined = False
|
||||||
else:
|
else:
|
||||||
self.logger.warn("Room doesn't exist: %s. Unable to leave.", room)
|
self.logger.warn(u"Room doesn't exist: %s. Unable to leave.", room)
|
||||||
|
|
||||||
def _lastSeen(self, number, seconds):
|
def _lastSeen(self, number, seconds):
|
||||||
self.logger.debug("Last seen %s at %s seconds" % (number, str(seconds)))
|
self.logger.debug(u"Last seen %s at %s seconds", number, seconds)
|
||||||
if seconds < 60:
|
if seconds < 60:
|
||||||
self.onPresenceAvailable(number)
|
self.onPresenceAvailable(number)
|
||||||
else:
|
else:
|
||||||
self.onPresenceUnavailable(number)
|
self.onPresenceUnavailable(number)
|
||||||
def sendReadReceipts(self, buddy):
|
def sendReadReceipts(self, buddy):
|
||||||
for _id, _from, participant in self.recvMsgIDs:
|
for _id, _from, participant in self.recvMsgIDs:
|
||||||
if _from.split('@')[0] == buddy:
|
if _from.split(u'@')[0] == buddy:
|
||||||
self.sendReceipt(_id, _from, 'read', participant)
|
self.sendReceipt(_id, _from, u'read', participant)
|
||||||
self.recvMsgIDs.remove((_id, _from, participant))
|
self.recvMsgIDs.remove((_id, _from, participant))
|
||||||
self.logger.debug("Send read receipt to %s (ID: %s)", _from, _id)
|
self.logger.debug(u"Send read receipt to %s (ID: %s)", _from, _id)
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onAuthSuccess(self, status, kind, creation,
|
def onAuthSuccess(self, status, kind, creation,
|
||||||
expiration, props, nonce, t):
|
expiration, props, nonce, t):
|
||||||
self.logger.info("Auth success: %s", self.user)
|
self.logger.info(u"Auth success: %s", self.user)
|
||||||
|
|
||||||
self.backend.handleConnected(self.user)
|
self.backend.handleConnected(self.user)
|
||||||
self.backend.handleBuddyChanged(self.user, "bot", self.bot.name,
|
self.backend.handleBuddyChanged(self.user, u"bot", self.bot.name,
|
||||||
["Admin"], protocol_pb2.STATUS_ONLINE)
|
[u"Admin"], protocol_pb2.STATUS_ONLINE)
|
||||||
# Initialisation?
|
# Initialisation?
|
||||||
self.requestPrivacyList()
|
self.requestPrivacyList()
|
||||||
self.requestClientConfig()
|
self.requestClientConfig()
|
||||||
self.requestServerProperties()
|
self.requestServerProperties()
|
||||||
# ?
|
# ?
|
||||||
|
|
||||||
self.logger.debug('Requesting groups list')
|
self.logger.debug(u'Requesting groups list')
|
||||||
self.requestGroupsList(self._updateGroups)
|
self.requestGroupsList(self._updateGroups)
|
||||||
# self.requestBroadcastList()
|
# self.requestBroadcastList()
|
||||||
|
|
||||||
|
@ -242,67 +232,62 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
if self.initialized == False:
|
if self.initialized == False:
|
||||||
self.sendOfflineMessages()
|
self.sendOfflineMessages()
|
||||||
#self.bot.call("welcome")
|
#self.bot.call(u"welcome")
|
||||||
self.initialized = True
|
self.initialized = True
|
||||||
|
|
||||||
self.loggedIn = True
|
self.loggedIn = True
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onAuthFailed(self, reason):
|
def onAuthFailed(self, reason):
|
||||||
self.logger.info("Auth failed: %s (%s)", self.user, reason)
|
self.logger.info(u"Auth failed: %s (%s)", self.user, reason)
|
||||||
self.backend.handleDisconnected(self.user, 0, reason)
|
self.backend.handleDisconnected(self.user, 0, reason)
|
||||||
self.password = None
|
self.password = None
|
||||||
self.loggedIn = False
|
self.loggedIn = False
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onDisconnect(self):
|
def onDisconnect(self):
|
||||||
self.logger.debug('Disconnected')
|
self.logger.debug(u'Disconnected')
|
||||||
self.backend.handleDisconnected(self.user, 0, 'Disconnected for unknown reasons')
|
self.backend.handleDisconnected(self.user, 0, u'Disconnected for unknown reasons')
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onReceipt(self, _id, _from, timestamp, type, participant, offline, items):
|
def onReceipt(self, _id, _from, timestamp, type, participant, offline, items):
|
||||||
self.logger.debug("received receipt, sending ack: " +
|
self.logger.debug(u"received receipt, sending ack: %s",
|
||||||
' '.join(map(str, [_id, _from, timestamp,
|
[_id, _from, timestamp, type, participant, offline, items]
|
||||||
type, participant, offline, items]))
|
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
number = _from.split('@')[0]
|
number = _from.split(u'@')[0]
|
||||||
self.backend.handleMessageAck(self.user, number, self.msgIDs[_id].xmppId)
|
self.backend.handleMessageAck(self.user, number, self.msgIDs[_id].xmppId)
|
||||||
self.msgIDs[_id].cnt = self.msgIDs[_id].cnt + 1
|
self.msgIDs[_id].cnt = self.msgIDs[_id].cnt + 1
|
||||||
if self.msgIDs[_id].cnt == 2:
|
if self.msgIDs[_id].cnt == 2:
|
||||||
del self.msgIDs[_id]
|
del self.msgIDs[_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.logger.error("Message %s not found. Unable to send ack", _id)
|
self.logger.error(u"Message %s not found. Unable to send ack", _id)
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onAck(self, _id, _class, _from, timestamp):
|
def onAck(self, _id, _class, _from, timestamp):
|
||||||
self.logger.debug('received ack ' +
|
self.logger.debug(u'received ack: %s', [_id, _class, _from, timestamp])
|
||||||
' '.join(map(str, [_id, _class, _from,timestamp,]))
|
|
||||||
)
|
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onTextMessage(self, _id, _from, to, notify, timestamp, participant,
|
def onTextMessage(self, _id, _from, to, notify, timestamp, participant,
|
||||||
offline, retry, body):
|
offline, retry, body):
|
||||||
self.logger.debug('received TextMessage' +
|
self.logger.debug(u'received TextMessage %s', [
|
||||||
' '.join(map(str, [
|
_id, _from, to, notify, timestamp,
|
||||||
_id, _from, to, notify, timestamp,
|
participant, offline, retry, body
|
||||||
participant, offline, retry, body
|
])
|
||||||
]))
|
buddy = _from.split(u'@')[0]
|
||||||
)
|
|
||||||
buddy = _from.split('@')[0]
|
|
||||||
messageContent = utils.softToUni(body)
|
messageContent = utils.softToUni(body)
|
||||||
self.sendReceipt(_id, _from, None, participant)
|
self.sendReceipt(_id, _from, None, participant)
|
||||||
self.recvMsgIDs.append((_id, _from, participant))
|
self.recvMsgIDs.append((_id, _from, participant))
|
||||||
self.logger.info("Message received from %s to %s: %s (at ts=%s)",
|
self.logger.info(u"Message received from %s to %s: %s (at ts=%s)",
|
||||||
buddy, self.legacyName, messageContent, timestamp)
|
buddy, self.legacyName, messageContent, timestamp)
|
||||||
if participant is not None: # Group message or broadcast
|
if participant is not None: # Group message or broadcast
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split(u'@')[0]
|
||||||
if _from.split('@')[1] == 'broadcast': # Broadcast message
|
if _from.split(u'@')[1] == u'broadcast': # Broadcast message
|
||||||
message = self.broadcast_prefix + messageContent
|
message = self.broadcast_prefix + messageContent
|
||||||
self.sendMessageToXMPP(partname, message, timestamp)
|
self.sendMessageToXMPP(partname, message, timestamp)
|
||||||
else: # Group message
|
else: # Group message
|
||||||
if notify is None:
|
if notify is None:
|
||||||
notify = ""
|
notify = u""
|
||||||
self.sendGroupMessageToXMPP(buddy, partname, messageContent,
|
self.sendGroupMessageToXMPP(buddy, partname, messageContent,
|
||||||
timestamp, notify)
|
timestamp, notify)
|
||||||
else:
|
else:
|
||||||
|
@ -310,14 +295,14 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onImage(self, image):
|
def onImage(self, image):
|
||||||
self.logger.debug('Received image message %s', str(image))
|
self.logger.debug(u'Received image message %s', str(image))
|
||||||
buddy = image._from.split('@')[0]
|
buddy = image._from.split(u'@')[0]
|
||||||
participant = image.participant
|
participant = image.participant
|
||||||
if image.caption is None:
|
if image.caption is None:
|
||||||
image.caption = ''
|
image.caption = u''
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split(u'@')[0]
|
||||||
if image._from.split('@')[1] == 'broadcast': # Broadcast message
|
if image._from.split(u'@')[1] == u'broadcast': # Broadcast message
|
||||||
self.sendMessageToXMPP(partname, self.broadcast_prefix, image.timestamp)
|
self.sendMessageToXMPP(partname, self.broadcast_prefix, image.timestamp)
|
||||||
self.sendMessageToXMPP(partname, image.url, image.timestamp)
|
self.sendMessageToXMPP(partname, image.url, image.timestamp)
|
||||||
self.sendMessageToXMPP(partname, image.caption, image.timestamp)
|
self.sendMessageToXMPP(partname, image.caption, image.timestamp)
|
||||||
|
@ -333,13 +318,13 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onAudio(self, audio):
|
def onAudio(self, audio):
|
||||||
self.logger.debug('Received audio message %s', str(audio))
|
self.logger.debug(u'Received audio message %s', str(audio))
|
||||||
buddy = audio._from.split('@')[0]
|
buddy = audio._from.split(u'@')[0]
|
||||||
participant = audio.participant
|
participant = audio.participant
|
||||||
message = audio.url
|
message = audio.url
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split(u'@')[0]
|
||||||
if audio._from.split('@')[1] == 'broadcast': # Broadcast message
|
if audio._from.split(u'@')[1] == u'broadcast': # Broadcast message
|
||||||
self.sendMessageToXMPP(partname, self.broadcast_prefix, audio.timestamp)
|
self.sendMessageToXMPP(partname, self.broadcast_prefix, audio.timestamp)
|
||||||
self.sendMessageToXMPP(partname, message, audio.timestamp)
|
self.sendMessageToXMPP(partname, message, audio.timestamp)
|
||||||
else: # Group message
|
else: # Group message
|
||||||
|
@ -352,14 +337,14 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onVideo(self, video):
|
def onVideo(self, video):
|
||||||
self.logger.debug('Received video message %s', str(video))
|
self.logger.debug(u'Received video message %s', str(video))
|
||||||
buddy = video._from.split('@')[0]
|
buddy = video._from.split(u'@')[0]
|
||||||
participant = video.participant
|
participant = video.participant
|
||||||
|
|
||||||
message = video.url
|
message = video.url
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split(u'@')[0]
|
||||||
if video._from.split('@')[1] == 'broadcast': # Broadcast message
|
if video._from.split(u'@')[1] == u'broadcast': # Broadcast message
|
||||||
self.sendMessageToXMPP(partname, self.broadcast_prefix, video.timestamp)
|
self.sendMessageToXMPP(partname, self.broadcast_prefix, video.timestamp)
|
||||||
self.sendMessageToXMPP(partname, message, video.timestamp)
|
self.sendMessageToXMPP(partname, message, video.timestamp)
|
||||||
else: # Group message
|
else: # Group message
|
||||||
|
@ -371,20 +356,20 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
|
|
||||||
def onLocation(self, location):
|
def onLocation(self, location):
|
||||||
buddy = location._from.split('@')[0]
|
buddy = location._from.split(u'@')[0]
|
||||||
latitude = location.getLatitude()
|
latitude = location.getLatitude()
|
||||||
longitude = location.getLongitude()
|
longitude = location.getLongitude()
|
||||||
url = location.getLocationURL()
|
url = location.getLocationURL()
|
||||||
participant = location.participant
|
participant = location.participant
|
||||||
latlong = 'geo:' + latitude + ',' + longitude
|
latlong = u'geo:' + latitude + u',' + longitude
|
||||||
|
|
||||||
self.logger.debug("Location received from %s: %s, %s",
|
self.logger.debug(u"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(u'@')[0]
|
||||||
if location._from.split('@')[1] == 'broadcast': # Broadcast message
|
if location._from.split(u'@')[1] == u'broadcast': # Broadcast message
|
||||||
self.sendMessageToXMPP(partname, self.broadcast_prefix, location.timestamp)
|
self.sendMessageToXMPP(partname, self.broadcast_prefix, location.timestamp)
|
||||||
if url is not None:
|
if url is not None:
|
||||||
self.sendMessageToXMPP(partname, url, location.timestamp)
|
self.sendMessageToXMPP(partname, url, location.timestamp)
|
||||||
|
@ -398,22 +383,20 @@ class Session(YowsupApp):
|
||||||
self.sendMessageToXMPP(buddy, url, location.timestamp)
|
self.sendMessageToXMPP(buddy, url, location.timestamp)
|
||||||
self.sendMessageToXMPP(buddy, latlong, location.timestamp)
|
self.sendMessageToXMPP(buddy, latlong, location.timestamp)
|
||||||
self.sendReceipt(location._id, location._from, None, location.participant)
|
self.sendReceipt(location._id, location._from, None, location.participant)
|
||||||
self.recvMsgIDs.append((loaction._id, location._from, location.participant))
|
self.recvMsgIDs.append((location._id, location._from, location.participant))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onVCard(self, _id, _from, name, card_data, to, notify, timestamp, participant):
|
def onVCard(self, _id, _from, name, card_data, to, notify, timestamp, participant):
|
||||||
self.logger.debug('received VCard' +
|
self.logger.debug(u'received VCard %s', [
|
||||||
' '.join(map(str, [
|
|
||||||
_id, _from, name, card_data, to, notify, timestamp, participant
|
_id, _from, name, card_data, to, notify, timestamp, participant
|
||||||
]))
|
])
|
||||||
)
|
message = u"Received VCard (not implemented yet)"
|
||||||
message = "Received VCard (not implemented yet)"
|
buddy = _from.split(u"@")[0]
|
||||||
buddy = _from.split("@")[0]
|
|
||||||
if participant is not None: # Group message
|
if participant is not None: # Group message
|
||||||
partname = participant.split('@')[0]
|
partname = participant.split(u'@')[0]
|
||||||
if _from.split('@')[1] == 'broadcast': # Broadcast message
|
if _from.split(u'@')[1] == u'broadcast': # Broadcast message
|
||||||
message = self.broadcast_prefix + message
|
message = self.broadcast_prefix + message
|
||||||
self.sendMessageToXMPP(partname, message, timestamp)
|
self.sendMessageToXMPP(partname, message, timestamp)
|
||||||
else: # Group message
|
else: # Group message
|
||||||
|
@ -428,15 +411,15 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
def transferFile(self, buddy, name, data):
|
def transferFile(self, buddy, name, data):
|
||||||
# Not working
|
# Not working
|
||||||
self.logger.debug('transfering file %s', name)
|
self.logger.debug(u'transfering file %s', name)
|
||||||
self.backend.handleFTStart(self.user, buddy, name, len(data))
|
self.backend.handleFTStart(self.user, buddy, name, len(data))
|
||||||
self.backend.handleFTData(0, data)
|
self.backend.handleFTData(0, data)
|
||||||
self.backend.handleFTFinish(self.user, buddy, name, len(data), 0)
|
self.backend.handleFTFinish(self.user, buddy, name, len(data), 0)
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onContactTyping(self, buddy):
|
def onContactTyping(self, buddy):
|
||||||
self.logger.info("Started typing: %s", buddy)
|
self.logger.info(u"Started typing: %s", buddy)
|
||||||
if buddy != 'bot':
|
if buddy != u'bot':
|
||||||
self.sendPresence(True)
|
self.sendPresence(True)
|
||||||
self.backend.handleBuddyTyping(self.user, buddy)
|
self.backend.handleBuddyTyping(self.user, buddy)
|
||||||
|
|
||||||
|
@ -445,15 +428,15 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onContactPaused(self, buddy):
|
def onContactPaused(self, buddy):
|
||||||
self.logger.info("Paused typing: %s", buddy)
|
self.logger.info(u"Paused typing: %s", buddy)
|
||||||
if buddy != 'bot':
|
if buddy != u'bot':
|
||||||
self.backend.handleBuddyTyped(self.user, buddy)
|
self.backend.handleBuddyTyped(self.user, buddy)
|
||||||
self.timer = Timer(3, self.backend.handleBuddyStoppedTyping,
|
self.timer = Timer(3, self.backend.handleBuddyStoppedTyping,
|
||||||
(self.user, buddy)).start()
|
(self.user, buddy)).start()
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onAddedToGroup(self, group):
|
def onAddedToGroup(self, group):
|
||||||
self.logger.debug("Added to group: %s", group)
|
self.logger.debug(u"Added to group: %s", group)
|
||||||
room = group.getGroupId()
|
room = group.getGroupId()
|
||||||
owner = group.getCreatorJid(full = False)
|
owner = group.getCreatorJid(full = False)
|
||||||
subjectOwner = group.getSubjectOwnerJid(full = False)
|
subjectOwner = group.getSubjectOwnerJid(full = False)
|
||||||
|
@ -461,25 +444,25 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
self.groups[room] = Group(room, owner, subject, subjectOwner, self.backend, self.user)
|
self.groups[room] = Group(room, owner, subject, subjectOwner, self.backend, self.user)
|
||||||
self.groups[room].addParticipants(group.getParticipants, self.buddies, self.legacyName)
|
self.groups[room].addParticipants(group.getParticipants, self.buddies, self.legacyName)
|
||||||
self.bot.send("You have been added to group: %s@%s (%s)"
|
self.bot.send(u"You have been added to group: %s@%s (%s)"
|
||||||
% (self._shortenGroupId(room), subject, self.backend.spectrum_jid))
|
% (room, subject, self.backend.spectrum_jid))
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onParticipantsAddedToGroup(self, group):
|
def onParticipantsAddedToGroup(self, group):
|
||||||
self.logger.debug("Participants added to group: %s", group)
|
self.logger.debug(u"Participants added to group: %s", group)
|
||||||
room = group.getGroupId().split('@')[0]
|
room = group.getGroupId().split(u'@')[0]
|
||||||
self.groups[room].addParticipants(group.getParticipants(), self.buddies, self.legacyName)
|
self.groups[room].addParticipants(group.getParticipants(), self.buddies, self.legacyName)
|
||||||
self.groups[room].sendParticipantsToSpectrum(self.legacyName)
|
self.groups[room].sendParticipantsToSpectrum(self.legacyName)
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onSubjectChanged(self, room, subject, subjectOwner, timestamp):
|
def onSubjectChanged(self, room, subject, subjectOwner, timestamp):
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
"onSubjectChange(rrom=%s, subject=%s, subjectOwner=%s, timestamp=%s)",
|
u"onSubjectChange(room=%s, subject=%s, subjectOwner=%s, timestamp=%s)",
|
||||||
room, subject, subjectOwner, timestamp)
|
room, subject, subjectOwner, timestamp)
|
||||||
try:
|
try:
|
||||||
group = self.groups[room]
|
group = self.groups[room]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.logger.error("Subject of non-existant group (%s) changed", group)
|
self.logger.error(u"Subject of non-existant group (%s) changed", group)
|
||||||
else:
|
else:
|
||||||
group.subject = subject
|
group.subject = subject
|
||||||
group.subjectOwner = subjectOwner
|
group.subjectOwner = subjectOwner
|
||||||
|
@ -491,74 +474,74 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onParticipantsRemovedFromGroup(self, room, participants):
|
def onParticipantsRemovedFromGroup(self, room, participants):
|
||||||
self.logger.debug("Participants removed from group: %s, %s",
|
self.logger.debug(u"Participants removed from group: %s, %s",
|
||||||
room, participants)
|
room, participants)
|
||||||
self.groups[room].removeParticipants(participants)
|
self.groups[room].removeParticipants(participants)
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onContactStatusChanged(self, number, status):
|
def onContactStatusChanged(self, number, status):
|
||||||
self.logger.debug("%s changed their status to %s", number, status)
|
self.logger.debug(u"%s changed their status to %s", number, status)
|
||||||
try:
|
try:
|
||||||
buddy = self.buddies[number]
|
buddy = self.buddies[number]
|
||||||
buddy.statusMsg = status
|
buddy.statusMsg = status
|
||||||
self.buddies.updateSpectrum(buddy)
|
self.buddies.updateSpectrum(buddy)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.logger.debug("%s not in buddy list", number)
|
self.logger.debug(u"%s not in buddy list", number)
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onContactPictureChanged(self, number):
|
def onContactPictureChanged(self, number):
|
||||||
self.logger.debug("%s changed their profile picture", number)
|
self.logger.debug(u"%s changed their profile picture", number)
|
||||||
self.buddies.requestVCard(number)
|
self.buddies.requestVCard(number)
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onContactAdded(self, number, nick):
|
def onContactAdded(self, number, nick):
|
||||||
self.logger.debug("Adding new contact %s (%s)", nick, number)
|
self.logger.debug(u"Adding new contact %s (%s)", nick, number)
|
||||||
self.updateBuddy(number, nick, [])
|
self.updateBuddy(number, nick, [])
|
||||||
|
|
||||||
# Called by superclass
|
# Called by superclass
|
||||||
def onContactRemoved(self, number):
|
def onContactRemoved(self, number):
|
||||||
self.logger.debug("Removing contact %s", number)
|
self.logger.debug(u"Removing contact %s", number)
|
||||||
self.removeBuddy(number)
|
self.removeBuddy(number)
|
||||||
|
|
||||||
def onContactUpdated(self, oldnumber, newnumber):
|
def onContactUpdated(self, oldnumber, newnumber):
|
||||||
self.logger.debug("Contact has changed number from %s to %s",
|
self.logger.debug(u"Contact has changed number from %s to %s",
|
||||||
oldnumber, newnumber)
|
oldnumber, newnumber)
|
||||||
if newnumber in self.buddies:
|
if newnumber in self.buddies:
|
||||||
self.logger.warn("Contact %s exists, just updating", newnumber)
|
self.logger.warn(u"Contact %s exists, just updating", newnumber)
|
||||||
self.buddies.refresh(newnumber)
|
self.buddies.refresh(newnumber)
|
||||||
try:
|
try:
|
||||||
buddy = self.buddies[oldnumber]
|
buddy = self.buddies[oldnumber]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.logger.warn("Old contact (%s) not found. Adding new contact (%s)",
|
self.logger.warn(u"Old contact (%s) not found. Adding new contact (%s)",
|
||||||
oldnumber, newnumber)
|
oldnumber, newnumber)
|
||||||
nick = ""
|
nick = u""
|
||||||
else:
|
else:
|
||||||
self.removeBuddy(buddy.number)
|
self.removeBuddy(buddy.number)
|
||||||
nick = buddy.nick
|
nick = buddy.nick
|
||||||
self.updateBuddy(newnumber, nick, [])
|
self.updateBuddy(newnumber, nick, [])
|
||||||
|
|
||||||
def onPresenceReceived(self, _type, name, jid, lastseen):
|
def onPresenceReceived(self, _type, name, jid, lastseen):
|
||||||
self.logger.info("Presence received: %s %s %s %s", _type, name, jid, lastseen)
|
self.logger.info(u"Presence received: %s %s %s %s", _type, name, jid, lastseen)
|
||||||
buddy = jid.split("@")[0]
|
buddy = jid.split(u"@")[0]
|
||||||
try:
|
try:
|
||||||
buddy = self.buddies[buddy]
|
buddy = self.buddies[buddy]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# Sometimes whatsapp send our own presence
|
# Sometimes whatsapp send our own presence
|
||||||
if buddy != self.legacyName:
|
if buddy != self.legacyName:
|
||||||
self.logger.error("Buddy not found: %s", buddy)
|
self.logger.error(u"Buddy not found: %s", buddy)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (lastseen == str(buddy.lastseen)) and (_type == buddy.presence):
|
if (lastseen == str(buddy.lastseen)) and (_type == buddy.presence):
|
||||||
return
|
return
|
||||||
|
|
||||||
if ((lastseen != "deny") and (lastseen != None) and (lastseen != "none")):
|
if ((lastseen != u"deny") and (lastseen != None) and (lastseen != u"none")):
|
||||||
buddy.lastseen = int(lastseen)
|
buddy.lastseen = int(lastseen)
|
||||||
if (_type == None):
|
if (_type == None):
|
||||||
buddy.lastseen = time.time()
|
buddy.lastseen = time.time()
|
||||||
|
|
||||||
buddy.presence = _type
|
buddy.presence = _type
|
||||||
|
|
||||||
if _type == "unavailable":
|
if _type == u"unavailable":
|
||||||
self.onPresenceUnavailable(buddy)
|
self.onPresenceUnavailable(buddy)
|
||||||
else:
|
else:
|
||||||
self.onPresenceAvailable(buddy)
|
self.onPresenceAvailable(buddy)
|
||||||
|
@ -566,17 +549,17 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
|
|
||||||
def onPresenceAvailable(self, buddy):
|
def onPresenceAvailable(self, buddy):
|
||||||
self.logger.info("Is available: %s", buddy)
|
self.logger.info(u"Is available: %s", buddy)
|
||||||
self.buddies.updateSpectrum(buddy)
|
self.buddies.updateSpectrum(buddy)
|
||||||
|
|
||||||
def onPresenceUnavailable(self, buddy):
|
def onPresenceUnavailable(self, buddy):
|
||||||
self.logger.info("Is unavailable: %s", buddy)
|
self.logger.info(u"Is unavailable: %s", buddy)
|
||||||
self.buddies.updateSpectrum(buddy)
|
self.buddies.updateSpectrum(buddy)
|
||||||
|
|
||||||
# spectrum RequestMethods
|
# spectrum RequestMethods
|
||||||
def sendTypingStarted(self, buddy):
|
def sendTypingStarted(self, buddy):
|
||||||
if buddy != "bot":
|
if buddy != u"bot":
|
||||||
self.logger.info("Started typing: %s to %s", self.legacyName, buddy)
|
self.logger.info(u"Started typing: %s to %s", self.legacyName, buddy)
|
||||||
self.sendTyping(buddy, True)
|
self.sendTyping(buddy, True)
|
||||||
self.sendReadReceipts(buddy)
|
self.sendReadReceipts(buddy)
|
||||||
# If he is typing he is present
|
# If he is typing he is present
|
||||||
|
@ -645,33 +628,33 @@ class Session(YowsupApp):
|
||||||
break
|
break
|
||||||
if number is not None:
|
if number is not None:
|
||||||
self.logger.debug("Private message sent from %s to %s", self.legacyName, number)
|
self.logger.debug("Private message sent from %s to %s", self.legacyName, number)
|
||||||
waId = self.sendTextMessage(number + '@s.whatsapp.net', message)
|
waId = self.sendTextMessage(number + u'@s.whatsapp.net', message)
|
||||||
self.msgIDs[waId] = MsgIDs( ID, waId)
|
self.msgIDs[waId] = MsgIDs( ID, waId)
|
||||||
else:
|
else:
|
||||||
self.logger.error("Attempted to send private message to non-existent user")
|
self.logger.error("Attempted to send private message to non-existent user")
|
||||||
self.logger.debug("%s to %s in %s", self.legacyName, nick, room)
|
self.logger.debug("%s to %s in %s", self.legacyName, nick, room)
|
||||||
else:
|
else:
|
||||||
room = sender
|
room = sender
|
||||||
if message[0] == '\\' and message[:1] != '\\\\':
|
if message[0] == u'\\' and message[:1] != u'\\\\':
|
||||||
self.logger.debug("Executing command %s in %s", message, room)
|
self.logger.debug("Executing command %s in %s", message, room)
|
||||||
self.executeCommand(message, room)
|
self.executeCommand(message, room)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
group = self.groups[self._lengthenGroupId(room)]
|
group = self.groups[room]
|
||||||
self.logger.debug("Group Message from %s to %s Groups: %s",
|
self.logger.debug("Group Message from %s to %s Groups: %s",
|
||||||
group.nick , group , self.groups)
|
group.nick , group , self.groups)
|
||||||
self.backend.handleMessage(
|
self.backend.handleMessage(
|
||||||
self.user, room, message.decode('utf-8'), group.nick, xhtml=xhtml
|
self.user, room, message.decode(u'utf-8'), group.nick, xhtml=xhtml
|
||||||
)
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.logger.error('Group not found: %s', room)
|
self.logger.error(u'Group not found: %s', room)
|
||||||
|
|
||||||
if (".jpg" in message.lower()) or (".webp" in message.lower()):
|
if (".jpg" in message.lower()) or (".webp" in message.lower()):
|
||||||
self.sendImage(message, ID, room + '@g.us')
|
self.sendImage(message, ID, room + u'@g.us')
|
||||||
elif "geo:" in message.lower():
|
elif "geo:" in message.lower():
|
||||||
self._sendLocation(room + "@g.us", message, ID)
|
self._sendLocation(room + "@g.us", message, ID)
|
||||||
else:
|
else:
|
||||||
self.sendTextMessage(room + '@g.us', message)
|
self.sendTextMessage(room + u'@g.us', message)
|
||||||
else: # private msg
|
else: # private msg
|
||||||
buddy = sender
|
buddy = sender
|
||||||
# if message == "\\lastseen":
|
# if message == "\\lastseen":
|
||||||
|
@ -692,14 +675,14 @@ class Session(YowsupApp):
|
||||||
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 + u'@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)
|
#self.sendTextMessage(sender + u'@s.whatsapp.net', message)
|
||||||
|
|
||||||
def executeCommand(self, command, room):
|
def executeCommand(self, command, room):
|
||||||
if command == '\\leave':
|
if command == u'\\leave':
|
||||||
self.logger.debug("Leaving room %s", room)
|
self.logger.debug("Leaving room %s", room)
|
||||||
# Leave group on whatsapp side
|
# Leave group on whatsapp side
|
||||||
self.leaveGroup(room)
|
self.leaveGroup(room)
|
||||||
|
@ -720,9 +703,9 @@ class Session(YowsupApp):
|
||||||
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:
|
#with open(u'/opt/transwhat/map.jpg', 'rb') as imageFile:
|
||||||
# raw = base64.b64encode(imageFile.read())
|
# raw = base64.b64encode(imageFile.read())
|
||||||
latitude,longitude = message.split(':')[1].split(',')
|
latitude,longitude = message.split(u':')[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)
|
||||||
|
@ -781,7 +764,7 @@ class Session(YowsupApp):
|
||||||
self.bot.send("%s: %s" % (nick, messageContent))
|
self.bot.send("%s: %s" % (nick, messageContent))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.logger.warn("Group is not in group list")
|
self.logger.warn("Group is not in group list")
|
||||||
self.backend.handleMessage(self.user, self._shortenGroupId(room),
|
self.backend.handleMessage(self.user, room,
|
||||||
messageContent, number, "", timestamp)
|
messageContent, number, "", timestamp)
|
||||||
|
|
||||||
|
|
||||||
|
@ -799,7 +782,7 @@ class Session(YowsupApp):
|
||||||
def changeStatusMessage(self, statusMessage):
|
def changeStatusMessage(self, statusMessage):
|
||||||
if (statusMessage != self.statusMessage) or (self.initialized == False):
|
if (statusMessage != self.statusMessage) or (self.initialized == False):
|
||||||
self.statusMessage = statusMessage
|
self.statusMessage = statusMessage
|
||||||
self.setStatus(statusMessage.encode('utf-8'))
|
self.setStatus(statusMessage.encode(u'utf-8'))
|
||||||
self.logger.info("Status message changed: %s", statusMessage)
|
self.logger.info("Status message changed: %s", statusMessage)
|
||||||
|
|
||||||
#if self.initialized == False:
|
#if self.initialized == False:
|
||||||
|
@ -833,7 +816,7 @@ class Session(YowsupApp):
|
||||||
def createThumb(self, size=100, raw=False):
|
def createThumb(self, size=100, raw=False):
|
||||||
img = Image.open(self.imgPath)
|
img = Image.open(self.imgPath)
|
||||||
width, height = img.size
|
width, height = img.size
|
||||||
img_thumbnail = self.imgPath + '_thumbnail'
|
img_thumbnail = self.imgPath + u'_thumbnail'
|
||||||
|
|
||||||
if width > height:
|
if width > height:
|
||||||
nheight = float(height) / width * size
|
nheight = float(height) / width * size
|
||||||
|
@ -843,7 +826,7 @@ class Session(YowsupApp):
|
||||||
nheight = size
|
nheight = size
|
||||||
|
|
||||||
img.thumbnail((nwidth, nheight), Image.ANTIALIAS)
|
img.thumbnail((nwidth, nheight), Image.ANTIALIAS)
|
||||||
img.save(img_thumbnail, 'JPEG')
|
img.save(img_thumbnail, u'JPEG')
|
||||||
|
|
||||||
with open(img_thumbnail, 'rb') as imageFile:
|
with open(img_thumbnail, 'rb') as imageFile:
|
||||||
raw = base64.b64encode(imageFile.read())
|
raw = base64.b64encode(imageFile.read())
|
||||||
|
@ -852,38 +835,38 @@ class Session(YowsupApp):
|
||||||
|
|
||||||
# Not used
|
# Not used
|
||||||
def onLocationReceived(self, messageId, jid, name, preview, latitude, longitude, receiptRequested, isBroadcast):
|
def onLocationReceived(self, messageId, jid, name, preview, latitude, longitude, receiptRequested, isBroadcast):
|
||||||
buddy = jid.split("@")[0]
|
buddy = jid.split(u"@")[0]
|
||||||
self.logger.info("Location received from %s: %s, %s", buddy, latitude, longitude)
|
self.logger.info(u"Location received from %s: %s, %s", buddy, latitude, longitude)
|
||||||
|
|
||||||
url = "http://maps.google.de?%s" % urllib.urlencode({ "q": "%s %s" % (latitude, longitude) })
|
url = u"http://maps.google.de?%s" % urllib.urlencode({ u"q": u"%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(u"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(u"@")[0]
|
||||||
buddy = jid.split("@")[0]
|
buddy = jid.split(u"@")[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(u"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):
|
||||||
room = gjid.split("@")[0]
|
room = gjid.split(u"@")[0]
|
||||||
buddy = jid.split("@")[0]
|
buddy = jid.split(u"@")[0]
|
||||||
|
|
||||||
self.logger.info("Removed %s from room %s", buddy, room)
|
self.logger.info(u"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(u"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(u"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(u"notification_ack", (jid, messageId))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
6
utils.py
6
utils.py
|
@ -43,8 +43,10 @@ def ago(secs):
|
||||||
return "%d %s ago" % (diff, period)
|
return "%d %s ago" % (diff, period)
|
||||||
|
|
||||||
def softToUni(message):
|
def softToUni(message):
|
||||||
message = message.decode("utf-8")
|
# Deprecated
|
||||||
return e4u.translate(message, reverse=False, **e4u.SOFTBANK_TRANSLATE_PROFILE)
|
# message = message.decode("utf-8")
|
||||||
|
# return e4u.translate(message, reverse=False, **e4u.SOFTBANK_TRANSLATE_PROFILE)
|
||||||
|
return message
|
||||||
|
|
||||||
def decodePassword(password):
|
def decodePassword(password):
|
||||||
return base64.b64decode(bytes(password.encode("utf-8")))
|
return base64.b64decode(bytes(password.encode("utf-8")))
|
||||||
|
|
Loading…
Reference in a new issue