mirror of https://gitlab.com/bashrc2/epicyon
Validate emoji reactions
parent
68badb0e36
commit
83d6c53221
|
@ -83,6 +83,7 @@ from like import sendLikeViaServer
|
||||||
from like import sendUndoLikeViaServer
|
from like import sendUndoLikeViaServer
|
||||||
from reaction import sendReactionViaServer
|
from reaction import sendReactionViaServer
|
||||||
from reaction import sendUndoReactionViaServer
|
from reaction import sendUndoReactionViaServer
|
||||||
|
from reaction import validEmojiContent
|
||||||
from skills import sendSkillViaServer
|
from skills import sendSkillViaServer
|
||||||
from availability import setAvailability
|
from availability import setAvailability
|
||||||
from availability import sendAvailabilityViaServer
|
from availability import sendAvailabilityViaServer
|
||||||
|
@ -1628,6 +1629,9 @@ if args.react:
|
||||||
if not args.emoji:
|
if not args.emoji:
|
||||||
print('Specify a reaction emoji with the --emoji option')
|
print('Specify a reaction emoji with the --emoji option')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
if not validEmojiContent(args.emoji):
|
||||||
|
print('This is not a valid emoji')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if not args.password:
|
if not args.password:
|
||||||
args.password = getpass.getpass('Password: ')
|
args.password = getpass.getpass('Password: ')
|
||||||
|
@ -1698,6 +1702,9 @@ if args.undoreact:
|
||||||
if not args.emoji:
|
if not args.emoji:
|
||||||
print('Specify a reaction emoji with the --emoji option')
|
print('Specify a reaction emoji with the --emoji option')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
if not validEmojiContent(args.emoji):
|
||||||
|
print('This is not a valid emoji')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if not args.password:
|
if not args.password:
|
||||||
args.password = getpass.getpass('Password: ')
|
args.password = getpass.getpass('Password: ')
|
||||||
|
|
5
inbox.py
5
inbox.py
|
@ -16,6 +16,7 @@ from linked_data_sig import verifyJsonSignature
|
||||||
from languages import understoodPostLanguage
|
from languages import understoodPostLanguage
|
||||||
from like import updateLikesCollection
|
from like import updateLikesCollection
|
||||||
from reaction import updateReactionCollection
|
from reaction import updateReactionCollection
|
||||||
|
from reaction import validEmojiContent
|
||||||
from utils import removeHtml
|
from utils import removeHtml
|
||||||
from utils import fileLastModified
|
from utils import fileLastModified
|
||||||
from utils import hasObjectString
|
from utils import hasObjectString
|
||||||
|
@ -1246,6 +1247,10 @@ def _receiveReaction(recentPostsCache: {},
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: ' + messageJson['type'] + ' content is not string')
|
print('DEBUG: ' + messageJson['type'] + ' content is not string')
|
||||||
return False
|
return False
|
||||||
|
if not validEmojiContent(messageJson['content']):
|
||||||
|
print('_receiveReaction: Invalid emoji reaction: "' +
|
||||||
|
messageJson['content'] + '" from ' + messageJson['actor'])
|
||||||
|
return False
|
||||||
if not hasUsersPath(messageJson['actor']):
|
if not hasUsersPath(messageJson['actor']):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: "users" or "profile" missing from actor in ' +
|
print('DEBUG: "users" or "profile" missing from actor in ' +
|
||||||
|
|
27
reaction.py
27
reaction.py
|
@ -8,6 +8,7 @@ __status__ = "Production"
|
||||||
__module_group__ = "ActivityPub"
|
__module_group__ = "ActivityPub"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from utils import hasObjectString
|
from utils import hasObjectString
|
||||||
from utils import hasObjectStringObject
|
from utils import hasObjectStringObject
|
||||||
|
@ -35,6 +36,21 @@ from auth import createBasicAuthHeader
|
||||||
from posts import getPersonBox
|
from posts import getPersonBox
|
||||||
|
|
||||||
|
|
||||||
|
emojiRegex = re.compile(r'[\u263a-\U0001f645]')
|
||||||
|
|
||||||
|
|
||||||
|
def validEmojiContent(emojiContent: str) -> bool:
|
||||||
|
"""Is the given emoji content valid?
|
||||||
|
"""
|
||||||
|
if not emojiContent:
|
||||||
|
return False
|
||||||
|
if len(emojiContent) > 1:
|
||||||
|
return False
|
||||||
|
if len(emojiRegex.findall(emojiContent)) == 0:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def noOfReactions(postJsonObject: {}, emojiContent: str) -> int:
|
def noOfReactions(postJsonObject: {}, emojiContent: str) -> int:
|
||||||
"""Returns the number of emoji reactions of a given content type on a post
|
"""Returns the number of emoji reactions of a given content type on a post
|
||||||
"""
|
"""
|
||||||
|
@ -75,6 +91,9 @@ def _reaction(recentPostsCache: {},
|
||||||
"""
|
"""
|
||||||
if not urlPermitted(objectUrl, federationList):
|
if not urlPermitted(objectUrl, federationList):
|
||||||
return None
|
return None
|
||||||
|
if not validEmojiContent(emojiContent):
|
||||||
|
print('_reaction: Invalid emoji reaction: "' + emojiContent + '"')
|
||||||
|
return
|
||||||
|
|
||||||
fullDomain = getFullDomain(domain, port)
|
fullDomain = getFullDomain(domain, port)
|
||||||
|
|
||||||
|
@ -179,6 +198,10 @@ def sendReactionViaServer(baseDir: str, session,
|
||||||
if not session:
|
if not session:
|
||||||
print('WARN: No session for sendReactionViaServer')
|
print('WARN: No session for sendReactionViaServer')
|
||||||
return 6
|
return 6
|
||||||
|
if not validEmojiContent(emojiContent):
|
||||||
|
print('sendReactionViaServer: Invalid emoji reaction: "' +
|
||||||
|
emojiContent + '"')
|
||||||
|
return 7
|
||||||
|
|
||||||
fromDomainFull = getFullDomain(fromDomain, fromPort)
|
fromDomainFull = getFullDomain(fromDomain, fromPort)
|
||||||
|
|
||||||
|
@ -363,6 +386,10 @@ def outboxReaction(recentPostsCache: {},
|
||||||
return
|
return
|
||||||
if not isinstance(messageJson['content'], str):
|
if not isinstance(messageJson['content'], str):
|
||||||
return
|
return
|
||||||
|
if not validEmojiContent(messageJson['content']):
|
||||||
|
print('outboxReaction: Invalid emoji reaction: "' +
|
||||||
|
messageJson['content'] + '"')
|
||||||
|
return
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s reaction request arrived in outbox')
|
print('DEBUG: c2s reaction request arrived in outbox')
|
||||||
|
|
||||||
|
|
11
tests.py
11
tests.py
|
@ -109,6 +109,7 @@ from like import likePost
|
||||||
from like import sendLikeViaServer
|
from like import sendLikeViaServer
|
||||||
from reaction import reactionPost
|
from reaction import reactionPost
|
||||||
from reaction import sendReactionViaServer
|
from reaction import sendReactionViaServer
|
||||||
|
from reaction import validEmojiContent
|
||||||
from announce import announcePublic
|
from announce import announcePublic
|
||||||
from announce import sendAnnounceViaServer
|
from announce import sendAnnounceViaServer
|
||||||
from city import parseNogoString
|
from city import parseNogoString
|
||||||
|
@ -5909,6 +5910,15 @@ def _testAddCWfromLists(baseDir: str) -> None:
|
||||||
assert postJsonObject['object']['summary'] == "Murdoch Press / Existing CW"
|
assert postJsonObject['object']['summary'] == "Murdoch Press / Existing CW"
|
||||||
|
|
||||||
|
|
||||||
|
def _testValidEmojiContent() -> None:
|
||||||
|
print('testValidEmojiContent')
|
||||||
|
assert not validEmojiContent(None)
|
||||||
|
assert not validEmojiContent(' ')
|
||||||
|
assert not validEmojiContent('j')
|
||||||
|
assert validEmojiContent('😀')
|
||||||
|
assert validEmojiContent('😄')
|
||||||
|
|
||||||
|
|
||||||
def runAllTests():
|
def runAllTests():
|
||||||
baseDir = os.getcwd()
|
baseDir = os.getcwd()
|
||||||
print('Running tests...')
|
print('Running tests...')
|
||||||
|
@ -5916,6 +5926,7 @@ def runAllTests():
|
||||||
_translateOntology(baseDir)
|
_translateOntology(baseDir)
|
||||||
_testGetPriceFromString()
|
_testGetPriceFromString()
|
||||||
_testFunctions()
|
_testFunctions()
|
||||||
|
_testValidEmojiContent()
|
||||||
_testAddCWfromLists(baseDir)
|
_testAddCWfromLists(baseDir)
|
||||||
_testWordsSimilarity()
|
_testWordsSimilarity()
|
||||||
_testSecondsBetweenPublished()
|
_testSecondsBetweenPublished()
|
||||||
|
|
Loading…
Reference in New Issue