Make check_auth return True / False

master
Tanner Collin 5 years ago
parent a0f3c9ce11
commit 4400455769
  1. 13
      README.md
  2. 25
      bwb/common.py
  3. 2
      setup.py

@ -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.

@ -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

@ -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',

Loading…
Cancel
Save