Sourcery suggested changes - #2
Open
SourceryAI wants to merge 1 commit into
Open
Conversation
Sourcery refactored this code to make it cleaner and more readable. If you want Sourcery to review the full project or all new pull requests, add [Sourcery](https://github.com/sourcery-ai/sourcery) to your repo. We try to only open PRs that are helpful. If this isn't helpful or you have any feedback for us - please [let us know](mailto:github@sourcery.ai)!
SourceryAI
commented
Nov 15, 2021
Comment on lines
-39
to
+54
| if request.method == 'POST': | ||
| app.logger.info('/listen request:'+ "".join( request.data.splitlines())) | ||
| _json = request.get_json(force=True) | ||
| if request.method != 'POST': | ||
| return | ||
|
|
||
| if "challenge" in _json: | ||
| return _json["challenge"] | ||
| app.logger.info('/listen request:'+ "".join( request.data.splitlines())) | ||
| _json = request.get_json(force=True) | ||
|
|
||
| if "challenge" in _json: | ||
| return _json["challenge"] | ||
|
|
||
|
|
||
| if _json["event"]["type"] == "message": | ||
| if not 'sybtype' in _json["event"]: | ||
| r = requests.post(corezoidUrl,data=request.data) | ||
| app.logger.info('/corezoid answer:' + "".join(r.content.splitlines())) | ||
| return '{"OK":true}' | ||
| if _json["event"]["type"] == "message" and 'sybtype' not in _json["event"]: | ||
| r = requests.post(corezoidUrl,data=request.data) | ||
| app.logger.info('/corezoid answer:' + "".join(r.content.splitlines())) | ||
|
|
||
| return '{"OK":true}' | ||
|
|
||
| return '{"OK":true}' |
Author
There was a problem hiding this comment.
Function listen_skype refactored with the following changes:
- Add guard clause (last-if-guard)
- Merge nested if conditions (merge-nested-ifs)
- Simplify logical expression using De Morgan identities (de-morgan)
SourceryAI
commented
Nov 15, 2021
Comment on lines
-59
to
+85
| if request.method == 'POST': | ||
| app.logger.info('/send request:' + "".join(request.data.splitlines())) | ||
| _json = request.get_json(force=True) | ||
|
|
||
| if _json["event"]["type"] == "message": | ||
| if not 'subtype' in _json["event"]: | ||
| if _json["production"]: | ||
| clusterChat=clusterChat_prod | ||
|
|
||
| sk = Skype(skypeLogin, skypePass, 'session.tmp') # connect to Skype | ||
| chats = sk.chats # your conversations | ||
| ch = chats.chat(clusterChat) | ||
|
|
||
| r = requests.get(slackGetUserUrl, params={"token": slackToken, "user": _json["event"]["user"]}) | ||
| # print r.content | ||
| _user = jsonpickle.decode(r.content) | ||
| # ch.sendMsg( _user["user"]["real_name"] + ' via Slack: ' + _json["event"]["text"]) # plain-text message | ||
| ch.sendRaw(messagetype="RichText", contenttype="text", | ||
| content='<b>' + _user["user"]["real_name"] + ' via Slack: </b>' + remove_html_tags(_json["event"][ | ||
| "text"])) # plain-text message | ||
| app.logger.info(_user["user"]["real_name"] + ' via Slack: ' + remove_html_tags(_json["event"]["text"])) | ||
| return '{"OK":true}' | ||
| if request.method != 'POST': | ||
| return | ||
|
|
||
| app.logger.info('/send request:' + "".join(request.data.splitlines())) | ||
| _json = request.get_json(force=True) | ||
|
|
||
| if _json["event"]["type"] == "message" and 'subtype' not in _json["event"]: | ||
| if _json["production"]: | ||
| clusterChat=clusterChat_prod | ||
|
|
||
| sk = Skype(skypeLogin, skypePass, 'session.tmp') # connect to Skype | ||
| chats = sk.chats # your conversations | ||
| ch = chats.chat(clusterChat) | ||
|
|
||
| r = requests.get(slackGetUserUrl, params={"token": slackToken, "user": _json["event"]["user"]}) | ||
| # print r.content | ||
| _user = jsonpickle.decode(r.content) | ||
| # ch.sendMsg( _user["user"]["real_name"] + ' via Slack: ' + _json["event"]["text"]) # plain-text message | ||
| ch.sendRaw(messagetype="RichText", contenttype="text", | ||
| content='<b>' + _user["user"]["real_name"] + ' via Slack: </b>' + remove_html_tags(_json["event"][ | ||
| "text"])) # plain-text message | ||
| app.logger.info(_user["user"]["real_name"] + ' via Slack: ' + remove_html_tags(_json["event"]["text"])) | ||
|
|
||
| return '{"OK":true}' | ||
|
|
||
| return '{"OK":true}' | ||
|
|
Author
There was a problem hiding this comment.
Function send_skype refactored with the following changes:
- Add guard clause (last-if-guard)
- Merge nested if conditions (merge-nested-ifs)
- Simplify logical expression using De Morgan identities (de-morgan)
SourceryAI
commented
Nov 15, 2021
Comment on lines
-88
to
+109
| if request.method == 'POST': | ||
| app.logger.info('/send telegram request:' + "".join(request.data.splitlines())) | ||
| _json = request.get_json(force=True) | ||
| if request.method != 'POST': | ||
| return | ||
|
|
||
| if _json["event"]["type"] == "message": | ||
| if not 'subtype' in _json["event"]: | ||
| app.logger.info('/send telegram request:' + "".join(request.data.splitlines())) | ||
| _json = request.get_json(force=True) | ||
|
|
||
| if _json["event"]["type"] == "message" and 'subtype' not in _json["event"]: | ||
|
|
||
| sk = Skype(skypeLogin, skypePass, 'session.tmp') # connect to Skype | ||
| chats = sk.chats # your conversations | ||
| ch = chats.chat(clusterChat) | ||
| sk = Skype(skypeLogin, skypePass, 'session.tmp') # connect to Skype | ||
| chats = sk.chats # your conversations | ||
| ch = chats.chat(clusterChat) | ||
|
|
||
| ch.sendRaw(messagetype="RichText", contenttype="text", | ||
| content='<b>' + _json["event"]["user"] + ' via Telegram: </b>' + remove_html_tags(_json["event"][ | ||
| "text"])) # plain-text message | ||
| app.logger.info(_json["event"]["user"] + ' via Telegram: ' + remove_html_tags(_json["event"]["text"])) | ||
| return '{"OK":true}' | ||
| ch.sendRaw(messagetype="RichText", contenttype="text", | ||
| content='<b>' + _json["event"]["user"] + ' via Telegram: </b>' + remove_html_tags(_json["event"][ | ||
| "text"])) # plain-text message | ||
| app.logger.info(_json["event"]["user"] + ' via Telegram: ' + remove_html_tags(_json["event"]["text"])) | ||
|
|
||
| return '{"OK":true}' | ||
|
|
||
| return '{"OK":true}' |
Author
There was a problem hiding this comment.
Function send_skype_telegram refactored with the following changes:
- Add guard clause (last-if-guard)
- Merge nested if conditions (merge-nested-ifs)
- Simplify logical expression using De Morgan identities (de-morgan)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sourcery refactored this code to make it cleaner and more readable.
If you want Sourcery to review the full project or all new pull requests, add Sourcery to your repo.
We try to only open PRs that are helpful. If this isn't helpful or you have any feedback for us - please let us know!