Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 提升水平_Python - Fatal编程技术网

Python 提升水平

Python 提升水平,python,Python,我有一个chatango机器人,它具有升级和降级功能,可以使用某些命令。但一旦我提升某人,它也会将其添加到黑名单(1级),例如。如果我使用“升级”命令,而此人为0级,则会将其添加到成员列表中,并将其设置为1级,但由于这也会将其添加到黑名单中,因此也会将其设置为1级。正因为如此,如果我重新启动机器人,并试图提升某人,它就会变得一团糟 这是密码 # Command Usage: 'promote <username>, 'promote <username>

我有一个chatango机器人,它具有升级和降级功能,可以使用某些命令。但一旦我提升某人,它也会将其添加到黑名单(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
#命令用法:'promote',promote
elif使用了前缀和self.getAccess(user.name.lower())>=lvl\u config.rank\u req\u min\u promote和cmd==“promote”和len(args)>3:
整体=message.body.split(“,3)
升级\用户名=整个\正文[1]。下()
promote\u username=promote\u username.strip()
cur\u rank=self.getRank(升级\u用户名)
尝试:
下一个秩=0
如果在整体[2]中出现“-”:
next_rank=0-int(整体[2])
其他:
next_rank=int(整体[2])
user\u level=self.getAccess(升级\u用户名)
如果用户级别==lvl\u config.rank\u lvl\u botowner:
下一级=用户级
elif用户级别!=-1:
下一个等级=下一个等级
其他:
如果self.getAccess(user.name.lower())>=lvl\u config.rank\u req\u blacklist\u rem:
下一个等级=下一个等级
其他:
下一级=用户级
除:
用户级别=0
下一个秩=0
user\u level=self.getAccess(升级\u用户名)
如果用户级别==lvl\u config.rank\u lvl\u botowner:
下一级=用户级
elif用户级别!=-1:
下一级=用户级+1
其他:
如果self.getAccess(user.name.lower())>=lvl\u config.rank\u req\u blacklist\u rem:
下一级=用户级+1
其他:
下一级=用户级
如果next\u rank>len(ranks)-1和self.getAccess(user.name.lower())>=lvl\u config.rank\u lvl\u botowner和next\u rank>self.getAccess(升级\u用户名):
聊天信息(“抱歉%s,我无法升级%s,因为它们已经是我的%s(%s)之一)。”%(字体颜色、字体、字体大小、self.getAlias(user.name)、self.getAlias(升级用户名)、self.getRank(升级用户名)、self.getAccess(升级用户名)),True)
elif next\u rank=0和self.getAccess(user.name.lower())>=self.getAccess(升级用户名)+lvl\u config.rank\u req\u修饰符\u升级和next\u rank>self.getAccess(升级用户名):
打印(“%s,%s”%(str(升级用户名).strip(),str(用户级别).strip())
尝试:
删除(“%s,%s%”(str(升级用户名).strip(),str(用户级别).strip())
例外情况除外,如e:
打印(e)
如果下一个排名!=0:
users.append(“%s,%s%”(str(promote\u username).strip(),str(next\u rank).strip())
尝试:
聊天室消息(“%s”已从%s(%s)升级为%s(%s)。“%(字体颜色、字体、字体大小、self.getAlias(升级用户名)、cur\u排名、用户级别、self.getRank(升级用户名)、self.getAccess(升级用户名)),True)
例外情况除外,如e:
打印(e)
elif next\u rank==-1和self.getAccess(user.name.lower())=self.getAccess(升级用户名):
聊天信息(“%s”在黑名单上,您无法删除。请与级别为“%s”或更高访问权限的人联系。“%”(字体颜色、字体、字体大小、self.getAlias(升级用户名)、lvl\u配置、排名请求黑名单、True)
elif next\u rank==self.getAccess(升级\u用户名):
聊天室消息(“%s”已经是%s(%s)的排名)。“%(字体颜色、字体、字体大小、self.getAlias(升级用户名)、self.getRank(升级用户名)、self.getAccess(升级用户名)),True)
#现在保存所有数据。
self.savranges()
#结束命令
我只是不知道我做错了什么,对我来说一切都很好。谢谢你的帮助

附言:我是荷兰人,很抱歉英语不好

whole_body = message.body.split(" ", 3)
这将在单个空间上拆分。如果要按单词分割(即单词之间的任意数量的空格),请使用:


只要写下:

    promote_username = whole_body[1].lower().strip()

因为
int
可以是负数,所以这可能会给您一个双负数。例如,如果
整体[2]
-50
,那么
下一级=0-int(整体[2])=0-int(“-50”)=0--50=50
,您可能只需要:

next_rank = int(whole_body[2])

这没用。为什么在那里


您的
try
块操作过度。它正在丢弃实际的异常。在
try
块中放入较少的语句,并使
except
部分仅匹配某些异常(例如
ValueError

只有在需要放弃任何和所有异常时,或者在调用
raise
传播异常之前需要进行一些清理时,才应该使用catch all
except:



不管怎样,这就是我能想到的。您可能希望查看
日志记录
模块,并将
logging.debug()
调用放在这里的各个点上,以查看您的代码经过了哪些步骤,以及您的各种访问和级别得到了哪些值。

我也做了您告诉我的事情,直到我用if“+”替换整个\u body[2]:中的if“-”才起作用在整体[2]:它仍然将用户名放在两个列表中。我需要命令将用户置于成员列表,而不是成员列表和黑名单:(
    promote_username = whole_body[1].lower().strip()
if "-" in whole_body[2]:
    next_rank = 0 - int(whole_body[2])
else:
    next_rank = int(whole_body[2])
next_rank = int(whole_body[2])
next_rank = next_rank