def while_waiting(self): global FriendList, RunSettings, NASCClient #npyscreen.notify_wait("Update") RunSettings.UpdateRunTime() self.lblRuntime.value = RunSettings.RunTime self.lblBotCount.value = str(RunSettings.BotterCount) self.lblMyFriendCode.value = friend_functions.FormattedFriendCode(RunSettings.friendcode) if RunSettings.active == 1: self.lblActive.value="True" else: self.lblActive.value = "False" flist = [friend_functions.FormattedFriendCode(x.fc) for x in FriendList.added] self.addedfriendslist.footer = "("+str(len(FriendList.added))+")" self.addedfriendslist.values = flist flist = [friend_functions.FormattedFriendCode(x.fc) for x in FriendList.lfcs] self.lfcslist.footer="("+str(len(FriendList.lfcs))+")" self.lfcslist.values = flist self.unfriendlist.footer="("+str(len(FriendList.remove))+")" flist = [friend_functions.FormattedFriendCode(friend_functions.PID2FC(x)) for x in FriendList.remove] self.unfriendlist.values = flist connected=NASCClient.IsConnected() if connected: self.lblConnected.value="Connected" else: self.lblConnected.value="Disconnected" self.getFriendsCB.value=RunSettings.active == 1 self.display()
def HandleNewFriends(): global FriendList, NASCClient FriendList.notadded = list(set(FriendList.notadded)) ## remove duplicates for fc in FriendList.notadded[:]: #while len(FriendList.notadded) > 0: curFriends = [x.fc for x in FriendList.added] curFriends.extend([x.fc for x in FriendList.lfcs]) curFriends.extend([friend_functions.PID2FC(x) for x in FriendList.remove]) #fc = FriendList.notadded[0] # remove from the actual list FriendList.notadded.remove(fc) # if not a valid friend, go to the next in the list if not friend_functions.is_valid_fc(fc): continue # if already on one of our lists, go to the next on the list if len([x for x in curFriends if x == fc]) > 0: continue logging.info("Adding friend %s",friend_functions.FormattedFriendCode(fc)) print("[",datetime.now(),"] Adding friend:",friend_functions.FormattedFriendCode(fc)) time.sleep(Intervals.betweenNintendoActions) #TODO error check this vvv rel = NASCClient.AddFriendFC(fc) if not rel is None: if rel.is_complete==True: logging.warning("NewFriends: Friend %s already completed, moving to LFCS list",friend_functions.FormattedFriendCode(fc)) print("[",datetime.now(),"] NewFriends: Friend",friend_functions.FormattedFriendCode(fc),"already completed, moving to LFCS list") p = friend_functions.process_friend(fc) p.lfcs = rel.friend_code FriendList.lfcs.append(p) #added_friends = [x for x in added_friends if x.pid != p.pid] else: FriendList.added.append(friend_functions.process_friend(fc))
def __init__(self,pid,lfcs): self.UI = False self.version = 0x200 self.active=1 self.friendcode = friend_functions.PID2FC(pid) self.pid = pid self.lfcs=lfcs self.BotterCount=0 self.ServerErrorCount=0 self.NintendoErrorCount=0 self.StartTime = datetime.utcnow() self.RunTime = str(datetime.utcnow() - self.StartTime).split(".")[0] self.Running = True self.LastGameChange = datetime.utcnow() self.CurrentGame = 0x0004000000131200 self.PauseUntil = datetime.utcnow() self.WaitForFriending = datetime.utcnow() self.WaitForResync = datetime.utcnow()
def sh_thread(): global RunSettings, NASCClient, FriendList #print("Running bot as",myFriendCode[0:4]+"-"+myFriendCode[4:8]+"-"+myFriendCode[8:]) while RunSettings.Running==True: try: if datetime.utcnow() < RunSettings.PauseUntil: continue if not Web.IsConnected(): RunSettings.PauseUntil = datetime.utcnow()+timedelta(seconds=Intervals.error_wait) if NASCClient.Error() > 0: RunSettings.PauseUntil = datetime.utcnow()+timedelta(seconds=Intervals.nintendo_wait) UnClaimAll() #RunSettings.active=0 #Web.SetActive(0) NASCClient.reconnect() clist = Web.getClaimedList() ## if the site doesnt have a fc as claimed, i shouldnt either ## unfriend anyone on my list that the website doesnt have for me FriendList.remove.extend([x.pid for x in FriendList.added if x.fc not in clist]) ## remove the "others" from the added friends list FriendList.added = [x for x in FriendList.added if x.fc in clist] ## compare the claimed list with the current friends lists and add new friends to notadded addedfcs = [x.fc for x in FriendList.added] addedfcs.extend([x.fc for x in FriendList.notadded]) addedfcs.extend([x.fc for x in FriendList.lfcs]) addedfcs.extend([friend_functions.PID2FC(x) for x in FriendList.remove]) clist = [x for x in clist if not x in addedfcs and len(x)==12] if len(clist) > 0: logging.warning("%s friends already claimed, queued for adding", len(clist)) print (len(clist)," friends already claimed, queued for adding") FriendList.notadded.extend(clist) ## Receives current relationship status for all friends, then iterates through them to set the lfcs status if not currently set if datetime.utcnow() >= RunSettings.WaitForResync: time.sleep(Intervals.between_actions) logging.debug("Resyncing friend list") Handle_ReSync() RunSettings.WaitForResync = datetime.utcnow()+timedelta(seconds=Intervals.resync) time.sleep(Intervals.between_actions) ## iterates through lfcs queue, uploads lfcs to website. returns false if the process fails somewhere if not Handle_LFCSQueue(): logging.error("Could not completed LFCS queue processing") print("[",datetime.now(),"] could not complete LFCS queue processing") time.sleep(Intervals.between_actions) ## true if it makes it through the list, false otherwise if not Handle_FriendTimeouts(): logging.error("Could not completed friend timeout processing") print("[",datetime.now(),"] could not Timeout old friends") time.sleep(Intervals.between_actions) ## iterates through removal queue, uploads lfcs to website. returns false if the process fails somewhere if not Handle_RemoveQueue(): logging.error("Could not completed Remove queue processing") print("[",datetime.now(),"] Could not handle RemoveQueue") continue if datetime.utcnow() >= RunSettings.WaitForFriending: time.sleep(Intervals.between_actions) logging.debug("Getting new FCs") print("[",datetime.now(),"] Quest: seeking new friends for the end of the world") nlist = Web.getNewList() for x in nlist: if Web.ClaimFC(x): FriendList.notadded.append(x) RunSettings.WaitForFriending = datetime.utcnow()+timedelta(seconds=Intervals.get_friends) if len(FriendList.notadded) > 0: logging.debug("%s new FCs to process", len(FriendList.notadded)) print ("[",datetime.now(),"]",len(FriendList.notadded),"new friends") time.sleep(Intervals.between_actions) HandleNewFriends() except Exception as e: print("[",datetime.now(),"] Got exception!!", e,"\n",sys.exc_info()[0].__name__, sys.exc_info()[2].tb_frame.f_code.co_filename, sys.exc_info()[2].tb_lineno) logging.error("Exception found: %s\n%s\n%s\n%s",e,sys.exc_info()[0].__name__, sys.exc_info()[2].tb_frame.f_code.co_filename, sys.exc_info()[2].tb_lineno)
def Handle_ReSync(): global FriendList, NASCClient friends = [] try: friends = NASCClient.RefreshAllFriendData([x.pid for x in FriendList.added]) except Exception as e: print("[",datetime.now(),"] Got exception!!", e,"\n",sys.exc_info()[0].__name__, sys.exc_info()[2].tb_frame.f_code.co_filename, sys.exc_info()[2].tb_lineno) logging.error("Exception found: %s\n%s\n%s\n%s",e,sys.exc_info()[0].__name__, sys.exc_info()[2].tb_frame.f_code.co_filename, sys.exc_info()[2].tb_lineno) friends = [] try: print("[",datetime.now(),"] ReSync:",len(friends),"friends currently") for x in friends: logging.debug("ReSync: Checking friend for completion, refreshing: %s",friend_functions.FormattedFriendCode(friend_functions.PID2FC(x.principal_id))) p = friend_functions.process_friend.from_pid(x.principal_id) if x.is_complete == True: p.lfcs = x.friend_code logging.info("ReSync: Friend was completed, adding to lfcs queue: %s",friend_functions.FormattedFriendCode(p.fc)) print("[",datetime.now(),"] ReSync: Friend was completed, adding to lfcs queue:",friend_functions.FormattedFriendCode(p.fc)) FriendList.newlfcs.put(p) else: logging.debug("ReSync: Friend wasnt complete yet or is not in added friendlist: %s",friend_functions.FormattedFriendCode(p.fc)) except Exception as e: print("[",datetime.now(),"] Got exception!!", e,"\n",sys.exc_info()[0].__name__, sys.exc_info()[2].tb_frame.f_code.co_filename, sys.exc_info()[2].tb_lineno) logging.error("Exception found: %s\n%s\n%s\n%s",e,sys.exc_info()[0].__name__, sys.exc_info()[2].tb_frame.f_code.co_filename, sys.exc_info()[2].tb_lineno) return False return True
x=input("") x=x.lower() if x=='q' or x=="quit": RunSettings.Running = False print("Application quit initiated, closing") sh_thread_obj.join() print("Removing friends") #print("added friends list,",len(added_friends)) #print("lfcs list,",len(lfcs_queue)) #print("remove friends list,",len(remove_queue)) rmlist = [x.fc for x in FriendList.added] rmlist.extend([x.fc for x in FriendList.lfcs]) rmlist.extend([friend_functions.PID2FC(x) for x in FriendList.remove]) while len(rmlist) > 0: fc = rmlist[0] rmlist.pop(0) print("Removing",fc) if Web.ResetFC(fc)==True: time.sleep(Intervals.betweenNintendoActions) NASCClient.RemoveFriendFC(fc) else: rmlist.append(fc) print("All Friends removed") print("Disconnected NASC Client") NASCClient.UpdatePresence(RunSettings.CurrentGame,"goodbyte",False) NASCClient.disconnect