generated from anoadragon453/nio-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from half-duplex/async-tokens
Async and data integrity protections from half-duplex
- Loading branch information
Showing
14 changed files
with
275 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[flake8] | ||
max-line-length = 99 | ||
import-order-style = google | ||
exclude = | ||
env/* | ||
venv/* | ||
accept-encodings = utf-8 | ||
ignore = E203 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Python lint | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.8] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements-dev.txt | ||
- name: Lint with black | ||
run: | | ||
black . --check | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --statistics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,54 @@ | ||
from nio import Api | ||
# coding=utf-8 | ||
|
||
from hashlib import sha256 | ||
def valid_token(token, tokens,sender): | ||
import logging | ||
|
||
from nio import Api | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def valid_token(token, tokens, sender): | ||
h = sha256() | ||
h.update(token.encode("utf-8")) | ||
msg = h.hexdigest() | ||
if msg in tokens: | ||
if tokens[msg] == 'unused': | ||
if tokens[msg] == "unused": | ||
return True, msg | ||
elif tokens[msg] == sender: | ||
return True, msg | ||
return False, "" | ||
return False, msg | ||
|
||
|
||
async def community_invite(client, group, sender):# | ||
async def community_invite(client, group, sender): # | ||
if not group: | ||
return | ||
path = "groups/{}/admin/users/invite/{}".format(group,sender) | ||
data = {"user_id":sender} | ||
path = "groups/{}/admin/users/invite/{}".format(group, sender) | ||
data = {"user_id": sender} | ||
query_parameters = {"access_token": client.access_token} | ||
path = Api._build_path(path, query_parameters) | ||
print(path) | ||
await client.send("PUT", | ||
path, | ||
Api.to_json(data), | ||
headers = {"Content-Type": "application/json"} | ||
) | ||
logging.debug("community_invite path: %r", path) | ||
await client.send( | ||
"PUT", path, Api.to_json(data), headers={"Content-Type": "application/json"} | ||
) | ||
return | ||
|
||
|
||
def is_admin(user): | ||
user = str(user) | ||
print(user) | ||
logging.debug("is_admin? %s", user) | ||
try: | ||
f = open("admin.csv", "rt") | ||
for nick in f.readlines(): | ||
print(nick) | ||
logging.debug("is_admin line: %s", nick) | ||
if user == nick.rstrip(): | ||
f.close() | ||
return True | ||
f.close() | ||
except FileNotFoundError: | ||
print("no admin.csv") | ||
logging.error("No admin.csv") | ||
return False | ||
|
||
|
||
def get_alias(roomid): | ||
return roomid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.