def accept(self, target_id): # 接受对方的好友申请 target_id = int(target_id) if target_id not in self.mf.accepting: raise SanguoException( errormsg.FRIEND_NOT_IN_ACCEPT_LIST, self.char_id, "Friend Accept", "character {0} not in accept list".format(target_id)) self.check_max_amount("Friend Accept") self.mf.accepting.remove(target_id) self.mf.friends.append(target_id) self.mf.save() target_char_friend = Friend(target_id) target_char_friend.someone_accept_me(self.char_id) self.send_update_friend_notify(target_id) new_friend_got_signal.send(sender=None, char_id=self.char_id, new_friend_id=target_id, total_friends_amount=self.real_cur_amount) self.send_friends_amount_notify()
def someone_accept_me(self, from_id): from_id = int(from_id) if from_id in self.mf.pending: self.mf.pending.remove(from_id) if from_id not in self.mf.friends: self.mf.friends.append(from_id) self.mf.save() self.send_new_friend_notify(from_id) new_friend_got_signal.send(sender=None, char_id=self.char_id, new_friend_id=from_id, total_friends_amount=self.real_cur_amount) self.send_friends_amount_notify()
def someone_accept_me(self, from_id): from_id = int(from_id) if from_id in self.mf.pending: self.mf.pending.remove(from_id) if from_id not in self.mf.friends: self.mf.friends.append(from_id) self.mf.save() self.send_new_friend_notify(from_id) new_friend_got_signal.send( sender=None, char_id=self.char_id, new_friend_id=from_id, total_friends_amount=self.real_cur_amount ) self.send_friends_amount_notify()
def accept(self, target_id): # 接受对方的好友申请 target_id = int(target_id) if target_id not in self.mf.accepting: raise SanguoException( errormsg.FRIEND_NOT_IN_ACCEPT_LIST, self.char_id, "Friend Accept", "character {0} not in accept list".format(target_id)) def _clean_target_pending(target_id): target = Friend(target_id) if self.char_id in target.mf.pending: target.mf.pending.remove(self.char_id) target.mf.save() target.send_remove_friend_notify([self.char_id]) target_char_friend = Friend(target_id) # 检查对方好友是否已满 if not target_char_friend.check_max_amount("Friend Accept By Other", raise_exception=False): # 对方满了 # 并且删除此人的申请 self.mf.accepting.remove(target_id) self.mf.save() self.send_remove_friend_notify([target_id]) _clean_target_pending(target_id) raise SanguoException( errormsg.FRIEND_OTHER_SIDE_IS_FULL, self.char_id, "Friend Accept", "other side {0} firend is full".format(target_id)) # 然后检查自己好友是否已满 try: self.check_max_amount("Friend Accept") except SanguoException as e: # 满了就清空所有申请 self.send_remove_friend_notify(self.mf.accepting) _accepting = self.mf.accepting self.mf.accepting = [] self.mf.save() for _acc in _accepting: _clean_target_pending(_acc) raise e self.mf.accepting.remove(target_id) self.mf.friends.append(target_id) self.mf.save() target_char_friend = Friend(target_id) target_char_friend.someone_accept_me(self.char_id) new_friend_got_signal.send(sender=None, char_id=self.char_id, new_friend_id=target_id, total_friends_amount=self.real_cur_amount) self.send_update_friend_notify(target_id) self.send_friends_amount_notify()
def accept(self, target_id): # 接受对方的好友申请 target_id = int(target_id) if target_id not in self.mf.accepting: raise SanguoException( errormsg.FRIEND_NOT_IN_ACCEPT_LIST, self.char_id, "Friend Accept", "character {0} not in accept list".format(target_id) ) def _clean_target_pending(target_id): target = Friend(target_id) if self.char_id in target.mf.pending: target.mf.pending.remove(self.char_id) target.mf.save() target.send_remove_friend_notify([self.char_id]) target_char_friend = Friend(target_id) # 检查对方好友是否已满 if not target_char_friend.check_max_amount("Friend Accept By Other", raise_exception=False): # 对方满了 # 并且删除此人的申请 self.mf.accepting.remove(target_id) self.mf.save() self.send_remove_friend_notify([target_id]) _clean_target_pending(target_id) raise SanguoException( errormsg.FRIEND_OTHER_SIDE_IS_FULL, self.char_id, "Friend Accept", "other side {0} firend is full".format(target_id) ) # 然后检查自己好友是否已满 try: self.check_max_amount("Friend Accept") except SanguoException as e: # 满了就清空所有申请 self.send_remove_friend_notify(self.mf.accepting) _accepting = self.mf.accepting self.mf.accepting = [] self.mf.save() for _acc in _accepting: _clean_target_pending(_acc) raise e self.mf.accepting.remove(target_id) self.mf.friends.append(target_id) self.mf.save() target_char_friend = Friend(target_id) target_char_friend.someone_accept_me(self.char_id) new_friend_got_signal.send( sender=None, char_id=self.char_id, new_friend_id=target_id, total_friends_amount=self.real_cur_amount ) self.send_update_friend_notify(target_id) self.send_friends_amount_notify()