From c9a0167d5506b76e2c13c5d7599cee53b7535559 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 20 Jul 2019 18:00:23 +0100 Subject: [PATCH] Move follow approval functions --- acceptreject.py | 33 +++++++++++++++++++++++++++++++++ epicyon.py | 29 ++++------------------------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/acceptreject.py b/acceptreject.py index 04a5f477..ab1a5b88 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 f1bba835..50554d6f 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: