Changeset b09ce17 for python/wa.py
- Timestamp:
- 2015-05-21T03:43:06Z (9 years ago)
- Children:
- 433c90b
- Parents:
- 2b4402f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/wa.py
r2b4402f rb09ce17 62 62 def receive(self, entity): 63 63 print "Received: %r" % entity 64 print entity64 #print entity 65 65 super(BitlBeeLayer, self).receive(entity) 66 66 … … 68 68 """Send an entity into Yowsup, but through the correct thread.""" 69 69 print "Queueing: %s" % entity.getTag() 70 print entity70 #print entity 71 71 def doit(): 72 72 self.toLower(entity) … … 79 79 self.b.yow = self 80 80 self.cb.connected() 81 self.toLower(AvailablePresenceProtocolEntity()) 81 try: 82 self.toLower(PresenceProtocolEntity(name=self.b.setting("name"))) 83 except KeyError: 84 pass 85 # Should send the contact list now, but BitlBee hasn't given 86 # it yet. See set_away() and send_initial_contacts() below. 82 87 83 88 @ProtocolEntityCallback("failure") … … 89 94 90 95 def onEvent(self, event): 91 print event96 print "Received event: %s name %s" % (event, event.getName()) 92 97 if event.getName() == "disconnect": 93 98 self.getStack().execDetached(self.daemon.StopDaemon) … … 96 101 def onPresence(self, pres): 97 102 status = 8 # MOBILE 98 online = isinstance(pres, AvailablePresenceProtocolEntity) 99 if online: 100 status += 1 # ONLINE 101 imcb_buddy_status(pres.getFrom(), status, None, None) 103 if pres.getType() != "unavailable": 104 status |= 1 # ONLINE 105 self.cb.buddy_status(pres.getFrom(), status, None, None) 102 106 103 107 @ProtocolEntityCallback("message") 104 108 def onMessage(self, msg): 105 self.cb.buddy_msg(msg.getFrom(), msg.getBody(), 0, msg.getTimestamp())106 107 109 receipt = OutgoingReceiptProtocolEntity(msg.getId(), msg.getFrom()) 108 110 self.toLower(receipt) 111 112 if msg.getParticipant(): 113 group = self.b.groups.get(msg.getFrom(), None) 114 if not group: 115 self.cb.log("Warning: Activity in room %s" % msg.getFrom()) 116 return 117 self.cb.chat_msg(group["id"], msg.getParticipant(), msg.getBody(), 0, msg.getTimestamp()) 118 else: 119 self.cb.buddy_msg(msg.getFrom(), msg.getBody(), 0, msg.getTimestamp()) 109 120 110 121 @ProtocolEntityCallback("receipt") … … 141 152 print "New status for %s: %s" % (status.getFrom(), status.status) 142 153 143 @ProtocolEntityCallback("chatstate")144 def onChatstate(self, entity):145 print(entity)154 #@ProtocolEntityCallback("chatstate") 155 #def onChatstate(self, entity): 156 # print(entity) 146 157 147 158 … … 176 187 }, 177 188 } 178 AWAY_STATES = ["A vailable"]189 AWAY_STATES = ["Away"] 179 190 ACCOUNT_FLAGS = 14 # HANDLE_DOMAINS + STATUS_MESSAGE + LOCAL_CONTACTS 180 191 # TODO: LOCAL LIST CAUSES CRASH! … … 192 203 self.logging_in = True 193 204 self.contacts = set() 205 self.groups = {} 206 self.groups_by_id = {} 194 207 195 208 def keepalive(self): 196 self.yow.Ship(PingIqProtocolEntity(to="s.whatsapp.net")) 209 # Too noisy while debugging 210 pass 211 #self.yow.Ship(PingIqProtocolEntity(to="s.whatsapp.net")) 197 212 198 213 def logout(self): … … 216 231 self.yow.Ship(UnsubscribePresenceProtocolEntity(handle)) 217 232 218 def set_away(self, _state, status):233 def set_away(self, state, status): 219 234 # When our first status is set, we've finalised login. 220 235 # Which means sync the full contact list now. … … 223 238 self.send_initial_contacts() 224 239 225 # I think state is not supported? 226 print "Trying to set status to %r, %r" % (_state, status) 227 self.yow.Ship(SetStatusIqProtocolEntity(status)) 240 print "Trying to set status to %r, %r" % (state, status) 241 if state: 242 # Only one option offered so None = available, not None = away. 243 self.yow.Ship(AvailablePresenceProtocolEntity()) 244 else: 245 self.yow.Ship(UnavailablePresenceProtocolEntity()) 246 if status: 247 self.yow.Ship(SetStatusIqProtocolEntity(status)) 228 248 229 249 def send_initial_contacts(self): … … 236 256 self.yow.Ship(PresenceProtocolEntity(name=value)) 237 257 258 def chat_join(self, id, name, _nick, _password, settings): 259 print "New chat created with id: %d" % id 260 self.groups[name] = {"id": id, "name": name} 261 self.groups_by_id[id] = self.groups[name] 262 self.bee.chat_add_buddy(id, self.account["user"]) 263 264 def chat_msg(self, id, text, flags): 265 msg = TextMessageProtocolEntity(text, to=self.groups_by_id[id]["name"]) 266 self.yow.Ship(msg) 267 238 268 def build_stack(self, account): 269 self.account = account 239 270 creds = (account["user"].split("@")[0], account["pass"]) 240 271
Note: See TracChangeset
for help on using the changeset viewer.