fix encoding issues
This commit is contained in:
parent
c005c31afa
commit
f25046de2d
|
@ -1,3 +1,6 @@
|
|||
# use unicode encoding for all literals by default (for python2.x)
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import protocol_pb2
|
||||
import socket
|
||||
import struct
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# use unicode encoding for all literals by default (for python2.x)
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import asyncore, socket
|
||||
import logging
|
||||
import sys
|
||||
|
|
30
buddy.py
30
buddy.py
|
@ -65,7 +65,7 @@ class BuddyList(dict):
|
|||
for buddy in buddies:
|
||||
number = buddy.buddyName
|
||||
nick = buddy.alias
|
||||
statusMsg = buddy.statusMessage.decode('utf-8')
|
||||
statusMsg = buddy.statusMessage
|
||||
groups = [g for g in buddy.group]
|
||||
image_hash = buddy.iconHash
|
||||
self[number] = Buddy(self.owner, number, nick, statusMsg,
|
||||
|
@ -79,7 +79,7 @@ class BuddyList(dict):
|
|||
self.session.sendSync(contacts, delta=False, interactive=True,
|
||||
success=self.onSync)
|
||||
|
||||
self.logger.debug("Roster add: %s", str(list(contacts)))
|
||||
self.logger.debug("Roster add: %s" % list(contacts))
|
||||
|
||||
for number in contacts:
|
||||
buddy = self[number]
|
||||
|
@ -90,21 +90,21 @@ class BuddyList(dict):
|
|||
|
||||
for number in existing:
|
||||
self.session.subscribePresence(number)
|
||||
self.logger.debug("%s is requesting statuses of: %s", self.user, existing)
|
||||
self.logger.debug("%s is requesting statuses of: %s" % (self.user, existing))
|
||||
self.session.requestStatuses(existing, success = self.onStatus)
|
||||
|
||||
self.logger.debug("Removing nonexisting buddies %s", nonexisting)
|
||||
self.logger.debug("Removing nonexisting buddies %s" % nonexisting)
|
||||
for number in nonexisting:
|
||||
self.remove(number)
|
||||
del self[number]
|
||||
|
||||
self.logger.debug("Removing invalid buddies %s", invalid)
|
||||
self.logger.debug("Removing invalid buddies %s" % invalid)
|
||||
for number in invalid:
|
||||
self.remove(number)
|
||||
del self[number]
|
||||
|
||||
def onStatus(self, contacts):
|
||||
self.logger.debug("%s received statuses of: %s", self.user, contacts)
|
||||
self.logger.debug("%s received statuses of: %s" % (self.user, contacts))
|
||||
for number, (status, time) in contacts.iteritems():
|
||||
buddy = self[number]
|
||||
if status is None:
|
||||
|
@ -127,7 +127,7 @@ class BuddyList(dict):
|
|||
else:
|
||||
buddy = Buddy(self.owner, number, nick, "", groups, image_hash)
|
||||
self[number] = buddy
|
||||
self.logger.debug("Roster add: %s", buddy)
|
||||
self.logger.debug("Roster add: %s" % buddy)
|
||||
self.session.sendSync([number], delta = True, interactive = True)
|
||||
self.session.subscribePresence(number)
|
||||
self.session.requestStatuses([number], success = self.onStatus)
|
||||
|
@ -151,9 +151,9 @@ class BuddyList(dict):
|
|||
|
||||
iconHash = buddy.image_hash if buddy.image_hash is not None else ""
|
||||
|
||||
self.logger.debug("Updating buddy %s (%s) in %s, image_hash = %s",
|
||||
buddy.nick, buddy.number, buddy.groups, iconHash)
|
||||
self.logger.debug("Status Message: %s", statusmsg)
|
||||
self.logger.debug("Updating buddy %s (%s) in %s, image_hash = %s" %
|
||||
(buddy.nick, buddy.number, buddy.groups, iconHash))
|
||||
self.logger.debug("Status Message: %s" % statusmsg)
|
||||
self.backend.handleBuddyChanged(self.user, buddy.number, buddy.nick,
|
||||
buddy.groups, status, statusMessage=statusmsg, iconHash=iconHash)
|
||||
|
||||
|
@ -190,7 +190,7 @@ class BuddyList(dict):
|
|||
buddynr = self.session.legacyName
|
||||
|
||||
# Get profile picture
|
||||
self.logger.debug('Requesting profile picture of %s', buddynr)
|
||||
self.logger.debug('Requesting profile picture of %s' % buddynr)
|
||||
response = deferred.Deferred()
|
||||
# Error probably means image doesn't exist
|
||||
error = deferred.Deferred()
|
||||
|
@ -201,12 +201,12 @@ class BuddyList(dict):
|
|||
pictureData = response.pictureData()
|
||||
# Send VCard
|
||||
if ID != None:
|
||||
call(self.logger.debug, 'Sending VCard (%s) with image id %s: %s',
|
||||
ID, response.pictureId(), pictureData.then(base64.b64encode))
|
||||
call(self.logger.debug, 'Sending VCard (%s) with image id %s: %s' %
|
||||
(ID, response.pictureId(), pictureData.then(base64.b64encode)))
|
||||
call(self.backend.handleVCard, self.user, ID, buddy, "", "",
|
||||
pictureData)
|
||||
# If error
|
||||
error.when(self.logger.debug, 'Sending VCard (%s) without image', ID)
|
||||
error.when(self.logger.debug, 'Sending VCard (%s) without image' % ID)
|
||||
error.when(self.backend.handleVCard, self.user, ID, buddy, "", "", "")
|
||||
|
||||
# Send image hash
|
||||
|
@ -219,7 +219,7 @@ class BuddyList(dict):
|
|||
nick = ""
|
||||
groups = []
|
||||
image_hash = pictureData.then(utils.sha1hash)
|
||||
call(self.logger.debug, 'Image hash is %s', image_hash)
|
||||
call(self.logger.debug, 'Image hash is %s' % image_hash)
|
||||
call(self.update, buddynr, nick, groups, image_hash)
|
||||
# No image
|
||||
error.when(self.logger.debug, 'No image')
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# use unicode encoding for all literals by default (for python2.x)
|
||||
from __future__ import unicode_literals
|
||||
from functools import partial
|
||||
|
||||
class Deferred(object):
|
||||
|
|
4
group.py
4
group.py
|
@ -1,3 +1,7 @@
|
|||
# use unicode encoding for all literals by default (for python2.x)
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
__author__ = "Steffen Vogel"
|
||||
__copyright__ = "Copyright 2015, Steffen Vogel"
|
||||
__license__ = "GPLv3"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# use unicode encoding for all literals by default (for python2.x)
|
||||
from __future__ import unicode_literals
|
||||
from Spectrum2 import protocol_pb2
|
||||
|
||||
from yowsupwrapper import YowsupApp
|
||||
|
@ -40,7 +42,7 @@ class RegisterSession(YowsupApp):
|
|||
'bot', 'Number does not start with provided country code')
|
||||
else:
|
||||
self.backend.handleMessage(self.user, 'bot', 'Requesting sms code')
|
||||
self.logger.debug('Requesting SMS code for %s', self.user)
|
||||
self.logger.debug('Requesting SMS code for %s' % self.user)
|
||||
self.countryCode = country_code
|
||||
self._requestSMSCodeNonBlock()
|
||||
elif buddy == 'bot' and self.state == self.WANT_SMS:
|
||||
|
@ -51,7 +53,7 @@ class RegisterSession(YowsupApp):
|
|||
self.backend.handleMessage(self.user,
|
||||
'bot', 'Invalid code. Must be of the form XXX-XXX.')
|
||||
else:
|
||||
self.logger.warn('Unauthorised user (%s) attempting to send messages',
|
||||
self.logger.warn('Unauthorised user (%s) attempting to send messages' %
|
||||
self.user)
|
||||
self.backend.handleMessage(self.user, buddy,
|
||||
'You are not logged in yet. You can only send messages to bot.')
|
||||
|
@ -104,7 +106,7 @@ class RegisterSession(YowsupApp):
|
|||
for k, v in result.items():
|
||||
if v is None:
|
||||
continue
|
||||
out.append("%s: %s" %(k, v.encode("utf-8") if type(v) is unistr else v))
|
||||
out.append("%s: %s" % (k, v))
|
||||
|
||||
return "\n".join(out)
|
||||
|
||||
|
|
198
session.py
198
session.py
|
@ -54,12 +54,12 @@ class MsgIDs:
|
|||
|
||||
|
||||
class Session(YowsupApp):
|
||||
broadcast_prefix = u'\U0001F4E2 '
|
||||
broadcast_prefix = '\U0001F4E2 '
|
||||
|
||||
def __init__(self, backend, user, legacyName, extra):
|
||||
super(Session, self).__init__()
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
self.logger.info("Created: %s", legacyName)
|
||||
self.logger.info("Created: %s" % legacyName)
|
||||
|
||||
self.backend = backend
|
||||
self.user = user
|
||||
|
@ -99,12 +99,12 @@ class Session(YowsupApp):
|
|||
self.logout()
|
||||
|
||||
def logout(self):
|
||||
self.logger.info("%s logged out", self.user)
|
||||
self.logger.info("%s logged out" % self.user)
|
||||
super(Session, self).logout()
|
||||
self.loggedIn = False
|
||||
|
||||
def login(self, password):
|
||||
self.logger.info("%s attempting login", self.user)
|
||||
self.logger.info("%s attempting login" % self.user)
|
||||
self.password = password
|
||||
self.shouldBeConncted = True
|
||||
super(Session, self).login(self.legacyName, self.password)
|
||||
|
@ -126,14 +126,14 @@ class Session(YowsupApp):
|
|||
rooms.append([self._shortenGroupId(room), group.subject])
|
||||
text.append(self._shortenGroupId(room) + '@' + self.backend.spectrum_jid + ' :' + group.subject)
|
||||
|
||||
self.logger.debug("Got rooms: %s", rooms)
|
||||
self.logger.debug("Got rooms: %s" % rooms)
|
||||
self.backend.handleRoomList(rooms)
|
||||
message = "Note, you are a participant of the following groups:\n" +\
|
||||
'\n'.join(text) + '\nIf you do not join them you will lose messages'
|
||||
message = "Note, you are a participant of the following groups:\n" + \
|
||||
"\n".join(text) + "\nIf you do not join them you will lose messages"
|
||||
#self.bot.send(message)
|
||||
|
||||
def _updateGroups(self, response, request):
|
||||
self.logger.debug('Received groups list %s', response)
|
||||
self.logger.debug('Received groups list %s' % response)
|
||||
groups = response.getGroups()
|
||||
for group in groups:
|
||||
room = group.getId()
|
||||
|
@ -159,8 +159,8 @@ class Session(YowsupApp):
|
|||
msg = self.groupOfflineQueue[room].pop(0)
|
||||
self.backend.handleMessage(self.user, room, msg[1],
|
||||
msg[0], "", msg[2])
|
||||
self.logger.debug("Send queued group message to: %s %s %s",
|
||||
msg[0],msg[1], msg[2])
|
||||
self.logger.debug("Send queued group message to: %s %s %s" %
|
||||
(msg[0],msg[1], msg[2]))
|
||||
self.gotGroupList = True
|
||||
for room, nick in self.joinRoomQueue:
|
||||
self.joinRoom(room, nick)
|
||||
|
@ -173,8 +173,8 @@ class Session(YowsupApp):
|
|||
return
|
||||
room = self._lengthenGroupId(room)
|
||||
if room in self.groups:
|
||||
self.logger.info("Joining room: %s room=%s, nick=%s",
|
||||
self.legacyName, room, nick)
|
||||
self.logger.info("Joining room: %s room=%s, nick=%s" %
|
||||
(self.legacyName, room, nick))
|
||||
|
||||
group = self.groups[room]
|
||||
group.joined = True
|
||||
|
@ -188,24 +188,24 @@ class Session(YowsupApp):
|
|||
group.sendParticipantsToSpectrum(self.legacyName)
|
||||
self.backend.handleSubject(self.user, self._shortenGroupId(room),
|
||||
group.subject, ownerNick)
|
||||
self.logger.debug("Room subject: room=%s, subject=%s",
|
||||
room, group.subject)
|
||||
self.logger.debug("Room subject: room=%s, subject=%s" %
|
||||
(room, group.subject))
|
||||
self.backend.handleRoomNicknameChanged(
|
||||
self.user, self._shortenGroupId(room), group.subject
|
||||
)
|
||||
else:
|
||||
self.logger.warn("Room doesn't exist: %s", room)
|
||||
self.logger.warn("Room doesn't exist: %s" % room)
|
||||
|
||||
def leaveRoom(self, room):
|
||||
if room in self.groups:
|
||||
self.logger.info("Leaving room: %s room=%s", self.legacyName, room)
|
||||
self.logger.info("Leaving room: %s room=%s" % (self.legacyName, room))
|
||||
group = self.groups[room]
|
||||
group.joined = False
|
||||
else:
|
||||
self.logger.warn("Room doesn't exist: %s. Unable to leave.", room)
|
||||
self.logger.warn("Room doesn't exist: %s. Unable to leave." % room)
|
||||
|
||||
def _lastSeen(self, number, seconds):
|
||||
self.logger.debug("Last seen %s at %s seconds" % (number, str(seconds)))
|
||||
self.logger.debug("Last seen %s at %s seconds" % (number, seconds))
|
||||
if seconds < 60:
|
||||
self.onPresenceAvailable(number)
|
||||
else:
|
||||
|
@ -215,12 +215,12 @@ class Session(YowsupApp):
|
|||
if _from.split('@')[0] == buddy:
|
||||
self.sendReceipt(_id, _from, 'read', participant)
|
||||
self.recvMsgIDs.remove((_id, _from, participant))
|
||||
self.logger.debug("Send read receipt to %s (ID: %s)", _from, _id)
|
||||
self.logger.debug("Send read receipt to %s (ID: %s)" % (_from, _id))
|
||||
|
||||
# Called by superclass
|
||||
def onAuthSuccess(self, status, kind, creation,
|
||||
expiration, props, nonce, t):
|
||||
self.logger.info("Auth success: %s", self.user)
|
||||
self.logger.info("Auth success: %s" % self.user)
|
||||
|
||||
self.backend.handleConnected(self.user)
|
||||
self.backend.handleBuddyChanged(self.user, "bot", self.bot.name,
|
||||
|
@ -249,7 +249,7 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onAuthFailed(self, reason):
|
||||
self.logger.info("Auth failed: %s (%s)", self.user, reason)
|
||||
self.logger.info("Auth failed: %s (%s)" % (self.user, reason))
|
||||
self.backend.handleDisconnected(self.user, 0, reason)
|
||||
self.password = None
|
||||
self.loggedIn = False
|
||||
|
@ -261,9 +261,8 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onReceipt(self, _id, _from, timestamp, type, participant, offline, items):
|
||||
self.logger.debug("received receipt, sending ack: " +
|
||||
' '.join(map(str, [_id, _from, timestamp,
|
||||
type, participant, offline, items]))
|
||||
self.logger.debug("received receipt, sending ack: %s" %
|
||||
[ _id, _from, timestamp, type, participant, offline, items ]
|
||||
)
|
||||
try:
|
||||
number = _from.split('@')[0]
|
||||
|
@ -272,29 +271,26 @@ class Session(YowsupApp):
|
|||
if self.msgIDs[_id].cnt == 2:
|
||||
del self.msgIDs[_id]
|
||||
except KeyError:
|
||||
self.logger.error("Message %s not found. Unable to send ack", _id)
|
||||
self.logger.error("Message %s not found. Unable to send ack" % _id)
|
||||
|
||||
# Called by superclass
|
||||
def onAck(self, _id, _class, _from, timestamp):
|
||||
self.logger.debug('received ack ' +
|
||||
' '.join(map(str, [_id, _class, _from,timestamp,]))
|
||||
)
|
||||
self.logger.debug('received ack: %s' % [ _id, _class, _from, timestamp ])
|
||||
|
||||
# Called by superclass
|
||||
def onTextMessage(self, _id, _from, to, notify, timestamp, participant,
|
||||
offline, retry, body):
|
||||
self.logger.debug('received TextMessage' +
|
||||
' '.join(map(str, [
|
||||
_id, _from, to, notify, timestamp,
|
||||
participant, offline, retry, body
|
||||
]))
|
||||
|
||||
self.logger.debug('received TextMessage: %s' %
|
||||
[_id, _from, to, notify, timestamp,
|
||||
participant, offline, retry, body]
|
||||
)
|
||||
buddy = _from.split('@')[0]
|
||||
messageContent = utils.softToUni(body)
|
||||
self.sendReceipt(_id, _from, None, participant)
|
||||
self.recvMsgIDs.append((_id, _from, participant))
|
||||
self.logger.info("Message received from %s to %s: %s (at ts=%s)",
|
||||
buddy, self.legacyName, messageContent, timestamp)
|
||||
self.logger.info("Message received from %s to %s: %s (at ts=%s)" %
|
||||
(buddy, self.legacyName, messageContent, timestamp))
|
||||
if participant is not None: # Group message or broadcast
|
||||
partname = participant.split('@')[0]
|
||||
if _from.split('@')[1] == 'broadcast': # Broadcast message
|
||||
|
@ -310,7 +306,7 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onImage(self, image):
|
||||
self.logger.debug('Received image message %s', str(image))
|
||||
self.logger.debug('Received image message: %s' % image)
|
||||
buddy = image._from.split('@')[0]
|
||||
participant = image.participant
|
||||
if image.caption is None:
|
||||
|
@ -333,7 +329,7 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onAudio(self, audio):
|
||||
self.logger.debug('Received audio message %s', str(audio))
|
||||
self.logger.debug('Received audio message: %s' % audio)
|
||||
buddy = audio._from.split('@')[0]
|
||||
participant = audio.participant
|
||||
message = audio.url
|
||||
|
@ -352,7 +348,7 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onVideo(self, video):
|
||||
self.logger.debug('Received video message %s', str(video))
|
||||
self.logger.debug('Received video message: %s' % video)
|
||||
buddy = video._from.split('@')[0]
|
||||
participant = video.participant
|
||||
|
||||
|
@ -378,8 +374,8 @@ class Session(YowsupApp):
|
|||
participant = location.participant
|
||||
latlong = 'geo:' + latitude + ',' + longitude
|
||||
|
||||
self.logger.debug("Location received from %s: %s, %s",
|
||||
buddy, latitude, longitude)
|
||||
self.logger.debug("Location received from %s: %s, %s" %
|
||||
(buddy, latitude, longitude))
|
||||
|
||||
|
||||
if participant is not None: # Group message
|
||||
|
@ -404,10 +400,8 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onVCard(self, _id, _from, name, card_data, to, notify, timestamp, participant):
|
||||
self.logger.debug('received VCard' +
|
||||
' '.join(map(str, [
|
||||
_id, _from, name, card_data, to, notify, timestamp, participant
|
||||
]))
|
||||
self.logger.debug('received VCard: %s' %
|
||||
[ _id, _from, name, card_data, to, notify, timestamp, participant ]
|
||||
)
|
||||
message = "Received VCard (not implemented yet)"
|
||||
buddy = _from.split("@")[0]
|
||||
|
@ -428,14 +422,14 @@ class Session(YowsupApp):
|
|||
|
||||
def transferFile(self, buddy, name, data):
|
||||
# Not working
|
||||
self.logger.debug('transfering file %s', name)
|
||||
self.logger.debug('transfering file: %s' % name)
|
||||
self.backend.handleFTStart(self.user, buddy, name, len(data))
|
||||
self.backend.handleFTData(0, data)
|
||||
self.backend.handleFTFinish(self.user, buddy, name, len(data), 0)
|
||||
|
||||
# Called by superclass
|
||||
def onContactTyping(self, buddy):
|
||||
self.logger.info("Started typing: %s", buddy)
|
||||
self.logger.info("Started typing: %s" % buddy)
|
||||
if buddy != 'bot':
|
||||
self.sendPresence(True)
|
||||
self.backend.handleBuddyTyping(self.user, buddy)
|
||||
|
@ -445,7 +439,7 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onContactPaused(self, buddy):
|
||||
self.logger.info("Paused typing: %s", buddy)
|
||||
self.logger.info("Paused typing: %s" % buddy)
|
||||
if buddy != 'bot':
|
||||
self.backend.handleBuddyTyped(self.user, buddy)
|
||||
self.timer = Timer(3, self.backend.handleBuddyStoppedTyping,
|
||||
|
@ -453,7 +447,7 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onAddedToGroup(self, group):
|
||||
self.logger.debug("Added to group: %s", group)
|
||||
self.logger.debug("Added to group: %s" % group)
|
||||
room = group.getGroupId()
|
||||
owner = group.getCreatorJid(full = False)
|
||||
subjectOwner = group.getSubjectOwnerJid(full = False)
|
||||
|
@ -466,7 +460,7 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onParticipantsAddedToGroup(self, group):
|
||||
self.logger.debug("Participants added to group: %s", group)
|
||||
self.logger.debug("Participants added to group: %s" % group)
|
||||
room = group.getGroupId().split('@')[0]
|
||||
self.groups[room].addParticipants(group.getParticipants(), self.buddies, self.legacyName)
|
||||
self.groups[room].sendParticipantsToSpectrum(self.legacyName)
|
||||
|
@ -474,12 +468,13 @@ class Session(YowsupApp):
|
|||
# Called by superclass
|
||||
def onSubjectChanged(self, room, subject, subjectOwner, timestamp):
|
||||
self.logger.debug(
|
||||
"onSubjectChange(rrom=%s, subject=%s, subjectOwner=%s, timestamp=%s)",
|
||||
room, subject, subjectOwner, timestamp)
|
||||
"onSubjectChange(rrom=%s, subject=%s, subjectOwner=%s, timestamp=%s)" %
|
||||
(room, subject, subjectOwner, timestamp)
|
||||
)
|
||||
try:
|
||||
group = self.groups[room]
|
||||
except KeyError:
|
||||
self.logger.error("Subject of non-existant group (%s) changed", group)
|
||||
self.logger.error("Subject of non-existant group (%s) changed" % group)
|
||||
else:
|
||||
group.subject = subject
|
||||
group.subjectOwner = subjectOwner
|
||||
|
@ -491,46 +486,46 @@ class Session(YowsupApp):
|
|||
|
||||
# Called by superclass
|
||||
def onParticipantsRemovedFromGroup(self, room, participants):
|
||||
self.logger.debug("Participants removed from group: %s, %s",
|
||||
room, participants)
|
||||
self.logger.debug("Participants removed from group: %s, %s" %
|
||||
(room, participants))
|
||||
self.groups[room].removeParticipants(participants)
|
||||
|
||||
# Called by superclass
|
||||
def onContactStatusChanged(self, number, status):
|
||||
self.logger.debug("%s changed their status to %s", number, status)
|
||||
self.logger.debug("%s changed their status to %s" % (number, status))
|
||||
try:
|
||||
buddy = self.buddies[number]
|
||||
buddy.statusMsg = status
|
||||
self.buddies.updateSpectrum(buddy)
|
||||
except KeyError:
|
||||
self.logger.debug("%s not in buddy list", number)
|
||||
self.logger.debug("%s not in buddy list" % number)
|
||||
|
||||
# Called by superclass
|
||||
def onContactPictureChanged(self, number):
|
||||
self.logger.debug("%s changed their profile picture", number)
|
||||
self.logger.debug("%s changed their profile picture" % number)
|
||||
self.buddies.requestVCard(number)
|
||||
|
||||
# Called by superclass
|
||||
def onContactAdded(self, number, nick):
|
||||
self.logger.debug("Adding new contact %s (%s)", nick, number)
|
||||
self.logger.debug("Adding new contact %s (%s)" % (nick, number))
|
||||
self.updateBuddy(number, nick, [])
|
||||
|
||||
# Called by superclass
|
||||
def onContactRemoved(self, number):
|
||||
self.logger.debug("Removing contact %s", number)
|
||||
self.logger.debug("Removing contact %s" % number)
|
||||
self.removeBuddy(number)
|
||||
|
||||
def onContactUpdated(self, oldnumber, newnumber):
|
||||
self.logger.debug("Contact has changed number from %s to %s",
|
||||
oldnumber, newnumber)
|
||||
self.logger.debug("Contact has changed number from %s to %s" %
|
||||
(oldnumber, newnumber))
|
||||
if newnumber in self.buddies:
|
||||
self.logger.warn("Contact %s exists, just updating", newnumber)
|
||||
self.logger.warn("Contact %s exists, just updating" % newnumber)
|
||||
self.buddies.refresh(newnumber)
|
||||
try:
|
||||
buddy = self.buddies[oldnumber]
|
||||
except KeyError:
|
||||
self.logger.warn("Old contact (%s) not found. Adding new contact (%s)",
|
||||
oldnumber, newnumber)
|
||||
self.logger.warn("Old contact (%s) not found. Adding new contact (%s)" %
|
||||
(oldnumber, newnumber))
|
||||
nick = ""
|
||||
else:
|
||||
self.removeBuddy(buddy.number)
|
||||
|
@ -538,17 +533,17 @@ class Session(YowsupApp):
|
|||
self.updateBuddy(newnumber, nick, [])
|
||||
|
||||
def onPresenceReceived(self, _type, name, jid, lastseen):
|
||||
self.logger.info("Presence received: %s %s %s %s", _type, name, jid, lastseen)
|
||||
self.logger.info("Presence received: %s %s %s %s" % (_type, name, jid, lastseen))
|
||||
buddy = jid.split("@")[0]
|
||||
try:
|
||||
buddy = self.buddies[buddy]
|
||||
except KeyError:
|
||||
# Sometimes whatsapp send our own presence
|
||||
if buddy != self.legacyName:
|
||||
self.logger.error("Buddy not found: %s", buddy)
|
||||
self.logger.error("Buddy not found: %s" % buddy)
|
||||
return
|
||||
|
||||
if (lastseen == str(buddy.lastseen)) and (_type == buddy.presence):
|
||||
if (lastseen == buddy.lastseen) and (_type == buddy.presence):
|
||||
return
|
||||
|
||||
if ((lastseen != "deny") and (lastseen != None) and (lastseen != "none")):
|
||||
|
@ -566,17 +561,17 @@ class Session(YowsupApp):
|
|||
|
||||
|
||||
def onPresenceAvailable(self, buddy):
|
||||
self.logger.info("Is available: %s", buddy)
|
||||
self.logger.info("Is available: %s" % buddy)
|
||||
self.buddies.updateSpectrum(buddy)
|
||||
|
||||
def onPresenceUnavailable(self, buddy):
|
||||
self.logger.info("Is unavailable: %s", buddy)
|
||||
self.logger.info("Is unavailable: %s" % buddy)
|
||||
self.buddies.updateSpectrum(buddy)
|
||||
|
||||
# spectrum RequestMethods
|
||||
def sendTypingStarted(self, buddy):
|
||||
if buddy != "bot":
|
||||
self.logger.info("Started typing: %s to %s", self.legacyName, buddy)
|
||||
self.logger.info("Started typing: %s to %s" % (self.legacyName, buddy))
|
||||
self.sendTyping(buddy, True)
|
||||
self.sendReadReceipts(buddy)
|
||||
# If he is typing he is present
|
||||
|
@ -586,7 +581,7 @@ class Session(YowsupApp):
|
|||
|
||||
def sendTypingStopped(self, buddy):
|
||||
if buddy != "bot":
|
||||
self.logger.info("Stopped typing: %s to %s", self.legacyName, buddy)
|
||||
self.logger.info("Stopped typing: %s to %s" % (self.legacyName, buddy))
|
||||
self.sendTyping(buddy, False)
|
||||
self.sendReadReceipts(buddy)
|
||||
|
||||
|
@ -602,7 +597,7 @@ class Session(YowsupApp):
|
|||
|
||||
# Success
|
||||
path = success.arg(0)
|
||||
call(self.logger.info, "Success: Image downloaded to %s", path)
|
||||
call(self.logger.info, "Success: Image downloaded to %s" % path)
|
||||
pathWithExt = path.then(lambda p: p + "." + imgType)
|
||||
call(os.rename, path, pathWithExt)
|
||||
pathJpg = path.then(lambda p: p + ".jpg")
|
||||
|
@ -610,7 +605,7 @@ class Session(YowsupApp):
|
|||
im = call(Image.open, pathWithExt)
|
||||
call(im.save, pathJpg)
|
||||
call(os.remove, pathWithExt)
|
||||
call(self.logger.info, "Sending image to %s", to)
|
||||
call(self.logger.info, "Sending image to %s" % to)
|
||||
waId = deferred.Deferred()
|
||||
call(super(Session, self).sendImage, to, pathJpg, onSuccess = waId.run)
|
||||
call(self.setWaId, ID, waId)
|
||||
|
@ -626,10 +621,9 @@ class Session(YowsupApp):
|
|||
self.msgIDs[waId] = MsgIDs(XmppId, waId)
|
||||
|
||||
def sendMessageToWA(self, sender, message, ID, xhtml=""):
|
||||
self.logger.info("Message sent from %s to %s: %s (xhtml=%s)",
|
||||
self.legacyName, sender, message, xhtml)
|
||||
self.logger.info("Message sent from %s to %s: %s (xhtml=%s)" %
|
||||
(self.legacyName, sender, message, xhtml))
|
||||
|
||||
message = message.encode("utf-8")
|
||||
self.sendReadReceipts(sender)
|
||||
|
||||
if sender == "bot":
|
||||
|
@ -644,27 +638,27 @@ class Session(YowsupApp):
|
|||
number = othernumber
|
||||
break
|
||||
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)
|
||||
self.msgIDs[waId] = MsgIDs( ID, waId)
|
||||
else:
|
||||
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:
|
||||
room = sender
|
||||
if message[0] == '\\' and message[:1] != '\\\\':
|
||||
self.logger.debug("Executing command %s in %s", message, room)
|
||||
self.logger.debug("Executing command %s in %s" % (message, room))
|
||||
self.executeCommand(message, room)
|
||||
else:
|
||||
try:
|
||||
group = self.groups[self._lengthenGroupId(room)]
|
||||
self.logger.debug("Group Message from %s to %s Groups: %s",
|
||||
group.nick , group , self.groups)
|
||||
self.logger.debug("Group Message from %s to %s Groups: %s" %
|
||||
(group.nick , group , self.groups))
|
||||
self.backend.handleMessage(
|
||||
self.user, room, message.decode('utf-8'), group.nick, xhtml=xhtml
|
||||
self.user, room, message, group.nick, xhtml=xhtml
|
||||
)
|
||||
except KeyError:
|
||||
self.logger.error('Group not found: %s', room)
|
||||
self.logger.error('Group not found: %s' % room)
|
||||
|
||||
if (".jpg" in message.lower()) or (".webp" in message.lower()):
|
||||
self.sendImage(message, ID, room + '@g.us')
|
||||
|
@ -695,12 +689,12 @@ class Session(YowsupApp):
|
|||
waId = self.sendTextMessage(sender + '@s.whatsapp.net', message)
|
||||
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):
|
||||
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)
|
||||
# Delete Room on spectrum side
|
||||
|
@ -713,7 +707,7 @@ class Session(YowsupApp):
|
|||
def onSuccess(buddy, lastseen):
|
||||
timestamp = time.localtime(time.localtime()-lastseen)
|
||||
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), lastseen))
|
||||
def onError(errorIqEntity, originalIqEntity):
|
||||
self.sendMessageToXMPP(errorIqEntity.getFrom(), "LastSeen Error")
|
||||
|
||||
|
@ -725,7 +719,7 @@ class Session(YowsupApp):
|
|||
latitude,longitude = message.split(':')[1].split(',')
|
||||
waId = self.sendLocation(buddy, float(latitude), float(longitude))
|
||||
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))
|
||||
|
||||
|
||||
|
||||
|
@ -734,22 +728,22 @@ class Session(YowsupApp):
|
|||
timestamp = time.strftime("%Y%m%dT%H%M%S", time.gmtime(timestamp))
|
||||
|
||||
if self.initialized == False:
|
||||
self.logger.debug("Message queued from %s to %s: %s",
|
||||
buddy, self.legacyName, messageContent)
|
||||
self.logger.debug("Message queued from %s to %s: %s" %
|
||||
(buddy, self.legacyName, messageContent))
|
||||
self.offlineQueue.append((buddy, messageContent, timestamp))
|
||||
else:
|
||||
self.logger.debug("Message sent from %s to %s: %s", buddy,
|
||||
self.legacyName, messageContent)
|
||||
self.logger.debug("Message sent from %s to %s: %s" % (
|
||||
buddy, self.legacyName, messageContent))
|
||||
self.backend.handleMessage(self.user, buddy, messageContent, "",
|
||||
"", timestamp)
|
||||
|
||||
def sendGroupMessageToXMPP(self, room, number, messageContent, timestamp = u"", defaultname = u""):
|
||||
def sendGroupMessageToXMPP(self, room, number, messageContent, timestamp = "", defaultname = ""):
|
||||
if timestamp:
|
||||
timestamp = time.strftime("%Y%m%dT%H%M%S", time.gmtime(timestamp))
|
||||
|
||||
if self.initialized == False:
|
||||
self.logger.debug("Group message queued from %s to %s: %s",
|
||||
number, room, messageContent)
|
||||
self.logger.debug("Group message queued from %s to %s: %s" %
|
||||
(number, room, messageContent))
|
||||
|
||||
if room not in self.groupOfflineQueue:
|
||||
self.groupOfflineQueue[room] = [ ]
|
||||
|
@ -758,8 +752,8 @@ class Session(YowsupApp):
|
|||
(number, messageContent, timestamp)
|
||||
)
|
||||
else:
|
||||
self.logger.debug("Group message sent from %s to %s: %s",
|
||||
number, room, messageContent)
|
||||
self.logger.debug("Group message sent from %s to %s: %s" %
|
||||
(number, room, messageContent))
|
||||
try:
|
||||
group = self.groups[room]
|
||||
# Update nickname
|
||||
|
@ -787,7 +781,7 @@ class Session(YowsupApp):
|
|||
|
||||
def changeStatus(self, status):
|
||||
if status != self.status:
|
||||
self.logger.info("Status changed: %s", status)
|
||||
self.logger.info("Status changed: %s" % status)
|
||||
self.status = status
|
||||
|
||||
if status == protocol_pb2.STATUS_ONLINE \
|
||||
|
@ -799,8 +793,8 @@ class Session(YowsupApp):
|
|||
def changeStatusMessage(self, statusMessage):
|
||||
if (statusMessage != self.statusMessage) or (self.initialized == False):
|
||||
self.statusMessage = statusMessage
|
||||
self.setStatus(statusMessage.encode('utf-8'))
|
||||
self.logger.info("Status message changed: %s", statusMessage)
|
||||
self.setStatus(statusMessage)
|
||||
self.logger.info("Status message changed: {0}".format(statusMessage))
|
||||
|
||||
#if self.initialized == False:
|
||||
# self.sendOfflineMessages()
|
||||
|
@ -824,7 +818,7 @@ class Session(YowsupApp):
|
|||
|
||||
def removeBuddy(self, buddy):
|
||||
if buddy != "bot":
|
||||
self.logger.info("Buddy removed: %s", buddy)
|
||||
self.logger.info("Buddy removed: %s" % buddy)
|
||||
self.buddies.remove(buddy)
|
||||
|
||||
def requestVCard(self, buddy, ID=None):
|
||||
|
@ -853,7 +847,7 @@ class Session(YowsupApp):
|
|||
# Not used
|
||||
def onLocationReceived(self, messageId, jid, name, preview, latitude, longitude, receiptRequested, isBroadcast):
|
||||
buddy = jid.split("@")[0]
|
||||
self.logger.info("Location received from %s: %s, %s", buddy, latitude, longitude)
|
||||
self.logger.info("Location received from %s: %s, %s" % (buddy, latitude, longitude))
|
||||
|
||||
url = "http://maps.google.de?%s" % urllib.urlencode({ "q": "%s %s" % (latitude, longitude) })
|
||||
self.sendMessageToXMPP(buddy, utils.shorten(url))
|
||||
|
@ -872,7 +866,7 @@ class Session(YowsupApp):
|
|||
room = gjid.split("@")[0]
|
||||
buddy = jid.split("@")[0]
|
||||
|
||||
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
|
||||
if receiptRequested: self.call("notification_ack", (gjid, messageId))
|
||||
|
|
21
transwhat.py
Executable file → Normal file
21
transwhat.py
Executable file → Normal file
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# use unicode encoding for all literals by default (for python2.x)
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
__author__ = "Steffen Vogel"
|
||||
__copyright__ = "Copyright 2015, Steffen Vogel"
|
||||
__license__ = "GPLv3"
|
||||
|
@ -23,6 +27,7 @@ __email__ = "post@steffenvogel.de"
|
|||
along with transWhat. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
|
||||
import argparse
|
||||
import traceback
|
||||
import logging
|
||||
|
@ -43,25 +48,21 @@ from yowsup.stacks import YowStack
|
|||
# Arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--debug', action='store_true')
|
||||
parser.add_argument('--log', type=str)
|
||||
parser.add_argument('--host', type=str, required=True)
|
||||
parser.add_argument('--port', type=int, required=True)
|
||||
parser.add_argument('--service.backend_id', metavar="ID", type=int, required=True)
|
||||
parser.add_argument('config', type=str)
|
||||
parser.add_argument('-j', type=str, required=True)
|
||||
parser.add_argument('-j', type=str, metavar="JID", required=True)
|
||||
|
||||
args, unknown = parser.parse_known_args()
|
||||
|
||||
YowConstants.PATH_STORAGE='/var/lib/spectrum2/' + args.j
|
||||
|
||||
if args.log is None:
|
||||
args.log = '/var/log/spectrum2/' + args.j + '/backends/backend.log'
|
||||
|
||||
loggingfile = '/var/log/spectrum2/' + args.j + '/backends/backend.log'
|
||||
# Logging
|
||||
logging.basicConfig(
|
||||
filename=args.log,
|
||||
format = "%(asctime)-15s %(levelname)s %(name)s: %(message)s",
|
||||
level = logging.DEBUG if args.debug else logging.INFO
|
||||
logging.basicConfig( \
|
||||
filename=loggingfile,\
|
||||
format = "%(asctime)-15s %(levelname)s %(name)s: %(message)s", \
|
||||
level = logging.DEBUG if args.debug else logging.INFO \
|
||||
)
|
||||
|
||||
# Handler
|
||||
|
|
8
utils.py
8
utils.py
|
@ -1,3 +1,7 @@
|
|||
# use unicode encoding for all literals by default (for python2.x)
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
__author__ = "Steffen Vogel"
|
||||
__copyright__ = "Copyright 2015, Steffen Vogel"
|
||||
__license__ = "GPLv3"
|
||||
|
@ -25,6 +29,7 @@ import e4u
|
|||
import base64
|
||||
import hashlib
|
||||
|
||||
|
||||
def ago(secs):
|
||||
periods = ["second", "minute", "hour", "day", "week", "month", "year", "decade"]
|
||||
lengths = [60, 60, 24, 7,4.35, 12, 10]
|
||||
|
@ -43,11 +48,10 @@ def ago(secs):
|
|||
return "%d %s ago" % (diff, period)
|
||||
|
||||
def softToUni(message):
|
||||
message = message.decode("utf-8")
|
||||
return e4u.translate(message, reverse=False, **e4u.SOFTBANK_TRANSLATE_PROFILE)
|
||||
|
||||
def decodePassword(password):
|
||||
return base64.b64decode(bytes(password.encode("utf-8")))
|
||||
return base64.b64decode(bytes(password))
|
||||
|
||||
def sha1hash(data):
|
||||
return hashlib.sha1(data).hexdigest()
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
# use unicode encoding for all literals by default (for python2.x)
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
__author__ = "Steffen Vogel"
|
||||
__copyright__ = "Copyright 2015, Steffen Vogel"
|
||||
__license__ = "GPLv3"
|
||||
|
@ -21,6 +25,7 @@ __email__ = "post@steffenvogel.de"
|
|||
along with transWhat. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
|
||||
from Spectrum2.backend import SpectrumBackend
|
||||
from Spectrum2 import protocol_pb2
|
||||
|
||||
|
@ -29,6 +34,7 @@ from registersession import RegisterSession
|
|||
|
||||
import logging
|
||||
|
||||
|
||||
class WhatsAppBackend(SpectrumBackend):
|
||||
def __init__(self, io, spectrum_jid):
|
||||
SpectrumBackend.__init__(self)
|
||||
|
@ -43,7 +49,7 @@ class WhatsAppBackend(SpectrumBackend):
|
|||
|
||||
# RequestsHandlers
|
||||
def handleLoginRequest(self, user, legacyName, password, extra):
|
||||
self.logger.debug("handleLoginRequest(user=%s, legacyName=%s)", user, legacyName)
|
||||
self.logger.debug("handleLoginRequest(user=%s, legacyName=%s)" % (user, legacyName))
|
||||
# Key word means we should register a new password
|
||||
if password == 'register':
|
||||
if user not in self.sessions:
|
||||
|
@ -55,13 +61,14 @@ class WhatsAppBackend(SpectrumBackend):
|
|||
self.sessions[user].login(password)
|
||||
|
||||
def handleLogoutRequest(self, user, legacyName):
|
||||
self.logger.debug("handleLogoutRequest(user=%s, legacyName=%s)", user, legacyName)
|
||||
self.logger.debug("handleLogoutRequest(user=%s, legacyName=%s)" % (user, legacyName))
|
||||
if user in self.sessions:
|
||||
self.sessions[user].logout()
|
||||
del self.sessions[user]
|
||||
|
||||
def handleMessageSendRequest(self, user, buddy, message, xhtml="", ID=""):
|
||||
self.logger.debug("handleMessageSendRequest(user=%s, buddy=%s, message=%s, xhtml=%s, ID=%s)", user, buddy, message, xhtml, ID)
|
||||
self.logger.debug("handleMessageSendRequest(user=%s, buddy=%s, message=%s, xhtml=%s, ID=%s)" %
|
||||
( user, buddy, message, xhtml, ID))
|
||||
# For some reason spectrum occasionally sends to identical messages to
|
||||
# a buddy, one to the bare jid and one to the /bot resource. This
|
||||
# causes duplicate messages. Thus we should not send consecutive
|
||||
|
@ -73,63 +80,63 @@ class WhatsAppBackend(SpectrumBackend):
|
|||
self.lastMsgId[user] = ID
|
||||
|
||||
def handleJoinRoomRequest(self, user, room, nickname, pasword):
|
||||
self.logger.debug("handleJoinRoomRequest(user=%s, room=%s, nickname=%s)", user, room, nickname)
|
||||
self.logger.debug("handleJoinRoomRequest(user=%s, room=%s, nickname=%s)" % (user, room, nickname))
|
||||
self.sessions[user].joinRoom(room, nickname)
|
||||
|
||||
def handleLeaveRoomRequest(self, user, room):
|
||||
self.logger.debug("handleLeaveRoomRequest(user=%s, room=%s)", user, room)
|
||||
self.logger.debug("handleLeaveRoomRequest(user=%s, room=%s)" % (user, room))
|
||||
self.sessions[user].leaveRoom(room)
|
||||
|
||||
def handleStatusChangeRequest(self, user, status, statusMessage):
|
||||
self.logger.debug("handleStatusChangeRequest(user=%s, status=%d, statusMessage=%s)", user, status, statusMessage)
|
||||
self.logger.debug("handleStatusChangeRequest(user=%s, status=%d, statusMessage=%s)" % (user, status, statusMessage))
|
||||
self.sessions[user].changeStatusMessage(statusMessage)
|
||||
self.sessions[user].changeStatus(status)
|
||||
|
||||
def handleBuddies(self, buddies):
|
||||
"""Called when user logs in. Used to initialize roster."""
|
||||
self.logger.debug("handleBuddies(buddies=%s)", buddies)
|
||||
self.logger.debug("handleBuddies(buddies=%s)" % buddies)
|
||||
buddies = [b for b in buddies.buddy]
|
||||
if len(buddies) > 0:
|
||||
user = buddies[0].userName
|
||||
self.sessions[user].loadBuddies(buddies)
|
||||
|
||||
def handleBuddyUpdatedRequest(self, user, buddy, nick, groups):
|
||||
self.logger.debug("handleBuddyUpdatedRequest(user=%s, buddy=%s, nick=%s, groups=%s)", user, buddy, nick, str(groups))
|
||||
self.logger.debug("handleBuddyUpdatedRequest(user=%s, buddy=%s, nick=%s, groups=%s)" % (user, buddy, nick, groups))
|
||||
self.sessions[user].updateBuddy(buddy, nick, groups)
|
||||
|
||||
def handleBuddyRemovedRequest(self, user, buddy, groups):
|
||||
self.logger.debug("handleBuddyRemovedRequest(user=%s, buddy=%s, groups=%s)", user, buddy, str(groups))
|
||||
self.logger.debug("handleBuddyRemovedRequest(user=%s, buddy=%s, groups=%s)" % (user, buddy, groups))
|
||||
self.sessions[user].removeBuddy(buddy)
|
||||
|
||||
def handleTypingRequest(self, user, buddy):
|
||||
self.logger.debug("handleTypingRequest(user=%s, buddy=%s)", user, buddy)
|
||||
self.logger.debug("handleTypingRequest(user=%s, buddy=%s)" % (user, buddy))
|
||||
self.sessions[user].sendTypingStarted(buddy)
|
||||
|
||||
def handleTypedRequest(self, user, buddy):
|
||||
self.logger.debug("handleTypedRequest(user=%s, buddy=%s)", user, buddy)
|
||||
self.logger.debug("handleTypedRequest(user=%s, buddy=%s)" % (user, buddy))
|
||||
self.sessions[user].sendTypingStopped(buddy)
|
||||
|
||||
def handleStoppedTypingRequest(self, user, buddy):
|
||||
self.logger.debug("handleStoppedTypingRequest(user=%s, buddy=%s)", user, buddy)
|
||||
self.logger.debug("handleStoppedTypingRequest(user=%s, buddy=%s)" % (user, buddy))
|
||||
self.sessions[user].sendTypingStopped(buddy)
|
||||
|
||||
def handleVCardRequest(self, user, buddy, ID):
|
||||
self.logger.debug("handleVCardRequest(user=%s, buddy=%s, ID=%s)", user, buddy, ID)
|
||||
self.logger.debug("handleVCardRequest(user=%s, buddy=%s, ID=%s)" % (user, buddy, ID))
|
||||
self.sessions[user].requestVCard(buddy, ID)
|
||||
|
||||
def handleVCardUpdatedRequest(self, user, photo, nickname):
|
||||
self.logger.debug("handleVCardUpdatedRequest(user=%s, nickname=%s)", user, nickname)
|
||||
self.logger.debug("handleVCardUpdatedRequest(user=%s, nickname=%s)" % (user, nickname))
|
||||
self.sessions[user].setProfilePicture(photo)
|
||||
|
||||
def handleBuddyBlockToggled(self, user, buddy, blocked):
|
||||
self.logger.debug("handleBuddyBlockedToggled(user=%s, buddy=%s, blocked=%s)", user, buddy, blocked)
|
||||
self.logger.debug("handleBuddyBlockedToggled(user=%s, buddy=%s, blocked=%s)" % (user, buddy, blocked))
|
||||
|
||||
def relogin(self, user, legacyName, password, extra):
|
||||
"""
|
||||
Used to re-initialize the session object. Used when finished with
|
||||
registration session and the user needs to login properly
|
||||
"""
|
||||
self.logger.debug("relogin(user=%s, legacyName=%s)", user, legacyName)
|
||||
self.logger.debug("relogin(user=%s, legacyName=%s)" % (user, legacyName))
|
||||
# Change password in spectrum database
|
||||
self.handleQuery('register %s %s %s' % (user, legacyName, password))
|
||||
# Key word means we should register a new password
|
||||
|
@ -144,8 +151,8 @@ class WhatsAppBackend(SpectrumBackend):
|
|||
pass
|
||||
|
||||
def handleFTStartRequest(self, user, buddy, fileName, size, ftID):
|
||||
self.logger.debug('File send request %s, for user %s, from %s, size: %s',
|
||||
fileName, user, buddy, size)
|
||||
self.logger.debug('File send request %s, for user %s, from %s, size: %s' %
|
||||
(fileName, user, buddy, size))
|
||||
|
||||
def handleFTFinishRequest(self, user, buddy, fileName, size, ftID):
|
||||
pass
|
||||
|
@ -160,7 +167,7 @@ class WhatsAppBackend(SpectrumBackend):
|
|||
pass
|
||||
|
||||
def handleMessageAckRequest(self, user, legacyName, ID = 0):
|
||||
self.logger.info("Meassage ACK request for %s !!",legacyName)
|
||||
self.logger.info("Meassage ACK request for %s !!" % legacyName)
|
||||
|
||||
def sendData(self, data):
|
||||
self.io.sendData(data)
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# use unicode encoding for all literals by default (for python2.x)
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from yowsup import env
|
||||
|
@ -264,7 +267,7 @@ class YowsupApp(object):
|
|||
- phone_number: (str) The cellphone number of the person to
|
||||
subscribe to
|
||||
"""
|
||||
self.logger.debug("Subscribing to Presence updates from %s", (phone_number))
|
||||
self.logger.debug("Subscribing to Presence updates from %s" % phone_number)
|
||||
jid = phone_number + '@s.whatsapp.net'
|
||||
entity = SubscribePresenceProtocolEntity(jid)
|
||||
self.sendEntity(entity)
|
||||
|
@ -394,7 +397,7 @@ class YowsupApp(object):
|
|||
iq = GetStatusesIqProtocolEntity([c + '@s.whatsapp.net' for c in contacts])
|
||||
def onSuccess(response, request):
|
||||
if success is not None:
|
||||
self.logger.debug("Received Statuses %s", response)
|
||||
self.logger.debug("Received Statuses %s" % response)
|
||||
s = {}
|
||||
for k, v in response.statuses.iteritems():
|
||||
s[k.split('@')[0]] = v
|
||||
|
@ -706,7 +709,7 @@ class YowsupApp(object):
|
|||
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
|
||||
entity = bytearray(entity)
|
||||
))
|
||||
|
||||
def sendIq(self, iq, onSuccess = None, onError = None):
|
||||
|
@ -798,7 +801,7 @@ class YowsupAppLayer(YowInterfaceLayer):
|
|||
"""
|
||||
Sends ack automatically
|
||||
"""
|
||||
self.logger.debug("Received notification (%s): %s", type(entity), entity)
|
||||
self.logger.debug("Received notification (%s): %s" % (type(entity), entity))
|
||||
self.toLower(entity.ack())
|
||||
if isinstance(entity, CreateGroupsNotificationProtocolEntity):
|
||||
self.caller.onAddedToGroup(entity)
|
||||
|
@ -840,7 +843,7 @@ class YowsupAppLayer(YowInterfaceLayer):
|
|||
|
||||
@ProtocolEntityCallback('message')
|
||||
def onMessageReceived(self, entity):
|
||||
self.logger.debug("Received Message: %s", entity)
|
||||
self.logger.debug("Received Message: %s" % entity)
|
||||
if entity.getType() == MessageProtocolEntity.MESSAGE_TYPE_TEXT:
|
||||
self.caller.onTextMessage(
|
||||
entity._id,
|
||||
|
|
Loading…
Reference in a new issue