Optionally remove twitter crossposts

main
Bob Mottram 2020-02-05 14:57:10 +00:00
parent a8a90b9245
commit fad14d0f0c
19 changed files with 70 additions and 16 deletions

View File

@ -4252,6 +4252,19 @@ class PubServer(BaseHTTPRequestHandler):
if not followDMsActive: if not followDMsActive:
if os.path.isfile(followDMsFilename): if os.path.isfile(followDMsFilename):
os.remove(followDMsFilename) os.remove(followDMsFilename)
# remove Twitter retweets
removeTwitterFilename= \
self.server.baseDir+'/accounts/'+ \
nickname+'@'+self.server.domain+'/.removeTwitter'
removeTwitterActive=False
if fields.get('removeTwitter'):
if fields['removeTwitter']=='on':
removeTwitterActive=True
with open(removeTwitterFilename, "w") as removeTwitterFile:
removeTwitterFile.write('\n')
if not removeTwitterActive:
if os.path.isfile(removeTwitterFilename):
os.remove(removeTwitterFilename)
# this account is a bot # this account is a bot
if fields.get('isBot'): if fields.get('isBot'):
if fields['isBot']=='on': if fields['isBot']=='on':

View File

@ -38,12 +38,27 @@ def removeFilter(baseDir: str,nickname: str,domain: str, \
return True return True
return False return False
def isTwitterPost(content: str) -> bool:
"""Returns true if the given post content is a retweet or twitter crosspost
"""
if content.contains('/twitter.com') or content.contains('@twitter.com'):
return True
elif content.contains('RT:'):
return True
return False
def isFiltered(baseDir: str,nickname: str,domain: str,content: str) -> bool: def isFiltered(baseDir: str,nickname: str,domain: str,content: str) -> bool:
"""Should the given content be filtered out? """Should the given content be filtered out?
This is a simple type of filter which just matches words, not a regex This is a simple type of filter which just matches words, not a regex
You can add individual words or use word1+word2 to indicate that two You can add individual words or use word1+word2 to indicate that two
words must be present although not necessarily adjacent words must be present although not necessarily adjacent
""" """
# optionally remove retweets
removeTwitter=baseDir+'/accounts/'+nickname+'@'+domain+'/.removeTwitter'
if os.path.isfile(removeTwitter):
if isTwitterPost(content):
return True
filtersFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/filters.txt' filtersFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/filters.txt'
if os.path.isfile(filtersFilename): if os.path.isfile(filtersFilename):
with open(filtersFilename, 'r') as fp: with open(filtersFilename, 'r') as fp:

View File

@ -51,6 +51,7 @@ from content import replaceEmojiFromTags
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
from config import getConfigParam from config import getConfigParam
from blocking import isBlocked from blocking import isBlocked
from filters import isFiltered
try: try:
from BeautifulSoup import BeautifulSoup from BeautifulSoup import BeautifulSoup
except ImportError: except ImportError:
@ -2721,6 +2722,12 @@ def downloadAnnounce(session,baseDir: str,httpPrefix: str, \
rejectAnnounce(announceFilename) rejectAnnounce(announceFilename)
#pprint(announcedJson) #pprint(announcedJson)
return None return None
if not announcedJson.get('content'):
rejectAnnounce(announceFilename)
return None
if isFiltered(baseDir,nickname,domain,announcedJson['content']):
rejectAnnounce(announceFilename)
return None
# wrap in create to be consistent with other posts # wrap in create to be consistent with other posts
announcedJson= \ announcedJson= \

View File

@ -206,5 +206,6 @@
"Email": "البريد الإلكتروني", "Email": "البريد الإلكتروني",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "هذا هو المقرر المقرر.", "This is a scheduled post.": "هذا هو المقرر المقرر.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "Correu electrònic", "Email": "Correu electrònic",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "Aquesta és una publicació programada.", "This is a scheduled post.": "Aquesta és una publicació programada.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "E-bost", "Email": "E-bost",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "Mae hon yn swydd wedi'i hamserlennu.", "This is a scheduled post.": "Mae hon yn swydd wedi'i hamserlennu.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "Email", "Email": "Email",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "Dies ist ein geplanter Beitrag.", "This is a scheduled post.": "Dies ist ein geplanter Beitrag.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "Email", "Email": "Email",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "This is a scheduled post.", "This is a scheduled post.": "This is a scheduled post.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "Email", "Email": "Email",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "Esta es una publicación programada.", "This is a scheduled post.": "Esta es una publicación programada.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "Email", "Email": "Email",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "Il s'agit d'un article programmé.", "This is a scheduled post.": "Il s'agit d'un article programmé.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "Ríomhphost", "Email": "Ríomhphost",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "Is post sceidealta é seo.", "This is a scheduled post.": "Is post sceidealta é seo.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "ईमेल", "Email": "ईमेल",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "यह एक अनुसूचित पद है।", "This is a scheduled post.": "यह एक अनुसूचित पद है।",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "E-mail", "Email": "E-mail",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "Questo è un post programmato", "This is a scheduled post.": "Questo è un post programmato",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "Eメール", "Email": "Eメール",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "これはスケジュールされた投稿です。", "This is a scheduled post.": "これはスケジュールされた投稿です。",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -202,5 +202,6 @@
"Email": "Email", "Email": "Email",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "This is a scheduled post.", "This is a scheduled post.": "This is a scheduled post.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "Email", "Email": "Email",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "Esta é uma postagem agendada.", "This is a scheduled post.": "Esta é uma postagem agendada.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "Эл. адрес", "Email": "Эл. адрес",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "Это запланированный пост.", "This is a scheduled post.": "Это запланированный пост.",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -206,5 +206,6 @@
"Email": "电子邮件", "Email": "电子邮件",
"PGP": "PGP", "PGP": "PGP",
"This is a scheduled post.": "这是预定的帖子。", "This is a scheduled post.": "这是预定的帖子。",
"Remove scheduled posts": "Remove scheduled posts" "Remove scheduled posts": "Remove scheduled posts",
"Remove Twitter posts": "Remove Twitter posts"
} }

View File

@ -597,6 +597,7 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
isBot='' isBot=''
isGroup='' isGroup=''
followDMs='' followDMs=''
removeTwitter=''
mediaInstanceStr='' mediaInstanceStr=''
displayNickname=nickname displayNickname=nickname
bioStr='' bioStr=''
@ -631,6 +632,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
isBot='' isBot=''
if os.path.isfile(baseDir+'/accounts/'+nickname+'@'+domain+'/.followDMs'): if os.path.isfile(baseDir+'/accounts/'+nickname+'@'+domain+'/.followDMs'):
followDMs='checked' followDMs='checked'
if os.path.isfile(baseDir+'/accounts/'+nickname+'@'+domain+'/.removeTwitter'):
removeTwitter='checked'
mediaInstance=getConfigParam(baseDir,"mediaInstance") mediaInstance=getConfigParam(baseDir,"mediaInstance")
if mediaInstance: if mediaInstance:
@ -772,6 +775,7 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
editProfileForm+=' <input type="checkbox" class="profilecheckbox" name="isBot" '+isBot+'>'+translate['This is a bot account']+'<br>' editProfileForm+=' <input type="checkbox" class="profilecheckbox" name="isBot" '+isBot+'>'+translate['This is a bot account']+'<br>'
editProfileForm+=' <input type="checkbox" class="profilecheckbox" name="isGroup" '+isGroup+'>'+translate['This is a group account']+'<br>' editProfileForm+=' <input type="checkbox" class="profilecheckbox" name="isGroup" '+isGroup+'>'+translate['This is a group account']+'<br>'
editProfileForm+=' <input type="checkbox" class="profilecheckbox" name="followDMs" '+followDMs+'>'+translate['Only people I follow can send me DMs']+'<br>' editProfileForm+=' <input type="checkbox" class="profilecheckbox" name="followDMs" '+followDMs+'>'+translate['Only people I follow can send me DMs']+'<br>'
editProfileForm+=' <input type="checkbox" class="profilecheckbox" name="removeTwitter" '+removeTwitter+'>'+translate['Remove Twitter posts']+'<br>'
if path.startswith('/users/'+adminNickname+'/'): if path.startswith('/users/'+adminNickname+'/'):
editProfileForm+=' <input type="checkbox" class="profilecheckbox" name="mediaInstance" '+mediaInstanceStr+'>'+translate['This is a media instance']+'<br>' editProfileForm+=' <input type="checkbox" class="profilecheckbox" name="mediaInstance" '+mediaInstanceStr+'>'+translate['This is a media instance']+'<br>'
editProfileForm+=' <br><b><label class="labels">'+translate['Filtered words']+'</label></b>' editProfileForm+=' <br><b><label class="labels">'+translate['Filtered words']+'</label></b>'