Make check_auth return True / False
This commit is contained in:
parent
a0f3c9ce11
commit
4400455769
13
README.md
13
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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user