points_stuff.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Basic-discord-bot 作者: TheWizoid 项目源码 文件源码
def add_points(message):
    """
    Every time someone sends a message, they gain one point.
    This is because any time based ones would result in mobile users having
    the same amount of each, due to idling.
    """

    split_message = message.content.split()

    message.author.name = message.author.name.lower()
    points = load_points(message, message.author.name)
    message_amount = messages.load_messages(message, message.author.name)

    non_trigger = ["!points","!roulette","!userpoints","!givepoints","!barryroulette","!rps","!rockpaperscissors"]
    non_message_trigger = ["!usermessages","!messages"]
    if message.author.name not in message_amount:
        message_amount[message.author.name] = 0
    elif len(split_message) == 0 or split_message[0] not in non_message_trigger:
        message_amount[message.author.name] += 1

    if message.author.name not in points:
        points[message.author.name] = 0
    elif len(split_message) == 0 or split_message[0] not in non_trigger:
        points[message.author.name] += 1

    try:
        pickle.dump(points, open("{0}/{0}_points.txt".format(str(message.server)),"wb"))
    except FileNotFoundError:
        try:
            os.makedir("{}".format(message.server))
        except FileExistsError:
            temp_points = open("{0}/{0}_points.txt".format(str(message.server)),"w")
            temp_points.close()
        pickle.dump(points, open("{0}/{0}_points.txt".format(str(message.server)),"wb"))
    pickle.dump(message_amount, open("{0}/{0}_messages.txt".format(str(message.server)),"wb"))
    return True

#Sets emotes in points, is its own function due to me using it twice.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号