mirror of https://gitlab.com/bashrc2/epicyon
Move announce function
parent
8f12dbbf02
commit
b208ec623d
61
announce.py
61
announce.py
|
@ -711,3 +711,64 @@ def update_announce_collection(recent_posts_cache: {},
|
|||
print('DEBUG: saving post with shares (announcements) added')
|
||||
pprint(post_json_object)
|
||||
save_json(post_json_object, post_filename)
|
||||
|
||||
|
||||
def disallow_announce(content: str, attachment: [], capabilities: {}) -> bool:
|
||||
"""Are announces/boosts not allowed for the given post?
|
||||
"""
|
||||
# pixelfed style capabilities
|
||||
if capabilities:
|
||||
if 'announce' in capabilities:
|
||||
if isinstance(capabilities['announce'], str):
|
||||
if not capabilities['announce'].endswith('#Public'):
|
||||
# TODO handle non-public announce permissions
|
||||
print('CAPABILITIES: announce ' + capabilities['announce'])
|
||||
return True
|
||||
else:
|
||||
# capabilities exist but with no announce defined
|
||||
return True
|
||||
|
||||
# emojis
|
||||
disallow_strings = (
|
||||
':boost_no:',
|
||||
':noboost:',
|
||||
':noboosts:',
|
||||
':no_boost:',
|
||||
':no_boosts:',
|
||||
':boosts_no:',
|
||||
'dont_repeat',
|
||||
'dont_announce',
|
||||
'dont_boost',
|
||||
'do not boost',
|
||||
"don't boost",
|
||||
'boost_denied',
|
||||
'boosts_denied',
|
||||
'boostdenied',
|
||||
'boostsdenied'
|
||||
)
|
||||
content_lower = content.lower()
|
||||
for diss in disallow_strings:
|
||||
if diss in content_lower:
|
||||
return True
|
||||
|
||||
# check for attached images without descriptions
|
||||
if isinstance(attachment, list):
|
||||
for item in attachment:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
if not item.get('mediaType'):
|
||||
continue
|
||||
if not item.get('url'):
|
||||
continue
|
||||
if not item['mediaType'].startswith('image/'):
|
||||
continue
|
||||
if not item.get('name'):
|
||||
# no image description
|
||||
return True
|
||||
image_description = item['name']
|
||||
if not isinstance(image_description, str):
|
||||
continue
|
||||
if len(image_description) < 5:
|
||||
# not enough description
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -25,7 +25,6 @@ from utils import get_attributed_to
|
|||
from utils import remove_html
|
||||
from utils import safe_system_string
|
||||
from utils import text_in_file
|
||||
from utils import disallow_announce
|
||||
from utils import disallow_reply
|
||||
from utils import get_base_content_from_post
|
||||
from utils import has_object_dict
|
||||
|
@ -60,6 +59,7 @@ from posts import c2s_box_json
|
|||
from posts import download_announce
|
||||
from announce import send_announce_via_server
|
||||
from announce import send_undo_announce_via_server
|
||||
from announce import disallow_announce
|
||||
from pgp import pgp_local_public_key
|
||||
from pgp import pgp_decrypt
|
||||
from pgp import has_local_pg_pkey
|
||||
|
|
61
utils.py
61
utils.py
|
@ -3348,67 +3348,6 @@ def _is_i2p_request(calling_domain: str, referer_domain: str,
|
|||
return False
|
||||
|
||||
|
||||
def disallow_announce(content: str, attachment: [], capabilities: {}) -> bool:
|
||||
"""Are announces/boosts not allowed for the given post?
|
||||
"""
|
||||
# pixelfed style capabilities
|
||||
if capabilities:
|
||||
if 'announce' in capabilities:
|
||||
if isinstance(capabilities['announce'], str):
|
||||
if not capabilities['announce'].endswith('#Public'):
|
||||
# TODO handle non-public announce permissions
|
||||
print('CAPABILITIES: announce ' + capabilities['announce'])
|
||||
return True
|
||||
else:
|
||||
# capabilities exist but with no announce defined
|
||||
return True
|
||||
|
||||
# emojis
|
||||
disallow_strings = (
|
||||
':boost_no:',
|
||||
':noboost:',
|
||||
':noboosts:',
|
||||
':no_boost:',
|
||||
':no_boosts:',
|
||||
':boosts_no:',
|
||||
'dont_repeat',
|
||||
'dont_announce',
|
||||
'dont_boost',
|
||||
'do not boost',
|
||||
"don't boost",
|
||||
'boost_denied',
|
||||
'boosts_denied',
|
||||
'boostdenied',
|
||||
'boostsdenied'
|
||||
)
|
||||
content_lower = content.lower()
|
||||
for diss in disallow_strings:
|
||||
if diss in content_lower:
|
||||
return True
|
||||
|
||||
# check for attached images without descriptions
|
||||
if isinstance(attachment, list):
|
||||
for item in attachment:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
if not item.get('mediaType'):
|
||||
continue
|
||||
if not item.get('url'):
|
||||
continue
|
||||
if not item['mediaType'].startswith('image/'):
|
||||
continue
|
||||
if not item.get('name'):
|
||||
# no image description
|
||||
return True
|
||||
image_description = item['name']
|
||||
if not isinstance(image_description, str):
|
||||
continue
|
||||
if len(image_description) < 5:
|
||||
# not enough description
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def disallow_reply(content: str) -> bool:
|
||||
"""Are replies not allowed for the given post?
|
||||
"""
|
||||
|
|
|
@ -20,6 +20,7 @@ from bookmarks import bookmarked_by_person
|
|||
from announce import update_announce_collection
|
||||
from announce import announced_by_person
|
||||
from announce import no_of_announces
|
||||
from announce import disallow_announce
|
||||
from like import liked_by_person
|
||||
from like import no_of_likes
|
||||
from follow import is_following_actor
|
||||
|
@ -54,7 +55,6 @@ from utils import remove_style_within_html
|
|||
from utils import license_link_from_name
|
||||
from utils import dont_speak_hashtags
|
||||
from utils import remove_eol
|
||||
from utils import disallow_announce
|
||||
from utils import disallow_reply
|
||||
from utils import remove_hash_from_post_id
|
||||
from utils import remove_html
|
||||
|
|
Loading…
Reference in New Issue