diff --git a/acceptreject.py b/acceptreject.py index 04a5f4779..ab1a5b888 100644 --- a/acceptreject.py +++ b/acceptreject.py @@ -193,3 +193,36 @@ def receiveAcceptReject(session,baseDir: str, \ if debug: print('DEBUG: Uh, '+messageJson['type']+', I guess') return True + +def manualDenyFollowRequest(baseDir: str,nickname: str,domain: str,denyHandle: str) -> None: + """Manually deny a follow request + """ + handle=args.nickname+'@'+domain + accountsDir=baseDir+'/accounts/'+handle + approveFollowsFilename=accountDir+'/followrequests.txt' + if handle in open(approveFollowsFilename).read(): + with open(approveFollowsFilename+'.new', 'w') as approvefilenew: + with open(approveFollowsFilename, 'r') as approvefile: + for approveHandle in approvefile: + if not approveHandle.startswith(denyHandle): + approvefilenew.write(approveHandle) + os.rename(approveFollowsFilename+'.new',approveFollowsFilename) + print('Follow request from '+denyHandle+' was denied.') + +def manualApproveFollowRequest(baseDir: str,nickname: str,domain: str,approveHandle: str): + """Manually approve a follow request + """ + handle=nickname+'@'+domain + accountsDir=baseDir+'/accounts/'+handle + approveFollowsFilename=accountDir+'/followrequests.txt' + if handle in open(approveFollowsFilename).read(): + with open(approveFollowsFilename+'.new', 'w') as approvefilenew: + with open(approveFollowsFilename, 'r') as approvefile: + for handle in approvefile: + if handle.startswith(approveHandle): + if ':' in handle: + port=int(handle.split(':')[1].replace('\n','')) + # TODO approve follow for handle/port + else: + approvefilenew.write(handle) + os.rename(approveFollowsFilename+'.new',approveFollowsFilename) diff --git a/epicyon.py b/epicyon.py index f1bba8358..50554d6f9 100644 --- a/epicyon.py +++ b/epicyon.py @@ -70,6 +70,8 @@ from roles import sendRoleViaServer from skills import sendSkillViaServer from availability import setAvailability from availability import sendAvailabilityViaServer +from acceptreject import manualDenyFollowRequest +from acceptreject import manualApproveFollowRequest import argparse def str2bool(v): @@ -334,20 +336,7 @@ if args.approve: if '@' not in args.approve: print('syntax: --approve nick@domain') sys.exit() - handle=args.nickname+'@'+domain - accountsDir=baseDir+'/accounts/'+handle - approveFollowsFilename=accountDir+'/followrequests.txt' - if handle in open(approveFollowsFilename).read(): - with open(approveFollowsFilename+'.new', 'w') as approvefilenew: - with open(approveFollowsFilename, 'r') as approvefile: - for approveHandle in approvefile: - if approveHandle.startswith(args.approve): - if ':' in approveHandle: - port=int(approveHandle.split(':')[1].replace('\n','')) - # TODO approve follow for handle/port - else: - approvefilenew.write(approveHandle) - os.rename(approveFollowsFilename+'.new',approveFollowsFilename) + manualApproveFollowRequest(baseDir,args.nickname,domain,args.approve) sys.exit() if args.deny: @@ -357,17 +346,7 @@ if args.deny: if '@' not in args.deny: print('syntax: --deny nick@domain') sys.exit() - handle=args.nickname+'@'+domain - accountsDir=baseDir+'/accounts/'+handle - approveFollowsFilename=accountDir+'/followrequests.txt' - if handle in open(approveFollowsFilename).read(): - with open(approveFollowsFilename+'.new', 'w') as approvefilenew: - with open(approveFollowsFilename, 'r') as approvefile: - for approveHandle in approvefile: - if not approveHandle.startswith(args.deny): - approvefilenew.write(approveHandle) - os.rename(approveFollowsFilename+'.new',approveFollowsFilename) - print('Follow request from '+args.deny+' was denied.') + manualDenyFollowRequest(baseDir,args.nickname,domain,args.deny) sys.exit() if args.followerspending: