我有一个聊天机器人,它具有升级和降级功能,以便使用某些命令。但是,一旦我提拔某人,它也会将他们添加到黑名单(-1 级)中,例如。如果我使用提升命令并且此人是 0 级,它会将他们添加到成员列表并使他/她成为 1 级,但由于它也将它们添加到黑名单中,它也会给他们 -1 级。正因为如此,如果我重新启动机器人并尝试提升某人,它就会变得一团糟。
这是代码。
# Command Usage: 'promote <username>, 'promote <username> <rank>
elif used_prefix and self.getAccess(user.name.lower()) >= lvl_config.rank_req_min_promote and cmd == "promote" and len(args) > 3:
whole_body = message.body.split(" ", 3)
promote_username = whole_body[1].lower()
promote_username = promote_username.strip()
cur_rank = self.getRank(promote_username)
try:
next_rank = 0
if "-" in whole_body[2]:
next_rank = 0 - int(whole_body[2])
else:
next_rank = int(whole_body[2])
user_level = self.getAccess(promote_username)
if user_level == lvl_config.rank_lvl_botowner:
next_rank = user_level
elif user_level != -1:
next_rank = next_rank
else:
if self.getAccess(user.name.lower()) >= lvl_config.rank_req_blacklist_rem:
next_rank = next_rank
else:
next_rank = user_level
except:
user_level = 0
next_rank = 0
user_level = self.getAccess(promote_username)
if user_level == lvl_config.rank_lvl_botowner:
next_rank = user_level
elif user_level != -1:
next_rank = user_level + 1
else:
if self.getAccess(user.name.lower()) >= lvl_config.rank_req_blacklist_rem:
next_rank = user_level + 1
else:
next_rank = user_level
if next_rank > len(ranks) - 1 and self.getAccess(user.name.lower()) >= lvl_config.rank_lvl_botowner and next_rank > self.getAccess(promote_username):
chat_message("<font color='#%s' face='%s' size='%s'>Sorry <b>%s</b>, I couldn't promote <b>%s</b> as they are already one of my <b>%s (%s)</b>.</font>" % (font_color, font_face, font_size, self.getAlias(user.name), self.getAlias(promote_username), self.getRank(promote_username), self.getAccess(promote_username)), True)
elif next_rank <= len(ranks) - 1 and next_rank >= 0 and self.getAccess(user.name.lower()) >= self.getAccess(promote_username) + lvl_config.rank_req_modifier_promote and next_rank > self.getAccess(promote_username):
print("%s,%s" % (str(promote_username).strip(), str(user_level).strip()))
try:
users.remove("%s,%s" % (str(promote_username).strip(), str(user_level).strip()))
except Exception as e:
print(e)
if next_rank != 0:
users.append("%s,%s" % (str(promote_username).strip(), str(next_rank).strip()))
try:
chat_message("<font color='#%s' face='%s' size='%s'><b>%s</b> has been promoted from <b>%s (%s)</b> and is now <b>%s (%s)</b>.</font>" % (font_color, font_face, font_size, self.getAlias(promote_username), cur_rank, user_level, self.getRank(promote_username), self.getAccess(promote_username)), True)
except Exception as e:
print(e)
elif next_rank == -1 and self.getAccess(user.name.lower()) < lvl_config.rank_req_blacklist_rem and next_rank >= self.getAccess(promote_username):
chat_message("<font color='#%s' face='%s' size='%s'><b>%s</b> is on the blacklist and cannot be removed by you. Contact a person with level %s or higher access.</font>" % (font_color, font_face, font_size, self.getAlias(promote_username), lvl_config.rank_req_blacklist_rem), True)
elif next_rank == self.getAccess(promote_username):
chat_message("<font color='#%s' face='%s' size='%s'><b>%s</b> is already a rank of %s (%s).</font>" % (font_color, font_face, font_size, self.getAlias(promote_username), self.getRank(promote_username), self.getAccess(promote_username)), True)
# Save all the data now.
self.savRanks()
# End Command
我只是无法弄清楚我做错了什么,一切对我来说似乎都很好。谢谢您的帮助!
PS:我是荷兰人,很抱歉英语不好!