Make check_auth return True / False

This commit is contained in:
Tanner Collin 2019-09-10 03:07:39 +00:00
parent a0f3c9ce11
commit 4400455769
3 changed files with 23 additions and 17 deletions

View File

@ -36,16 +36,23 @@ When you see and authed '🤝', reply with *unauthed* '🤝'.
### Interaction ### 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: Example:
```text ```text
text = bwb.parse(text)
if text.startswith('!'): if text.startswith('!'):
... ...
elif text.startswith('000000'):
text = text[6:]
elif bwb.check_auth(text):
authed = True
text = text[6:]
else: else:
authed, text = bwb.parse(text) return
if not text: return
``` ```
Use `bwb.wrap()` to auth and encode outgoing commands. Use `bwb.wrap()` to auth and encode outgoing commands.

View File

@ -60,17 +60,6 @@ class common:
return True return True
return False 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): def to_b58(self, text):
return 'l' + base58.b58encode(text.encode()).decode() return 'l' + base58.b58encode(text.encode()).decode()
@ -125,5 +114,15 @@ class common:
return text return text
def parse(self, text): def parse(self, text):
decoded = self.dec(text) or self.from_b58(text) or text return self.dec(text) or self.from_b58(text) or text
return self.check_auth(decoded) # returns tuple
def check_auth(self, text):
try:
int(text[:6])
except ValueError:
return False
if self.check_otp(text[:6]):
return True
else:
return False

View File

@ -5,7 +5,7 @@ with io.open('README.md', encoding='utf-8') as fh:
long_description = fh.read() long_description = fh.read()
setuptools.setup(name='bwb', setuptools.setup(name='bwb',
version="1.0.6", version='1.0.7',
description='bwb', description='bwb',
long_description=long_description, long_description=long_description,
long_description_content_type='text/markdown', long_description_content_type='text/markdown',