2021-03-09 12:03:50 +00:00
|
|
|
__filename__ = "notifications_client.py"
|
2021-03-04 13:57:30 +00:00
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
|
|
|
__version__ = "1.2.0"
|
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
|
|
|
|
|
|
|
import os
|
|
|
|
import html
|
|
|
|
import time
|
2021-03-04 15:21:38 +00:00
|
|
|
import sys
|
|
|
|
import select
|
2021-03-12 10:06:24 +00:00
|
|
|
from pathlib import Path
|
2021-03-11 20:33:45 +00:00
|
|
|
from random import randint
|
2021-03-12 14:55:37 +00:00
|
|
|
from utils import getStatusNumber
|
2021-03-12 10:06:24 +00:00
|
|
|
from utils import saveJson
|
2021-03-10 13:38:11 +00:00
|
|
|
from utils import getNicknameFromActor
|
|
|
|
from utils import getDomainFromActor
|
2021-03-09 22:12:12 +00:00
|
|
|
from utils import getFullDomain
|
2021-03-12 12:04:34 +00:00
|
|
|
from utils import isPGPEncrypted
|
2021-03-04 13:57:30 +00:00
|
|
|
from session import createSession
|
|
|
|
from speaker import getSpeakerFromServer
|
|
|
|
from speaker import getSpeakerPitch
|
|
|
|
from speaker import getSpeakerRate
|
|
|
|
from speaker import getSpeakerRange
|
2021-03-10 13:04:22 +00:00
|
|
|
from like import sendLikeViaServer
|
2021-03-10 13:07:24 +00:00
|
|
|
from like import sendUndoLikeViaServer
|
2021-03-10 13:38:11 +00:00
|
|
|
from follow import sendFollowRequestViaServer
|
|
|
|
from follow import sendUnfollowRequestViaServer
|
2021-03-10 19:06:39 +00:00
|
|
|
from posts import sendPostViaServer
|
2021-03-10 21:45:34 +00:00
|
|
|
from announce import sendAnnounceViaServer
|
2021-03-11 17:15:32 +00:00
|
|
|
from pgp import pgpDecrypt
|
2021-03-11 20:33:45 +00:00
|
|
|
from pgp import hasLocalPGPkey
|
|
|
|
from pgp import pgpEncryptToActor
|
2021-03-04 14:36:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _waitForKeypress(timeout: int, debug: bool) -> str:
|
|
|
|
"""Waits for a keypress with a timeout
|
|
|
|
Returns the key pressed, or None on timeout
|
|
|
|
"""
|
2021-03-04 15:21:38 +00:00
|
|
|
i, o, e = select.select([sys.stdin], [], [], timeout)
|
|
|
|
|
|
|
|
if (i):
|
2021-03-04 15:27:27 +00:00
|
|
|
text = sys.stdin.readline().strip()
|
2021-03-04 15:21:38 +00:00
|
|
|
if debug:
|
2021-03-04 15:27:27 +00:00
|
|
|
print("Text entered: " + text)
|
|
|
|
return text
|
2021-03-04 15:21:38 +00:00
|
|
|
else:
|
2021-03-04 14:36:24 +00:00
|
|
|
if debug:
|
2021-03-04 15:21:38 +00:00
|
|
|
print("Timeout")
|
2021-03-04 14:36:24 +00:00
|
|
|
return None
|
2021-03-04 13:57:30 +00:00
|
|
|
|
|
|
|
|
2021-03-04 14:54:30 +00:00
|
|
|
def _speakerEspeak(espeak, pitch: int, rate: int, srange: int,
|
|
|
|
sayText: str) -> None:
|
|
|
|
"""Speaks the given text with espeak
|
|
|
|
"""
|
|
|
|
espeak.set_parameter(espeak.Parameter.Pitch, pitch)
|
|
|
|
espeak.set_parameter(espeak.Parameter.Rate, rate)
|
|
|
|
espeak.set_parameter(espeak.Parameter.Range, srange)
|
|
|
|
espeak.synth(html.unescape(sayText))
|
|
|
|
|
|
|
|
|
|
|
|
def _speakerPicospeaker(pitch: int, rate: int, systemLanguage: str,
|
|
|
|
sayText: str) -> None:
|
|
|
|
speakerLang = 'en-GB'
|
|
|
|
if systemLanguage:
|
|
|
|
if systemLanguage.startswith('fr'):
|
|
|
|
speakerLang = 'fr-FR'
|
|
|
|
elif systemLanguage.startswith('es'):
|
|
|
|
speakerLang = 'es-ES'
|
|
|
|
elif systemLanguage.startswith('de'):
|
|
|
|
speakerLang = 'de-DE'
|
|
|
|
elif systemLanguage.startswith('it'):
|
|
|
|
speakerLang = 'it-IT'
|
|
|
|
speakerCmd = 'picospeaker ' + \
|
|
|
|
'-l ' + speakerLang + \
|
|
|
|
' -r ' + str(rate) + \
|
|
|
|
' -p ' + str(pitch) + ' "' + \
|
2021-03-10 12:26:10 +00:00
|
|
|
html.unescape(sayText) + '" 2> /dev/null'
|
2021-03-04 14:54:30 +00:00
|
|
|
os.system(speakerCmd)
|
|
|
|
|
|
|
|
|
2021-03-09 19:52:10 +00:00
|
|
|
def _playNotificationSound(soundFilename: str, player='ffplay') -> None:
|
|
|
|
"""Plays a sound
|
|
|
|
"""
|
|
|
|
if not os.path.isfile(soundFilename):
|
|
|
|
return
|
|
|
|
|
|
|
|
if player == 'ffplay':
|
|
|
|
os.system('ffplay ' + soundFilename +
|
2021-03-10 15:43:21 +00:00
|
|
|
' -autoexit -hide_banner -nodisp 2> /dev/null')
|
2021-03-09 19:52:10 +00:00
|
|
|
|
|
|
|
|
2021-03-09 20:32:50 +00:00
|
|
|
def _desktopNotification(notificationType: str,
|
2021-03-09 21:23:32 +00:00
|
|
|
title: str, message: str) -> None:
|
2021-03-09 20:32:50 +00:00
|
|
|
"""Shows a desktop notification
|
|
|
|
"""
|
|
|
|
if not notificationType:
|
|
|
|
return
|
|
|
|
|
|
|
|
if notificationType == 'notify-send':
|
|
|
|
# Ubuntu
|
|
|
|
os.system('notify-send "' + title + '" "' + message + '"')
|
2021-03-11 10:01:05 +00:00
|
|
|
elif notificationType == 'zenity':
|
|
|
|
# Zenity
|
|
|
|
os.system('zenity --notification --title "' + title +
|
|
|
|
'" --text="' + message + '"')
|
2021-03-09 20:32:50 +00:00
|
|
|
elif notificationType == 'osascript':
|
|
|
|
# Mac
|
|
|
|
os.system("osascript -e 'display notification \"" +
|
|
|
|
message + "\" with title \"" + title + "\"'")
|
|
|
|
elif notificationType == 'New-BurntToastNotification':
|
|
|
|
# Windows
|
|
|
|
os.system("New-BurntToastNotification -Text \"" +
|
|
|
|
title + "\", '" + message + "'")
|
|
|
|
|
|
|
|
|
2021-03-10 12:11:42 +00:00
|
|
|
def _textToSpeech(sayStr: str, screenreader: str,
|
|
|
|
pitch: int, rate: int, srange: int,
|
|
|
|
systemLanguage: str, espeak=None) -> None:
|
|
|
|
"""Say something via TTS
|
|
|
|
"""
|
|
|
|
# speak the post content
|
|
|
|
if screenreader == 'espeak':
|
|
|
|
_speakerEspeak(espeak, pitch, rate, srange, sayStr)
|
|
|
|
elif screenreader == 'picospeaker':
|
|
|
|
_speakerPicospeaker(pitch, rate,
|
|
|
|
systemLanguage, sayStr)
|
|
|
|
|
|
|
|
|
2021-03-11 10:47:52 +00:00
|
|
|
def _sayCommand(content: str, sayStr: str, screenreader: str,
|
2021-03-10 12:11:42 +00:00
|
|
|
systemLanguage: str,
|
|
|
|
espeak=None,
|
|
|
|
speakerName='screen reader',
|
|
|
|
speakerGender='They/Them') -> None:
|
2021-03-10 10:25:41 +00:00
|
|
|
"""Speaks a command
|
|
|
|
"""
|
2021-03-11 10:47:52 +00:00
|
|
|
print(content)
|
2021-03-10 10:32:08 +00:00
|
|
|
if not screenreader:
|
|
|
|
return
|
2021-03-10 10:25:41 +00:00
|
|
|
|
2021-03-10 12:11:42 +00:00
|
|
|
pitch = getSpeakerPitch(speakerName,
|
|
|
|
screenreader, speakerGender)
|
|
|
|
rate = getSpeakerRate(speakerName, screenreader)
|
|
|
|
srange = getSpeakerRange(speakerName)
|
2021-03-10 10:25:41 +00:00
|
|
|
|
2021-03-10 12:11:42 +00:00
|
|
|
_textToSpeech(sayStr, screenreader,
|
|
|
|
pitch, rate, srange,
|
|
|
|
systemLanguage, espeak)
|
2021-03-10 10:25:41 +00:00
|
|
|
|
|
|
|
|
2021-03-10 20:28:43 +00:00
|
|
|
def _notificationReplyToPost(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:
|
2021-03-10 18:30:00 +00:00
|
|
|
"""Use the notification client to send a reply to the most recent post
|
|
|
|
"""
|
|
|
|
if '://' not in postId:
|
|
|
|
return
|
|
|
|
toNickname = getNicknameFromActor(postId)
|
|
|
|
toDomain, toPort = getDomainFromActor(postId)
|
|
|
|
sayStr = 'Replying to ' + toNickname + '@' + toDomain
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr,
|
2021-03-10 18:30:00 +00:00
|
|
|
screenreader, systemLanguage, espeak)
|
|
|
|
sayStr = 'Type your reply message, then press Enter.'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 18:30:00 +00:00
|
|
|
replyMessage = input()
|
|
|
|
if not replyMessage:
|
|
|
|
sayStr = 'No reply was entered.'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 18:30:00 +00:00
|
|
|
return
|
|
|
|
replyMessage = replyMessage.strip()
|
|
|
|
if not replyMessage:
|
|
|
|
sayStr = 'No reply was entered.'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 18:30:00 +00:00
|
|
|
return
|
|
|
|
sayStr = 'You entered this reply:'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
_sayCommand(replyMessage, replyMessage, screenreader,
|
|
|
|
systemLanguage, espeak)
|
2021-03-10 18:30:00 +00:00
|
|
|
sayStr = 'Send this reply, yes or no?'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 18:30:00 +00:00
|
|
|
yesno = input()
|
|
|
|
if 'y' not in yesno.lower():
|
|
|
|
sayStr = 'Abandoning reply'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 18:30:00 +00:00
|
|
|
return
|
2021-03-10 19:06:39 +00:00
|
|
|
ccUrl = None
|
|
|
|
followersOnly = False
|
|
|
|
attach = None
|
|
|
|
mediaType = None
|
|
|
|
attachedImageDescription = None
|
|
|
|
isArticle = False
|
|
|
|
subject = None
|
|
|
|
commentsEnabled = True
|
2021-03-10 20:35:05 +00:00
|
|
|
sayStr = 'Sending reply'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 19:31:33 +00:00
|
|
|
if 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) == 0:
|
|
|
|
sayStr = 'Reply sent'
|
|
|
|
else:
|
|
|
|
sayStr = 'Reply failed'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 18:30:00 +00:00
|
|
|
|
|
|
|
|
2021-03-10 20:28:43 +00:00
|
|
|
def _notificationNewPost(session,
|
|
|
|
baseDir: str, nickname: str, password: str,
|
|
|
|
domain: str, port: int, httpPrefix: str,
|
|
|
|
cachedWebfingers: {}, personCache: {},
|
|
|
|
debug: bool,
|
|
|
|
screenreader: str, systemLanguage: str,
|
|
|
|
espeak) -> None:
|
|
|
|
"""Use the notification client to create a new post
|
|
|
|
"""
|
|
|
|
sayStr = 'Create new post'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 20:28:43 +00:00
|
|
|
sayStr = 'Type your post, then press Enter.'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 20:28:43 +00:00
|
|
|
newMessage = input()
|
|
|
|
if not newMessage:
|
|
|
|
sayStr = 'No post was entered.'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 20:28:43 +00:00
|
|
|
return
|
|
|
|
newMessage = newMessage.strip()
|
|
|
|
if not newMessage:
|
|
|
|
sayStr = 'No post was entered.'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 20:28:43 +00:00
|
|
|
return
|
|
|
|
sayStr = 'You entered this public post:'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
_sayCommand(newMessage, newMessage, screenreader, systemLanguage, espeak)
|
2021-03-10 20:28:43 +00:00
|
|
|
sayStr = 'Send this post, yes or no?'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 20:28:43 +00:00
|
|
|
yesno = input()
|
|
|
|
if 'y' not in yesno.lower():
|
|
|
|
sayStr = 'Abandoning new post'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 20:28:43 +00:00
|
|
|
return
|
|
|
|
ccUrl = None
|
|
|
|
followersOnly = False
|
|
|
|
attach = None
|
|
|
|
mediaType = None
|
|
|
|
attachedImageDescription = None
|
|
|
|
isArticle = False
|
|
|
|
subject = None
|
|
|
|
commentsEnabled = True
|
|
|
|
subject = None
|
2021-03-10 20:35:05 +00:00
|
|
|
sayStr = 'Sending'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 20:28:43 +00:00
|
|
|
if sendPostViaServer(__version__,
|
|
|
|
baseDir, session, nickname, password,
|
|
|
|
domain, port,
|
|
|
|
None, '#Public', port, ccUrl,
|
|
|
|
httpPrefix, newMessage, followersOnly,
|
|
|
|
commentsEnabled, attach, mediaType,
|
|
|
|
attachedImageDescription,
|
|
|
|
cachedWebfingers, personCache, isArticle,
|
|
|
|
debug, None, None, subject) == 0:
|
|
|
|
sayStr = 'Post sent'
|
|
|
|
else:
|
|
|
|
sayStr = 'Post failed'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
2021-03-10 20:28:43 +00:00
|
|
|
|
|
|
|
|
2021-03-11 12:24:20 +00:00
|
|
|
def _notificationNewDM(session, toHandle: str,
|
|
|
|
baseDir: str, nickname: str, password: str,
|
|
|
|
domain: str, port: int, httpPrefix: str,
|
|
|
|
cachedWebfingers: {}, personCache: {},
|
|
|
|
debug: bool,
|
|
|
|
screenreader: str, systemLanguage: str,
|
|
|
|
espeak) -> None:
|
|
|
|
"""Use the notification client to create a new direct message
|
|
|
|
"""
|
|
|
|
toPort = port
|
|
|
|
if '://' in toHandle:
|
|
|
|
toNickname = getNicknameFromActor(toHandle)
|
|
|
|
toDomain, toPort = getDomainFromActor(toHandle)
|
|
|
|
toHandle = toNickname + '@' + toDomain
|
|
|
|
else:
|
|
|
|
if toHandle.startswith('@'):
|
|
|
|
toHandle = toHandle[1:]
|
|
|
|
toNickname = toHandle.split('@')[0]
|
|
|
|
toDomain = toHandle.split('@')[1]
|
|
|
|
|
|
|
|
sayStr = 'Create new direct message to ' + toHandle
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
sayStr = 'Type your direct message, then press Enter.'
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
newMessage = input()
|
|
|
|
if not newMessage:
|
|
|
|
sayStr = 'No direct message was entered.'
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
return
|
|
|
|
newMessage = newMessage.strip()
|
|
|
|
if not newMessage:
|
|
|
|
sayStr = 'No direct message was entered.'
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
return
|
|
|
|
sayStr = 'You entered this direct message to ' + toHandle + ':'
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
_sayCommand(newMessage, newMessage, screenreader, systemLanguage, espeak)
|
|
|
|
ccUrl = None
|
|
|
|
followersOnly = False
|
|
|
|
attach = None
|
|
|
|
mediaType = None
|
|
|
|
attachedImageDescription = None
|
|
|
|
isArticle = False
|
|
|
|
subject = None
|
|
|
|
commentsEnabled = True
|
|
|
|
subject = None
|
2021-03-11 20:33:45 +00:00
|
|
|
|
|
|
|
# if there is a local PGP key then attempt to encrypt the DM
|
|
|
|
# using the PGP public key of the recipient
|
2021-03-12 14:55:37 +00:00
|
|
|
newMessageOriginal = newMessage
|
2021-03-11 20:33:45 +00:00
|
|
|
if hasLocalPGPkey():
|
|
|
|
sayStr = \
|
|
|
|
'Local PGP key detected...' + \
|
|
|
|
'Fetching PGP public key for ' + toHandle
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
paddedMessage = newMessage
|
|
|
|
if len(paddedMessage) < 32:
|
|
|
|
# add some padding before and after
|
|
|
|
# This is to guard against cribs based on small messages, like "Hi"
|
|
|
|
for before in range(randint(1, 16)):
|
|
|
|
paddedMessage = ' ' + paddedMessage
|
|
|
|
for after in range(randint(1, 16)):
|
|
|
|
paddedMessage += ' '
|
|
|
|
cipherText = \
|
|
|
|
pgpEncryptToActor(paddedMessage, toHandle)
|
|
|
|
if not cipherText:
|
2021-03-11 20:52:35 +00:00
|
|
|
sayStr = \
|
|
|
|
toHandle + ' has no PGP public key. ' + \
|
|
|
|
'Your message will be sent in clear text'
|
2021-03-11 20:33:45 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
else:
|
|
|
|
newMessage = cipherText
|
|
|
|
sayStr = 'Message encrypted'
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
|
2021-03-11 20:52:35 +00:00
|
|
|
sayStr = 'Send this direct message, yes or no?'
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
yesno = input()
|
|
|
|
if 'y' not in yesno.lower():
|
|
|
|
sayStr = 'Abandoning new direct message'
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
return
|
|
|
|
|
2021-03-11 12:24:20 +00:00
|
|
|
sayStr = 'Sending'
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
if sendPostViaServer(__version__,
|
|
|
|
baseDir, session, nickname, password,
|
|
|
|
domain, port,
|
|
|
|
toNickname, toDomain, toPort, ccUrl,
|
|
|
|
httpPrefix, newMessage, followersOnly,
|
|
|
|
commentsEnabled, attach, mediaType,
|
|
|
|
attachedImageDescription,
|
|
|
|
cachedWebfingers, personCache, isArticle,
|
|
|
|
debug, None, None, subject) == 0:
|
2021-03-12 14:55:37 +00:00
|
|
|
# store the DM locally
|
|
|
|
statusNumber, published = getStatusNumber()
|
|
|
|
postId = \
|
|
|
|
httpPrefix + '://' + getFullDomain(domain, port) + \
|
|
|
|
'/users/' + nickname + '/statuses/' + statusNumber
|
|
|
|
speakerJson = {
|
|
|
|
"name": nickname,
|
|
|
|
"summary": "",
|
|
|
|
"content": newMessageOriginal,
|
|
|
|
"say": newMessageOriginal,
|
|
|
|
"published": published,
|
|
|
|
"imageDescription": "",
|
|
|
|
"detectedLinks": [],
|
|
|
|
"id": postId,
|
|
|
|
"direct": True
|
|
|
|
}
|
|
|
|
_storeMessage(speakerJson, 'sent')
|
2021-03-11 12:24:20 +00:00
|
|
|
sayStr = 'Direct message sent'
|
|
|
|
else:
|
|
|
|
sayStr = 'Direct message failed'
|
|
|
|
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
|
|
|
|
|
|
|
|
|
2021-03-12 14:55:37 +00:00
|
|
|
def _storeMessage(speakerJson: {}, boxName: str) -> None:
|
2021-03-12 11:40:41 +00:00
|
|
|
"""Stores a message in your home directory for later reading
|
2021-03-12 10:06:24 +00:00
|
|
|
"""
|
|
|
|
if not speakerJson.get('published'):
|
|
|
|
return
|
|
|
|
homeDir = str(Path.home())
|
|
|
|
if not os.path.isdir(homeDir + '/.config'):
|
|
|
|
os.mkdir(homeDir + '/.config')
|
|
|
|
if not os.path.isdir(homeDir + '/.config/epicyon'):
|
|
|
|
os.mkdir(homeDir + '/.config/epicyon')
|
2021-03-12 14:55:37 +00:00
|
|
|
msgDir = homeDir + '/.config/epicyon/' + boxName
|
2021-03-12 10:06:24 +00:00
|
|
|
if not os.path.isdir(msgDir):
|
|
|
|
os.mkdir(msgDir)
|
|
|
|
msgFilename = msgDir + '/' + speakerJson['published'] + '.json'
|
|
|
|
saveJson(speakerJson, msgFilename)
|
|
|
|
|
|
|
|
|
2021-03-09 12:03:50 +00:00
|
|
|
def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str,
|
|
|
|
nickname: str, domain: str, port: int,
|
|
|
|
password: str, screenreader: str,
|
2021-03-10 09:57:19 +00:00
|
|
|
systemLanguage: str,
|
|
|
|
notificationSounds: bool,
|
2021-03-10 14:22:33 +00:00
|
|
|
notificationType: str,
|
2021-03-10 09:57:19 +00:00
|
|
|
debug: bool) -> None:
|
2021-03-09 12:03:50 +00:00
|
|
|
"""Runs the notifications and screen reader client,
|
|
|
|
which announces new inbox items
|
2021-03-04 13:57:30 +00:00
|
|
|
"""
|
2021-03-10 10:25:41 +00:00
|
|
|
espeak = None
|
2021-03-09 19:52:10 +00:00
|
|
|
if screenreader:
|
|
|
|
if screenreader == 'espeak':
|
|
|
|
print('Setting up espeak')
|
|
|
|
from espeak import espeak
|
|
|
|
elif screenreader != 'picospeaker':
|
|
|
|
print(screenreader + ' is not a supported TTS system')
|
|
|
|
return
|
2021-03-04 13:57:30 +00:00
|
|
|
|
2021-03-10 10:49:45 +00:00
|
|
|
sayStr = 'Running ' + screenreader + ' for ' + nickname + '@' + domain
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader,
|
2021-03-10 10:49:45 +00:00
|
|
|
systemLanguage, espeak)
|
2021-03-09 21:30:23 +00:00
|
|
|
else:
|
|
|
|
print('Running desktop notifications for ' + nickname + '@' + domain)
|
2021-03-10 09:57:19 +00:00
|
|
|
if notificationSounds:
|
2021-03-10 10:49:45 +00:00
|
|
|
sayStr = 'Notification sounds on'
|
2021-03-10 09:57:19 +00:00
|
|
|
else:
|
2021-03-10 10:49:45 +00:00
|
|
|
sayStr = 'Notification sounds off'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader,
|
2021-03-10 10:49:45 +00:00
|
|
|
systemLanguage, espeak)
|
|
|
|
sayStr = '/q or /quit to exit'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader,
|
2021-03-10 10:49:45 +00:00
|
|
|
systemLanguage, espeak)
|
2021-03-10 12:41:26 +00:00
|
|
|
print('')
|
2021-03-10 10:51:06 +00:00
|
|
|
keyPress = _waitForKeypress(2, debug)
|
|
|
|
|
2021-03-10 10:25:41 +00:00
|
|
|
originalScreenReader = screenreader
|
2021-03-09 22:12:12 +00:00
|
|
|
domainFull = getFullDomain(domain, port)
|
|
|
|
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
2021-03-04 13:57:30 +00:00
|
|
|
prevSay = ''
|
2021-03-09 19:52:10 +00:00
|
|
|
prevDM = False
|
|
|
|
prevReply = False
|
|
|
|
prevCalendar = False
|
|
|
|
prevFollow = False
|
|
|
|
prevLike = ''
|
|
|
|
prevShare = False
|
|
|
|
dmSoundFilename = 'dm.ogg'
|
|
|
|
replySoundFilename = 'reply.ogg'
|
|
|
|
calendarSoundFilename = 'calendar.ogg'
|
|
|
|
followSoundFilename = 'follow.ogg'
|
|
|
|
likeSoundFilename = 'like.ogg'
|
|
|
|
shareSoundFilename = 'share.ogg'
|
|
|
|
player = 'ffplay'
|
2021-03-10 12:37:44 +00:00
|
|
|
nameStr = None
|
|
|
|
gender = None
|
|
|
|
messageStr = None
|
2021-03-11 10:52:06 +00:00
|
|
|
content = None
|
2021-03-10 13:04:22 +00:00
|
|
|
cachedWebfingers = {}
|
|
|
|
personCache = {}
|
2021-03-04 13:57:30 +00:00
|
|
|
while (1):
|
|
|
|
session = createSession(proxyType)
|
|
|
|
speakerJson = \
|
|
|
|
getSpeakerFromServer(baseDir, session, nickname, password,
|
|
|
|
domain, port, httpPrefix, True, __version__)
|
|
|
|
if speakerJson:
|
2021-03-09 19:52:10 +00:00
|
|
|
if speakerJson.get('notify'):
|
2021-03-09 22:12:12 +00:00
|
|
|
title = 'Epicyon'
|
|
|
|
if speakerJson['notify'].get('title'):
|
|
|
|
title = speakerJson['notify']['title']
|
2021-03-09 19:52:10 +00:00
|
|
|
soundsDir = 'theme/default/sounds'
|
|
|
|
if speakerJson['notify'].get('theme'):
|
2021-03-09 23:22:48 +00:00
|
|
|
if isinstance(speakerJson['notify']['theme'], str):
|
|
|
|
soundsDir = \
|
|
|
|
'theme/' + \
|
|
|
|
speakerJson['notify']['theme'] + '/sounds'
|
|
|
|
if not os.path.isdir(soundsDir):
|
|
|
|
soundsDir = 'theme/default/sounds'
|
2021-03-09 22:47:10 +00:00
|
|
|
if speakerJson['notify']['dm'] != prevDM:
|
|
|
|
if speakerJson['notify']['dm'] is True:
|
2021-03-10 09:57:19 +00:00
|
|
|
if notificationSounds:
|
|
|
|
_playNotificationSound(soundsDir + '/' +
|
|
|
|
dmSoundFilename, player)
|
2021-03-09 22:47:10 +00:00
|
|
|
_desktopNotification(notificationType, title,
|
2021-03-09 22:12:12 +00:00
|
|
|
'New direct message ' +
|
|
|
|
actor + '/dm')
|
2021-03-09 22:47:10 +00:00
|
|
|
prevDM = speakerJson['notify']['dm']
|
|
|
|
elif speakerJson['notify']['reply'] != prevReply:
|
|
|
|
if speakerJson['notify']['reply'] is True:
|
2021-03-10 09:57:19 +00:00
|
|
|
if notificationSounds:
|
|
|
|
_playNotificationSound(soundsDir + '/' +
|
|
|
|
replySoundFilename,
|
|
|
|
player)
|
2021-03-09 22:47:10 +00:00
|
|
|
_desktopNotification(notificationType, title,
|
2021-03-09 22:12:12 +00:00
|
|
|
'New reply ' +
|
|
|
|
actor + '/tlreplies')
|
2021-03-09 22:35:06 +00:00
|
|
|
prevReply = speakerJson['notify']['reply']
|
2021-03-09 22:47:10 +00:00
|
|
|
elif speakerJson['notify']['calendar'] != prevCalendar:
|
|
|
|
if speakerJson['notify']['calendar'] is True:
|
2021-03-10 09:57:19 +00:00
|
|
|
if notificationSounds:
|
|
|
|
_playNotificationSound(soundsDir + '/' +
|
|
|
|
calendarSoundFilename,
|
|
|
|
player)
|
2021-03-09 22:47:10 +00:00
|
|
|
_desktopNotification(notificationType, title,
|
2021-03-09 22:12:12 +00:00
|
|
|
'New calendar event ' +
|
|
|
|
actor + '/calendar')
|
2021-03-09 22:47:10 +00:00
|
|
|
prevCalendar = speakerJson['notify']['calendar']
|
|
|
|
elif speakerJson['notify']['followRequests'] != prevFollow:
|
|
|
|
if speakerJson['notify']['followRequests'] is True:
|
2021-03-10 09:57:19 +00:00
|
|
|
if notificationSounds:
|
|
|
|
_playNotificationSound(soundsDir + '/' +
|
|
|
|
followSoundFilename,
|
|
|
|
player)
|
2021-03-09 22:47:10 +00:00
|
|
|
_desktopNotification(notificationType, title,
|
2021-03-09 22:12:12 +00:00
|
|
|
'New follow request ' +
|
|
|
|
actor + '/followers#buttonheader')
|
2021-03-09 22:47:10 +00:00
|
|
|
prevFollow = speakerJson['notify']['followRequests']
|
|
|
|
elif speakerJson['notify']['likedBy'] != prevLike:
|
2021-03-10 09:57:19 +00:00
|
|
|
if notificationSounds:
|
|
|
|
_playNotificationSound(soundsDir + '/' +
|
|
|
|
likeSoundFilename, player)
|
2021-03-09 22:47:10 +00:00
|
|
|
_desktopNotification(notificationType, title,
|
|
|
|
'New like ' +
|
|
|
|
speakerJson['notify']['likedBy'])
|
|
|
|
prevLike = speakerJson['notify']['likedBy']
|
|
|
|
elif speakerJson['notify']['share'] != prevShare:
|
|
|
|
if speakerJson['notify']['share'] is True:
|
2021-03-10 09:57:19 +00:00
|
|
|
if notificationSounds:
|
|
|
|
_playNotificationSound(soundsDir + '/' +
|
|
|
|
shareSoundFilename,
|
|
|
|
player)
|
2021-03-09 22:47:10 +00:00
|
|
|
_desktopNotification(notificationType, title,
|
2021-03-09 22:12:12 +00:00
|
|
|
'New shared item ' +
|
|
|
|
actor + '/shares')
|
2021-03-09 22:47:10 +00:00
|
|
|
prevShare = speakerJson['notify']['share']
|
2021-03-09 19:52:10 +00:00
|
|
|
|
|
|
|
if speakerJson.get('say'):
|
|
|
|
if speakerJson['say'] != prevSay:
|
|
|
|
if speakerJson.get('name'):
|
|
|
|
nameStr = speakerJson['name']
|
|
|
|
gender = 'They/Them'
|
|
|
|
if speakerJson.get('gender'):
|
|
|
|
gender = speakerJson['gender']
|
|
|
|
|
|
|
|
# append image description if needed
|
|
|
|
if not speakerJson.get('imageDescription'):
|
2021-03-10 12:37:44 +00:00
|
|
|
messageStr = speakerJson['say']
|
2021-03-09 19:52:10 +00:00
|
|
|
else:
|
2021-03-10 12:37:44 +00:00
|
|
|
messageStr = speakerJson['say'] + '. ' + \
|
2021-03-09 19:52:10 +00:00
|
|
|
speakerJson['imageDescription']
|
2021-03-12 09:50:08 +00:00
|
|
|
encryptedMessage = False
|
|
|
|
if speakerJson.get('id') and \
|
|
|
|
isPGPEncrypted(messageStr):
|
|
|
|
encryptedMessage = True
|
2021-03-11 19:13:41 +00:00
|
|
|
messageStr = pgpDecrypt(messageStr,
|
|
|
|
speakerJson['id'])
|
2021-03-10 12:15:08 +00:00
|
|
|
|
2021-03-11 10:47:52 +00:00
|
|
|
content = messageStr
|
|
|
|
if speakerJson.get('content'):
|
2021-03-12 09:50:08 +00:00
|
|
|
if not encryptedMessage:
|
2021-03-11 19:13:41 +00:00
|
|
|
content = speakerJson['content']
|
2021-03-12 11:43:32 +00:00
|
|
|
else:
|
|
|
|
content = '🔓 ' + messageStr
|
2021-03-11 10:47:52 +00:00
|
|
|
|
2021-03-10 12:11:42 +00:00
|
|
|
# say the speaker's name
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(nameStr, nameStr, screenreader,
|
2021-03-10 12:11:42 +00:00
|
|
|
systemLanguage, espeak,
|
|
|
|
nameStr, gender)
|
|
|
|
|
|
|
|
time.sleep(2)
|
2021-03-09 19:52:10 +00:00
|
|
|
|
|
|
|
# speak the post content
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(content, messageStr, screenreader,
|
2021-03-10 12:11:42 +00:00
|
|
|
systemLanguage, espeak,
|
|
|
|
nameStr, gender)
|
2021-03-09 19:52:10 +00:00
|
|
|
|
2021-03-12 10:06:24 +00:00
|
|
|
if encryptedMessage:
|
|
|
|
speakerJson['content'] = content
|
|
|
|
speakerJson['say'] = messageStr
|
|
|
|
speakerJson['decrypted'] = True
|
2021-03-12 14:55:37 +00:00
|
|
|
_storeMessage(speakerJson, 'dm')
|
2021-03-12 14:34:56 +00:00
|
|
|
elif speakerJson.get('direct'):
|
|
|
|
speakerJson['decrypted'] = False
|
2021-03-12 14:55:37 +00:00
|
|
|
_storeMessage(speakerJson, 'dm')
|
2021-03-12 10:06:24 +00:00
|
|
|
|
2021-03-10 12:40:17 +00:00
|
|
|
print('')
|
|
|
|
|
2021-03-09 19:52:10 +00:00
|
|
|
prevSay = speakerJson['say']
|
2021-03-04 13:57:30 +00:00
|
|
|
|
|
|
|
# wait for a while, or until a key is pressed
|
2021-03-04 18:05:46 +00:00
|
|
|
keyPress = _waitForKeypress(30, debug)
|
|
|
|
if keyPress:
|
|
|
|
if keyPress.startswith('/'):
|
|
|
|
keyPress = keyPress[1:]
|
|
|
|
if keyPress == 'q' or keyPress == 'quit' or keyPress == 'exit':
|
2021-03-10 10:46:50 +00:00
|
|
|
sayStr = 'Quit'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader,
|
2021-03-10 10:46:50 +00:00
|
|
|
systemLanguage, espeak)
|
2021-03-10 18:31:45 +00:00
|
|
|
if screenreader:
|
2021-03-10 19:06:39 +00:00
|
|
|
keyPress = _waitForKeypress(2, debug)
|
2021-03-04 18:05:46 +00:00
|
|
|
break
|
2021-03-10 18:30:00 +00:00
|
|
|
elif keyPress == 'reply' or keyPress == 'r':
|
|
|
|
if speakerJson.get('id'):
|
|
|
|
postId = speakerJson['id']
|
2021-03-10 19:06:39 +00:00
|
|
|
subject = None
|
|
|
|
if speakerJson.get('summary'):
|
|
|
|
subject = speakerJson['summary']
|
|
|
|
sessionReply = createSession(proxyType)
|
2021-03-10 20:28:43 +00:00
|
|
|
_notificationReplyToPost(sessionReply, postId,
|
|
|
|
baseDir, nickname, password,
|
|
|
|
domain, port, httpPrefix,
|
|
|
|
cachedWebfingers, personCache,
|
|
|
|
debug, subject,
|
|
|
|
screenreader, systemLanguage,
|
|
|
|
espeak)
|
|
|
|
print('')
|
2021-03-11 12:24:20 +00:00
|
|
|
elif (keyPress == 'post' or keyPress == 'p' or
|
|
|
|
keyPress == 'send' or
|
2021-03-11 12:53:00 +00:00
|
|
|
keyPress.startswith('dm ') or
|
|
|
|
keyPress.startswith('direct message ') or
|
2021-03-11 12:24:20 +00:00
|
|
|
keyPress.startswith('post ') or
|
|
|
|
keyPress.startswith('send ')):
|
2021-03-10 20:28:43 +00:00
|
|
|
sessionPost = createSession(proxyType)
|
2021-03-11 12:53:00 +00:00
|
|
|
if keyPress.startswith('dm ') or \
|
|
|
|
keyPress.startswith('direct message ') or \
|
|
|
|
keyPress.startswith('post ') or \
|
2021-03-11 12:24:20 +00:00
|
|
|
keyPress.startswith('send '):
|
2021-03-11 12:32:31 +00:00
|
|
|
keyPress = keyPress.replace(' to ', ' ')
|
2021-03-11 12:54:36 +00:00
|
|
|
keyPress = keyPress.replace(' dm ', ' ')
|
|
|
|
keyPress = keyPress.replace(' DM ', ' ')
|
2021-03-11 12:24:20 +00:00
|
|
|
# direct message
|
2021-03-11 12:30:29 +00:00
|
|
|
toHandle = None
|
2021-03-11 12:24:20 +00:00
|
|
|
if keyPress.startswith('post '):
|
|
|
|
toHandle = keyPress.split('post ', 1)[1]
|
2021-03-11 12:30:29 +00:00
|
|
|
elif keyPress.startswith('send '):
|
2021-03-11 12:24:20 +00:00
|
|
|
toHandle = keyPress.split('send ', 1)[1]
|
2021-03-11 12:53:00 +00:00
|
|
|
elif keyPress.startswith('dm '):
|
|
|
|
toHandle = keyPress.split('dm ', 1)[1]
|
|
|
|
elif keyPress.startswith('direct message '):
|
|
|
|
toHandle = keyPress.split('direct message ', 1)[1]
|
2021-03-11 12:30:29 +00:00
|
|
|
if toHandle:
|
|
|
|
_notificationNewDM(sessionPost, toHandle,
|
|
|
|
baseDir, nickname, password,
|
|
|
|
domain, port, httpPrefix,
|
|
|
|
cachedWebfingers, personCache,
|
|
|
|
debug,
|
|
|
|
screenreader, systemLanguage,
|
|
|
|
espeak)
|
2021-03-11 12:24:20 +00:00
|
|
|
else:
|
|
|
|
# public post
|
|
|
|
_notificationNewPost(sessionPost,
|
|
|
|
baseDir, nickname, password,
|
|
|
|
domain, port, httpPrefix,
|
|
|
|
cachedWebfingers, personCache,
|
|
|
|
debug,
|
|
|
|
screenreader, systemLanguage,
|
|
|
|
espeak)
|
2021-03-10 18:30:00 +00:00
|
|
|
print('')
|
2021-03-10 13:04:22 +00:00
|
|
|
elif keyPress == 'like':
|
|
|
|
if nameStr and gender and messageStr:
|
2021-03-11 10:47:52 +00:00
|
|
|
sayStr = 'Liking post by ' + nameStr
|
|
|
|
_sayCommand(sayStr, sayStr,
|
2021-03-10 13:04:22 +00:00
|
|
|
screenreader,
|
|
|
|
systemLanguage, espeak)
|
2021-03-10 16:56:27 +00:00
|
|
|
sessionLike = createSession(proxyType)
|
|
|
|
sendLikeViaServer(baseDir, sessionLike,
|
2021-03-10 13:04:22 +00:00
|
|
|
nickname, password,
|
|
|
|
domain, port,
|
|
|
|
httpPrefix, speakerJson['id'],
|
|
|
|
cachedWebfingers, personCache,
|
|
|
|
True, __version__)
|
2021-03-10 13:13:54 +00:00
|
|
|
print('')
|
2021-03-10 13:07:24 +00:00
|
|
|
elif keyPress == 'unlike' or keyPress == 'undo like':
|
|
|
|
if nameStr and gender and messageStr:
|
2021-03-11 10:47:52 +00:00
|
|
|
sayStr = 'Undoing like of post by ' + nameStr
|
|
|
|
_sayCommand(sayStr, sayStr,
|
2021-03-10 13:07:24 +00:00
|
|
|
screenreader,
|
|
|
|
systemLanguage, espeak)
|
2021-03-10 16:56:27 +00:00
|
|
|
sessionUnlike = createSession(proxyType)
|
|
|
|
sendUndoLikeViaServer(baseDir, sessionUnlike,
|
2021-03-10 13:07:24 +00:00
|
|
|
nickname, password,
|
|
|
|
domain, port,
|
|
|
|
httpPrefix, speakerJson['id'],
|
|
|
|
cachedWebfingers, personCache,
|
|
|
|
True, __version__)
|
2021-03-10 13:13:54 +00:00
|
|
|
print('')
|
2021-03-10 21:45:34 +00:00
|
|
|
elif (keyPress == 'announce' or
|
|
|
|
keyPress == 'boost' or
|
|
|
|
keyPress == 'retweet'):
|
|
|
|
if speakerJson.get('id'):
|
|
|
|
if nameStr and gender and messageStr:
|
|
|
|
postId = speakerJson['id']
|
2021-03-11 10:47:52 +00:00
|
|
|
sayStr = 'Announcing post by ' + nameStr
|
|
|
|
_sayCommand(sayStr, sayStr,
|
2021-03-10 21:45:34 +00:00
|
|
|
screenreader,
|
|
|
|
systemLanguage, espeak)
|
|
|
|
sessionAnnounce = createSession(proxyType)
|
|
|
|
sendAnnounceViaServer(baseDir, sessionAnnounce,
|
|
|
|
nickname, password,
|
|
|
|
domain, port,
|
|
|
|
httpPrefix, postId,
|
|
|
|
cachedWebfingers, personCache,
|
|
|
|
True, __version__)
|
|
|
|
print('')
|
2021-03-10 13:38:11 +00:00
|
|
|
elif keyPress.startswith('follow '):
|
|
|
|
followHandle = keyPress.replace('follow ', '').strip()
|
|
|
|
if followHandle.startswith('@'):
|
|
|
|
followHandle = followHandle[1:]
|
|
|
|
if '@' in followHandle or '://' in followHandle:
|
|
|
|
followNickname = getNicknameFromActor(followHandle)
|
|
|
|
followDomain, followPort = \
|
|
|
|
getDomainFromActor(followHandle)
|
|
|
|
if followNickname and followDomain:
|
2021-03-11 10:47:52 +00:00
|
|
|
sayStr = 'Sending follow request to ' + \
|
|
|
|
followNickname + '@' + followDomain
|
|
|
|
_sayCommand(sayStr, sayStr,
|
2021-03-10 13:38:11 +00:00
|
|
|
screenreader, systemLanguage, espeak)
|
2021-03-10 16:56:27 +00:00
|
|
|
sessionFollow = createSession(proxyType)
|
|
|
|
sendFollowRequestViaServer(baseDir, sessionFollow,
|
2021-03-10 13:38:11 +00:00
|
|
|
nickname, password,
|
|
|
|
domain, port,
|
|
|
|
followNickname,
|
|
|
|
followDomain,
|
|
|
|
followPort,
|
|
|
|
httpPrefix,
|
|
|
|
cachedWebfingers,
|
|
|
|
personCache,
|
|
|
|
debug, __version__)
|
|
|
|
else:
|
2021-03-11 10:47:52 +00:00
|
|
|
sayStr = followHandle + ' is not valid'
|
|
|
|
_sayCommand(sayStr,
|
2021-03-10 13:38:11 +00:00
|
|
|
screenreader, systemLanguage, espeak)
|
|
|
|
print('')
|
|
|
|
elif (keyPress.startswith('unfollow ') or
|
|
|
|
keyPress.startswith('stop following ')):
|
|
|
|
followHandle = keyPress.replace('unfollow ', '').strip()
|
|
|
|
followHandle = followHandle.replace('stop following ', '')
|
|
|
|
if followHandle.startswith('@'):
|
|
|
|
followHandle = followHandle[1:]
|
|
|
|
if '@' in followHandle or '://' in followHandle:
|
|
|
|
followNickname = getNicknameFromActor(followHandle)
|
|
|
|
followDomain, followPort = \
|
|
|
|
getDomainFromActor(followHandle)
|
|
|
|
if followNickname and followDomain:
|
2021-03-11 10:47:52 +00:00
|
|
|
sayStr = 'Stop following ' + \
|
|
|
|
followNickname + '@' + followDomain
|
|
|
|
_sayCommand(sayStr, sayStr,
|
2021-03-10 13:38:11 +00:00
|
|
|
screenreader, systemLanguage, espeak)
|
2021-03-10 16:56:27 +00:00
|
|
|
sessionUnfollow = createSession(proxyType)
|
|
|
|
sendUnfollowRequestViaServer(baseDir, sessionUnfollow,
|
2021-03-10 13:38:11 +00:00
|
|
|
nickname, password,
|
|
|
|
domain, port,
|
|
|
|
followNickname,
|
|
|
|
followDomain,
|
|
|
|
followPort,
|
|
|
|
httpPrefix,
|
|
|
|
cachedWebfingers,
|
|
|
|
personCache,
|
|
|
|
debug, __version__)
|
|
|
|
else:
|
2021-03-11 10:47:52 +00:00
|
|
|
sayStr = followHandle + ' is not valid'
|
|
|
|
_sayCommand(sayStr, sayStr,
|
2021-03-10 13:38:11 +00:00
|
|
|
screenreader, systemLanguage, espeak)
|
|
|
|
print('')
|
2021-03-10 13:13:54 +00:00
|
|
|
elif (keyPress == 'repeat' or keyPress == 'replay' or
|
2021-03-11 11:15:41 +00:00
|
|
|
keyPress == 'rp' or keyPress == 'again' or
|
|
|
|
keyPress == 'say again'):
|
2021-03-11 11:09:33 +00:00
|
|
|
if screenreader and nameStr and \
|
|
|
|
gender and messageStr and content:
|
|
|
|
sayStr = 'Repeating ' + nameStr
|
2021-03-11 11:12:01 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader,
|
2021-03-10 12:37:44 +00:00
|
|
|
systemLanguage, espeak,
|
|
|
|
nameStr, gender)
|
|
|
|
time.sleep(2)
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(content, messageStr, screenreader,
|
2021-03-10 12:40:17 +00:00
|
|
|
systemLanguage, espeak,
|
|
|
|
nameStr, gender)
|
|
|
|
print('')
|
2021-03-11 11:15:41 +00:00
|
|
|
elif (keyPress == 'sounds on' or
|
|
|
|
keyPress == 'sound on' or
|
|
|
|
keyPress == 'sound'):
|
2021-03-10 10:34:06 +00:00
|
|
|
sayStr = 'Notification sounds on'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader,
|
2021-03-10 10:32:08 +00:00
|
|
|
systemLanguage, espeak)
|
2021-03-10 09:57:19 +00:00
|
|
|
notificationSounds = True
|
2021-03-11 11:15:41 +00:00
|
|
|
elif (keyPress == 'sounds off' or
|
|
|
|
keyPress == 'sound off' or
|
|
|
|
keyPress == 'nosound'):
|
2021-03-10 10:34:06 +00:00
|
|
|
sayStr = 'Notification sounds off'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader,
|
2021-03-10 10:32:08 +00:00
|
|
|
systemLanguage, espeak)
|
2021-03-10 09:57:19 +00:00
|
|
|
notificationSounds = False
|
2021-03-10 10:32:08 +00:00
|
|
|
elif (keyPress == 'speak' or
|
|
|
|
keyPress == 'screen reader on' or
|
|
|
|
keyPress == 'speaker on' or
|
|
|
|
keyPress == 'talker on' or
|
|
|
|
keyPress == 'reader on'):
|
2021-03-10 10:25:41 +00:00
|
|
|
if originalScreenReader:
|
|
|
|
screenreader = originalScreenReader
|
2021-03-10 10:34:06 +00:00
|
|
|
sayStr = 'Screen reader on'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, screenreader,
|
2021-03-10 10:25:41 +00:00
|
|
|
systemLanguage, espeak)
|
|
|
|
else:
|
|
|
|
print('No --screenreader option was specified')
|
2021-03-10 10:32:08 +00:00
|
|
|
elif (keyPress == 'mute' or
|
|
|
|
keyPress == 'screen reader off' or
|
|
|
|
keyPress == 'speaker off' or
|
|
|
|
keyPress == 'talker off' or
|
|
|
|
keyPress == 'reader off'):
|
2021-03-10 10:25:41 +00:00
|
|
|
if originalScreenReader:
|
|
|
|
screenreader = None
|
2021-03-10 10:34:06 +00:00
|
|
|
sayStr = 'Screen reader off'
|
2021-03-11 10:47:52 +00:00
|
|
|
_sayCommand(sayStr, sayStr, originalScreenReader,
|
2021-03-10 10:25:41 +00:00
|
|
|
systemLanguage, espeak)
|
|
|
|
else:
|
|
|
|
print('No --screenreader option was specified')
|