当前位置: 首页>>代码示例>>Python>>正文


Python User.region方法代码示例

本文整理汇总了Python中db.User.region方法的典型用法代码示例。如果您正苦于以下问题:Python User.region方法的具体用法?Python User.region怎么用?Python User.region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在db.User的用法示例。


在下文中一共展示了User.region方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_user

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import region [as 别名]
 def create_user(self, name, team):
     newbie = User(name=name, team=team, loyalists=100, leader=True)
     self.sess.add(newbie)
     cap = Region.capital_for(team, self.sess)
     newbie.region = cap
     self.sess.commit()
     return newbie
开发者ID:Dominoed,项目名称:chromabot,代码行数:9,代码来源:playtest.py

示例2: recruit_from_comment

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import region [as 别名]
    def recruit_from_comment(self, comment):
        session = self.session
        if not comment.author:  # Deleted comments don't have an author
            return
        name = comment.author.name.lower()
        if name == self.config.username.lower():
            return

        # Is this author already one of us?
        found = session.query(User).filter_by(
            name=name).first()
        if not found:
            # Getting the author ID triggers a lookup on the userpage.  In the
            # case of banned users, this will 404.  @failable would normally
            # catch that just fine, but I want to check it here so that in the
            # future, I can do things like e.g. add to an 'ignored' list and
            # save myself the lookup
            try:
                author_id = comment.author.id
            except NotFound:
                logging.warn("Ignored banned user %s" % name)
                return

            team = 0
            assignment = self.config['game']['assignment']
            if assignment == 'uid':
                base10_id = base36decode(author_id)
                team = base10_id % 2
            elif assignment == "random":
                team = random.randint(0, 1)
            is_leader = name in self.config["game"]["leaders"]
            newbie = User(name=name,
                          team=team,
                          loyalists=100,
                          leader=is_leader)
            session.add(newbie)

            cap = Region.capital_for(newbie.team, session)
            if not cap:
                logging.fatal("Could not find capital for %d" %
                              newbie.team)
            newbie.region = cap

            session.commit()
            logging.info("Created combatant %s", newbie)

            reply = ("Welcome to Chroma!  You are now a %s "
                     "in the %s army, commanding a force of loyalists "
                     "%d people strong. You are currently encamped at %s"
            ) % (newbie.rank,
                 num_to_team(newbie.team, self.config),
                 newbie.loyalists,
                 cap.markdown())
            comment.reply(reply)
        else:
            #logging.info("Already registered %s", comment.author.name)
            pass
开发者ID:atiaxi,项目名称:chromabot,代码行数:59,代码来源:main.py

示例3: recruit_from_post

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import region [as 别名]
    def recruit_from_post(self, post):
        post.replace_more_comments(threshold=0)
        flat_comments = praw.helpers.flatten_tree(post.comments)
        session = self.session
        for comment in flat_comments:
            if not comment.author:  # Deleted comments don't have an author
                continue
            name = comment.author.name.lower()
            if name == self.config.username.lower():
                continue

            # Is this author already one of us?
            found = session.query(User).filter_by(name=name).first()
            if not found:
                team = 0
                assignment = self.config["game"]["assignment"]
                if assignment == "uid":
                    base10_id = base36decode(comment.author.id)
                    team = base10_id % 2
                elif assignment == "random":
                    team = random.randint(0, 1)
                is_leader = name in self.config["game"]["leaders"]
                newbie = User(name=name, team=team, loyalists=100, leader=is_leader)
                session.add(newbie)

                cap = Region.capital_for(newbie.team, session)
                if not cap:
                    logging.fatal("Could not find capital for %d" % newbie.team)
                newbie.region = cap

                session.commit()
                logging.info("Created combatant %s", newbie)

                reply = (
                    "Welcome to Chroma!  You are now a %s "
                    "in the %s army, commanding a force of loyalists "
                    "%d people strong. You are currently encamped at %s"
                ) % (newbie.rank, num_to_team(newbie.team, self.config), newbie.loyalists, cap.markdown())
                comment.reply(reply)
            else:
                # logging.info("Already registered %s", comment.author.name)
                pass
开发者ID:JBoggsy,项目名称:chromabot,代码行数:44,代码来源:main.py


注:本文中的db.User.region方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。