From 44004557693d3b8b1d0b9fd22599aa4d0ec83c3b Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 10 Sep 2019 03:07:39 +0000 Subject: [PATCH] Make check_auth return True / False --- README.md | 13 ++++++++++--- bwb/common.py | 25 ++++++++++++------------- setup.py | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4172ae4..5362926 100644 --- a/README.md +++ b/README.md @@ -36,16 +36,23 @@ When you see and authed '🤝', reply with *unauthed* '🤝'. ### Interaction -Run every incoming message through `bwb.parse()` since it's inexpensive. This will decrypt and remove base58 encoding. If the command is invalid, `text` will be `None`. +Run every incoming message through `bwb.parse()` since it's inexpensive. This will decrypt and remove base58 encoding. + +Once decoded, send it through `bwb.check_auth()` which will return `True` or `False` if the code is valid. Example: ```text +text = bwb.parse(text) if text.startswith('!'): ... +elif text.startswith('000000'): + text = text[6:] +elif bwb.check_auth(text): + authed = True + text = text[6:] else: - authed, text = bwb.parse(text) - if not text: return + return ``` Use `bwb.wrap()` to auth and encode outgoing commands. diff --git a/bwb/common.py b/bwb/common.py index 3e20bcc..d639c93 100644 --- a/bwb/common.py +++ b/bwb/common.py @@ -60,17 +60,6 @@ class common: return True return False - def check_auth(self, text): - try: - int(text[:6]) - except ValueError: - return False, None - - if self.check_otp(text[:6]): - return True, text[6:] - else: - return False, text[6:] - def to_b58(self, text): return 'l' + base58.b58encode(text.encode()).decode() @@ -125,5 +114,15 @@ class common: return text def parse(self, text): - decoded = self.dec(text) or self.from_b58(text) or text - return self.check_auth(decoded) # returns tuple + return self.dec(text) or self.from_b58(text) or text + + def check_auth(self, text): + try: + int(text[:6]) + except ValueError: + return False + + if self.check_otp(text[:6]): + return True + else: + return False diff --git a/setup.py b/setup.py index 176ecda..8549797 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with io.open('README.md', encoding='utf-8') as fh: long_description = fh.read() setuptools.setup(name='bwb', - version="1.0.6", + version='1.0.7', description='bwb', long_description=long_description, long_description_content_type='text/markdown',