Changeset 7051acb for python/wa.py
- Timestamp:
- 2015-11-25T02:46:09Z (9 years ago)
- Children:
- 63cad66
- Parents:
- e1352e15
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/wa.py
re1352e15 r7051acb 329 329 "type": "int", 330 330 }, 331 "reg_mode": { 332 "default": "sms", 333 }, 331 334 "name": { 332 335 "flags": 0x100, # NULL_OK 336 }, 337 # EW! Need to include this setting to trick BitlBee into 338 # doing registration instead of refusing to login w/o pwd. 339 # TODO: Make this a flag instead of faking oauth. 340 "oauth": { 341 "default": True, 333 342 }, 334 343 } … … 340 349 341 350 def login(self, account): 342 self.stack = self.build_stack(account) 351 super(YowsupIMPlugin, self).login(account) 352 self.account = account 353 self.number = self.account["user"].split("@")[0] 354 self.registering = False 355 if not self.account["pass"]: 356 return self._register() 357 358 self.stack = self._build_stack() 343 359 self.daemon = YowsupDaemon(name="yowsup") 344 360 self.daemon.stack = self.stack … … 366 382 self.stack.execDetached(self.daemon.StopDaemon) 367 383 384 def _register(self): 385 self.registering = True 386 self.bee.log("New account, starting registration") 387 from yowsup.registration import WACodeRequest 388 cr = WACodeRequest(str(self.setting("cc")), self.number, 389 "000", "000", "000", "000", 390 self.setting("reg_mode")) 391 res = cr.send() 392 res = {k: v for k, v in res.iteritems() if v is not None} 393 if res.get("status", "") != "sent": 394 self.bee.error("Failed to start registration: %r" % res) 395 self.bee.logout(False) 396 return 397 398 text = ("Registration request sent. You will receive a SMS or " 399 "call with a confirmation code. Please respond to this " 400 "message with that code.") 401 sender = "wa_%s" % self.number 402 self.bee.add_buddy(sender, "") 403 self.bee.buddy_msg(sender, text, 0, 0) 404 405 def _register_confirm(self, code): 406 from yowsup.registration import WARegRequest 407 code = code.strip().replace("-", "") 408 rr = WARegRequest(str(self.setting("cc")), self.number, code) 409 res = rr.send() 410 res = {k: v for k, v in res.iteritems() if v is not None} 411 if (res.get("status", "") != "ok") or (not self.get("pw", "")): 412 self.bee.error("Failed to finish registration: %r" % res) 413 self.bee.logout(False) 414 return 415 self.bee.log("Registration finished, attempting login") 416 self.bee.set_setstr("password", res["pw"]) 417 self.account["pass"] = res["pw"] 418 self.login(self.account) 419 368 420 def buddy_msg(self, to, text, flags): 421 if self.registering: 422 return self._register_confirm(text) 369 423 msg = TextMessageProtocolEntity(text, to=to) 370 424 self.yow.Ship(msg) … … 388 442 389 443 def set_set_name(self, _key, value): 390 self.yow.Ship(PresenceProtocolEntity(name=value)) 444 #self.yow.Ship(PresenceProtocolEntity(name=value)) 445 pass 391 446 392 447 def chat_join(self, id, name, _nick, _password, settings): … … 434 489 del group["id"] 435 490 436 def build_stack(self, account): 437 self.account = account 438 creds = (account["user"].split("@")[0], account["pass"]) 491 def _build_stack(self): 492 creds = (self.number, self.account["pass"]) 439 493 440 494 stack = (YowStackBuilder()
Note: See TracChangeset
for help on using the changeset viewer.