From fcc36517791fe08fcee83cfc5a3b20428b9ade4f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 10 Mar 2021 18:44:44 +0000 Subject: [PATCH 1/4] Pronomouce --- speaker.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/speaker.py b/speaker.py index f6fc31db8..2dde36ec2 100644 --- a/speaker.py +++ b/speaker.py @@ -90,6 +90,8 @@ def _speakerPronounce(baseDir: str, sayText: str, translate: {}) -> str: "Gmail": "G-mail", "OpenPGP": "Open P-G-P", "Tor": "Toor", + "memes": "meemes", + "Memes": "Meemes", "fwiw": "for what it's worth", "fyi": "for your information", "imho": "in my opinion", From 0b7cf977fbf6010111d0f8d7391bbc865e26707a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 10 Mar 2021 19:06:39 +0000 Subject: [PATCH 2/4] Sending replies via notification client --- notifications_client.py | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/notifications_client.py b/notifications_client.py index 533825585..8325d3395 100644 --- a/notifications_client.py +++ b/notifications_client.py @@ -23,6 +23,7 @@ from like import sendLikeViaServer from like import sendUndoLikeViaServer from follow import sendFollowRequestViaServer from follow import sendUnfollowRequestViaServer +from posts import sendPostViaServer def _waitForKeypress(timeout: int, debug: bool) -> str: @@ -137,7 +138,11 @@ def _sayCommand(sayStr: str, screenreader: str, systemLanguage, espeak) -def _replyToPost(postId: str, +def _replyToPost(session, postId: str, + baseDir: str, nickname: str, password: str, + domain: str, port: int, httpPrefix: str, + cachedWebfingers: {}, personCache: {}, + debug: bool, subject: str, screenreader: str, systemLanguage: str, espeak) -> None: """Use the notification client to send a reply to the most recent post """ @@ -171,6 +176,23 @@ def _replyToPost(postId: str, sayStr = 'Abandoning reply' _sayCommand(sayStr, screenreader, systemLanguage, espeak) return + ccUrl = None + followersOnly = False + attach = None + mediaType = None + attachedImageDescription = None + isArticle = False + subject = None + commentsEnabled = True + sendPostViaServer(__version__, + baseDir, session, nickname, password, + domain, port, + toNickname, toDomain, toPort, ccUrl, + httpPrefix, replyMessage, followersOnly, + commentsEnabled, attach, mediaType, + attachedImageDescription, + cachedWebfingers, personCache, isArticle, + debug, postId, postId, subject) def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, @@ -348,12 +370,21 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, _sayCommand(sayStr, screenreader, systemLanguage, espeak) if screenreader: - keyPress = _waitForKeypress(2, dbug) + keyPress = _waitForKeypress(2, debug) break elif keyPress == 'reply' or keyPress == 'r': if speakerJson.get('id'): postId = speakerJson['id'] - _replyToPost(postId, screenreader, systemLanguage, espeak) + subject = None + if speakerJson.get('summary'): + subject = speakerJson['summary'] + sessionReply = createSession(proxyType) + _replyToPost(sessionReply, postId, + baseDir, nickname, password, + domain, port, httpPrefix, + cachedWebfingers, personCache, + debug, subject, + screenreader, systemLanguage, espeak) print('') elif keyPress == 'like': if nameStr and gender and messageStr: From 63b7aa6d94632c6b68f48124df0f11486931c687 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 10 Mar 2021 19:11:14 +0000 Subject: [PATCH 3/4] Timeout when sending post via c2s --- posts.py | 2 +- session.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/posts.py b/posts.py index fcfe3bce4..e31a4e888 100644 --- a/posts.py +++ b/posts.py @@ -2141,7 +2141,7 @@ def sendPostViaServer(projectVersion: str, postDumps = json.dumps(postJsonObject) postResult = \ postJsonString(session, postDumps, [], - inboxUrl, headers, debug) + inboxUrl, headers, debug, 60) if not postResult: if debug: print('DEBUG: POST failed for c2s to '+inboxUrl) diff --git a/session.py b/session.py index 2661c6ffc..14e5b8666 100644 --- a/session.py +++ b/session.py @@ -173,7 +173,8 @@ def postJsonString(session, postJsonStr: str, federationList: [], inboxUrl: str, headers: {}, - debug: bool) -> (bool, bool): + debug: bool, + timeoutSec=30) -> (bool, bool): """Post a json message string to the inbox of another person The second boolean returned is true if the send is unauthorized NOTE: Here we post a string rather than the original json so that @@ -182,7 +183,8 @@ def postJsonString(session, postJsonStr: str, """ try: postResult = \ - session.post(url=inboxUrl, data=postJsonStr, headers=headers) + session.post(url=inboxUrl, data=postJsonStr, + headers=headers, timeout=timeoutSec) except requests.exceptions.RequestException as e: print('WARN: error during postJsonString requests') print(e) From d6efc44fe2b8917ed73aa76d36a5a477348a3914 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 10 Mar 2021 19:24:52 +0000 Subject: [PATCH 4/4] Timeout on post --- announce.py | 3 ++- availability.py | 2 +- delete.py | 2 +- follow.py | 4 ++-- like.py | 6 ++++-- posts.py | 8 +++++--- roles.py | 2 +- session.py | 54 +++++++++++++++++++++++++++++-------------------- shares.py | 5 +++-- skills.py | 3 ++- 10 files changed, 53 insertions(+), 36 deletions(-) diff --git a/announce.py b/announce.py index c8c54c61a..e8a3f2133 100644 --- a/announce.py +++ b/announce.py @@ -256,7 +256,8 @@ def sendAnnounceViaServer(baseDir: str, session, 'Content-type': 'application/json', 'Authorization': authHeader } - postResult = postJson(session, newAnnounceJson, [], inboxUrl, headers) + postResult = postJson(session, newAnnounceJson, [], inboxUrl, + headers, 30, True) if not postResult: print('WARN: Announce not posted') diff --git a/availability.py b/availability.py index d0c116c41..0b0f48847 100644 --- a/availability.py +++ b/availability.py @@ -142,7 +142,7 @@ def sendAvailabilityViaServer(baseDir: str, session, 'Authorization': authHeader } postResult = postJson(session, newAvailabilityJson, [], - inboxUrl, headers) + inboxUrl, headers, 30, True) if not postResult: print('WARN: failed to post availability') diff --git a/delete.py b/delete.py index 8d8d0b37a..027221abb 100644 --- a/delete.py +++ b/delete.py @@ -91,7 +91,7 @@ def sendDeleteViaServer(baseDir: str, session, 'Authorization': authHeader } postResult = \ - postJson(session, newDeleteJson, [], inboxUrl, headers) + postJson(session, newDeleteJson, [], inboxUrl, headers, 30, True) if not postResult: if debug: print('DEBUG: POST announce failed for c2s to ' + inboxUrl) diff --git a/follow.py b/follow.py index c3a383664..6c88c1adf 100644 --- a/follow.py +++ b/follow.py @@ -1004,7 +1004,7 @@ def sendFollowRequestViaServer(baseDir: str, session, 'Authorization': authHeader } postResult = \ - postJson(session, newFollowJson, [], inboxUrl, headers) + postJson(session, newFollowJson, [], inboxUrl, headers, 30, True) if not postResult: if debug: print('DEBUG: POST announce failed for c2s to ' + inboxUrl) @@ -1096,7 +1096,7 @@ def sendUnfollowRequestViaServer(baseDir: str, session, 'Authorization': authHeader } postResult = \ - postJson(session, unfollowJson, [], inboxUrl, headers) + postJson(session, unfollowJson, [], inboxUrl, headers, 30, True) if not postResult: if debug: print('DEBUG: POST announce failed for c2s to ' + inboxUrl) diff --git a/like.py b/like.py index 8975207f0..b80463c52 100644 --- a/like.py +++ b/like.py @@ -203,7 +203,8 @@ def sendLikeViaServer(baseDir: str, session, 'Content-type': 'application/json', 'Authorization': authHeader } - postResult = postJson(session, newLikeJson, [], inboxUrl, headers, 30) + postResult = postJson(session, newLikeJson, [], inboxUrl, + headers, 30, True) if not postResult: print('WARN: POST announce failed for c2s to ' + inboxUrl) return 5 @@ -282,7 +283,8 @@ def sendUndoLikeViaServer(baseDir: str, session, 'Content-type': 'application/json', 'Authorization': authHeader } - postResult = postJson(session, newUndoLikeJson, [], inboxUrl, headers) + postResult = postJson(session, newUndoLikeJson, [], inboxUrl, + headers, 30, True) if not postResult: print('WARN: POST announce failed for c2s to ' + inboxUrl) return 5 diff --git a/posts.py b/posts.py index e31a4e888..81d2c4345 100644 --- a/posts.py +++ b/posts.py @@ -2141,7 +2141,7 @@ def sendPostViaServer(projectVersion: str, postDumps = json.dumps(postJsonObject) postResult = \ postJsonString(session, postDumps, [], - inboxUrl, headers, debug, 60) + inboxUrl, headers, debug, 60, True) if not postResult: if debug: print('DEBUG: POST failed for c2s to '+inboxUrl) @@ -4184,7 +4184,8 @@ def sendBlockViaServer(baseDir: str, session, 'Content-type': 'application/json', 'Authorization': authHeader } - postResult = postJson(session, newBlockJson, [], inboxUrl, headers) + postResult = postJson(session, newBlockJson, [], inboxUrl, + headers, 30, True) if not postResult: print('WARN: Unable to post block') @@ -4266,7 +4267,8 @@ def sendUndoBlockViaServer(baseDir: str, session, 'Content-type': 'application/json', 'Authorization': authHeader } - postResult = postJson(session, newBlockJson, [], inboxUrl, headers) + postResult = postJson(session, newBlockJson, [], inboxUrl, + headers, 30, True) if not postResult: print('WARN: Unable to post block') diff --git a/roles.py b/roles.py index a0d055d9d..3569159d6 100644 --- a/roles.py +++ b/roles.py @@ -349,7 +349,7 @@ def sendRoleViaServer(baseDir: str, session, 'Authorization': authHeader } postResult = \ - postJson(session, newRoleJson, [], inboxUrl, headers) + postJson(session, newRoleJson, [], inboxUrl, headers, 30, True) if not postResult: if debug: print('DEBUG: POST announce failed for c2s to '+inboxUrl) diff --git a/session.py b/session.py index 14e5b8666..879e9bf88 100644 --- a/session.py +++ b/session.py @@ -137,12 +137,13 @@ def getJson(session, url: str, headers: {}, params: {}, def postJson(session, postJsonObject: {}, federationList: [], - inboxUrl: str, headers: {}, timeoutSec=60) -> str: + inboxUrl: str, headers: {}, timeoutSec=60, quiet=False) -> str: """Post a json message to the inbox of another person """ # check that we are posting to a permitted domain if not urlPermitted(inboxUrl, federationList): - print('postJson: ' + inboxUrl + ' not permitted') + if not quiet: + print('postJson: ' + inboxUrl + ' not permitted') return None try: @@ -151,18 +152,20 @@ def postJson(session, postJsonObject: {}, federationList: [], data=json.dumps(postJsonObject), headers=headers, timeout=timeoutSec) except requests.exceptions.RequestException as e: - print('ERROR: postJson requests failed ' + inboxUrl + ' ' + - json.dumps(postJsonObject) + ' ' + str(headers)) - print(e) + if not quiet: + print('ERROR: postJson requests failed ' + inboxUrl + ' ' + + json.dumps(postJsonObject) + ' ' + str(headers)) + print(e) return None except SocketError as e: - if e.errno == errno.ECONNRESET: + if not quiet and e.errno == errno.ECONNRESET: print('WARN: connection was reset during postJson') return None except ValueError as e: - print('ERROR: postJson failed ' + inboxUrl + ' ' + - json.dumps(postJsonObject) + ' ' + str(headers)) - print(e) + if not quiet: + print('ERROR: postJson failed ' + inboxUrl + ' ' + + json.dumps(postJsonObject) + ' ' + str(headers)) + print(e) return None if postResult: return postResult.text @@ -174,7 +177,8 @@ def postJsonString(session, postJsonStr: str, inboxUrl: str, headers: {}, debug: bool, - timeoutSec=30) -> (bool, bool): + timeoutSec=30, + quiet=False) -> (bool, bool): """Post a json message string to the inbox of another person The second boolean returned is true if the send is unauthorized NOTE: Here we post a string rather than the original json so that @@ -186,30 +190,36 @@ def postJsonString(session, postJsonStr: str, session.post(url=inboxUrl, data=postJsonStr, headers=headers, timeout=timeoutSec) except requests.exceptions.RequestException as e: - print('WARN: error during postJsonString requests') - print(e) + if not quiet: + print('WARN: error during postJsonString requests') + print(e) return None, None except SocketError as e: - if e.errno == errno.ECONNRESET: + if not quiet and e.errno == errno.ECONNRESET: print('WARN: connection was reset during postJsonString') - print('ERROR: postJsonString failed ' + inboxUrl + ' ' + - postJsonStr + ' ' + str(headers)) + if not quiet: + print('ERROR: postJsonString failed ' + inboxUrl + ' ' + + postJsonStr + ' ' + str(headers)) return None, None except ValueError as e: - print('WARN: error during postJsonString') - print(e) + if not quiet: + print('WARN: error during postJsonString') + print(e) return None, None if postResult.status_code < 200 or postResult.status_code > 202: if postResult.status_code >= 400 and \ postResult.status_code <= 405 and \ postResult.status_code != 404: - print('WARN: Post to ' + inboxUrl + ' is unauthorized. Code ' + - str(postResult.status_code)) + if not quiet: + print('WARN: Post to ' + inboxUrl + + ' is unauthorized. Code ' + + str(postResult.status_code)) return False, True else: - print('WARN: Failed to post to ' + inboxUrl + - ' with headers ' + str(headers)) - print('status code ' + str(postResult.status_code)) + if not quiet: + print('WARN: Failed to post to ' + inboxUrl + + ' with headers ' + str(headers)) + print('status code ' + str(postResult.status_code)) return False, False return True, False diff --git a/shares.py b/shares.py index 871b63ff5..cf726d1a6 100644 --- a/shares.py +++ b/shares.py @@ -406,7 +406,7 @@ def sendShareViaServer(baseDir, session, 'Authorization': authHeader } postResult = \ - postJson(session, newShareJson, [], inboxUrl, headers) + postJson(session, newShareJson, [], inboxUrl, headers, 30, True) if not postResult: if debug: print('DEBUG: POST announce failed for c2s to ' + inboxUrl) @@ -495,7 +495,8 @@ def sendUndoShareViaServer(baseDir: str, session, 'Authorization': authHeader } postResult = \ - postJson(session, undoShareJson, [], inboxUrl, headers) + postJson(session, undoShareJson, [], inboxUrl, + headers, 30, True) if not postResult: if debug: print('DEBUG: POST announce failed for c2s to ' + inboxUrl) diff --git a/skills.py b/skills.py index bd245de09..dd8ac8eac 100644 --- a/skills.py +++ b/skills.py @@ -160,7 +160,8 @@ def sendSkillViaServer(baseDir: str, session, nickname: str, password: str, 'Authorization': authHeader } postResult = \ - postJson(session, newSkillJson, [], inboxUrl, headers) + postJson(session, newSkillJson, [], inboxUrl, + headers, 30, True) if not postResult: if debug: print('DEBUG: POST announce failed for c2s to ' + inboxUrl)