2019-07-14 19:27:13 +00:00
|
|
|
__filename__ = "blocking.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
|
|
|
__version__ = "0.0.1"
|
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
def addBlock(baseDir: str,nickname: str,domain: str, \
|
2019-07-14 19:57:05 +00:00
|
|
|
blockNickname: str,blockDomain: str) -> bool:
|
2019-07-14 19:27:13 +00:00
|
|
|
"""Block the given account
|
|
|
|
"""
|
|
|
|
blockingFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/blocking.txt'
|
|
|
|
blockHandle=blockNickName+'@'+blockDomain
|
|
|
|
if os.path.isfile(blockingFilename):
|
|
|
|
if blockHandle in open(blockingFilename).read():
|
2019-07-14 19:57:05 +00:00
|
|
|
return False
|
2019-07-14 19:27:13 +00:00
|
|
|
blockFile=open(blockingFilename, "a+")
|
|
|
|
blockFile.write(blockHandle+'\n')
|
|
|
|
blockFile.close()
|
2019-07-14 19:57:05 +00:00
|
|
|
return True
|
2019-07-14 19:27:13 +00:00
|
|
|
|
|
|
|
def removeBlock(baseDir: str,nickname: str,domain: str, \
|
2019-07-14 19:57:05 +00:00
|
|
|
unblockNickname: str,unblockDomain: str) -> bool:
|
2019-07-14 19:27:13 +00:00
|
|
|
"""Unblock the given account
|
|
|
|
"""
|
|
|
|
unblockingFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/blocking.txt'
|
|
|
|
unblockHandle=unblockNickName+'@'+unblockDomain
|
|
|
|
if os.path.isfile(unblockingFilename):
|
|
|
|
if unblockHandle in open(unblockingFilename).read():
|
|
|
|
with open(unblockingFilename, 'r') as fp:
|
|
|
|
with open(unblockingFilename+'.new', 'w') as fpnew:
|
|
|
|
for line in fp:
|
|
|
|
handle=line.replace('\n','')
|
|
|
|
if unblockHandle not in line:
|
|
|
|
fpnew.write(handle+'\n')
|
|
|
|
if os.path.isfile(unblockingFilename+'.new'):
|
|
|
|
os.rename(unblockingFilename+'.new',unblockingFilename)
|
2019-07-14 19:57:05 +00:00
|
|
|
return True
|
|
|
|
return False
|
2019-07-14 19:27:13 +00:00
|
|
|
|
|
|
|
def isBlocked(baseDir: str,nickname: str,domain: str, \
|
|
|
|
blockNickname: str,blockDomain: str) -> bool:
|
|
|
|
"""Is the given nickname blocked?
|
|
|
|
"""
|
|
|
|
blockingFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/blocking.txt'
|
|
|
|
blockHandle=blockNickName+'@'+blockDomain
|
|
|
|
if os.path.isfile(blockingFilename):
|
|
|
|
if blockHandle in open(blockingFilename).read():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|