Exemple #1
0
    def add_props(cls, user, wrapped):
        user_fullnames = {w.user_fullname for w in wrapped}
        target_fullnames = {w.target_fullname for w in wrapped}

        users = Account._by_fullname(user_fullnames,
                                     data=True,
                                     return_dict=True)
        targets = Thing._by_fullname(target_fullnames,
                                     data=True,
                                     return_dict=True)

        author_ids = {
            t.author_id
            for t in targets.itervalues() if hasattr(t, 'author_id')
        }
        link_ids = {
            t.link_id
            for t in targets.itervalues() if hasattr(t, 'link_id')
        }
        sr_ids = {t.sr_id for t in targets.itervalues() if hasattr(t, 'sr_id')}

        authors = Account._byID(author_ids, data=True, return_dict=True)
        links = Link._byID(link_ids, data=True, return_dict=True)
        subreddits = Subreddit._byID(sr_ids, data=True, return_dict=True)

        target_things = {}
        for fullname, target in targets.iteritems():
            if isinstance(target, (Comment, Link)):
                author = authors[target.author_id]
                if isinstance(target, Link):
                    subreddit = subreddits[target.sr_id]
                    path = target.make_permalink(subreddit)
                else:
                    link = links[target.link_id]
                    subreddit = subreddits[link.sr_id]
                    path = target.make_permalink(link, subreddit)
                target_things[fullname] = GameLogTarget(
                    target, path, author, subreddit)
            elif isinstance(target, Account):
                target_things[fullname] = WrappedUser(target)

        for w in wrapped:
            w.is_self = (c.user_is_loggedin
                         and w.user_fullname == c.user._fullname)
            w.user = WrappedUser(users[w.user_fullname])
            w.target = target_things[w.target_fullname]
            w.item = g.f2pitems[w.item]
            w.user_team = scores.get_user_team(users[w.user_fullname])
            if isinstance(w.target, WrappedUser):
                target_user = targets[w.target.fullname]
            else:
                target_user = authors[targets[w.target_fullname].author_id]
            w.target_team = scores.get_user_team(target_user)
Exemple #2
0
    def _claim_hat(msg):
        data = json.loads(msg.body)

        account = Account._byID(int(data["user-id"]), data=True)
        if account.f2p != "claiming":
            g.log.warning("%r attempted to claim twice!", account)
            return

        user_team = scores.get_user_team(account)
        promo_id = g.steam_promo_items[user_team]

        g.stats.event_count("f2p.claim_hat", "item_%s" % promo_id)

        response = session.post(GRANT_URL,
                                data={
                                    "SteamID": data["steam-id"],
                                    "PromoID": promo_id,
                                    "key": g.steam_api_key,
                                    "format": "json",
                                })

        # band-aid for requests API change in v1.0.0
        if callable(response.json):
            response_data = response.json()
        else:
            response_data = response.json

        if response_data["result"]["status"] != 1:
            g.log.warning("Steam Promo for %r -> %r failed: %s", account,
                          data["steam-id"], response_data["statusDetail"])
            raise Exception

        account.f2p = "claimed"
        account._commit()
Exemple #3
0
    def _claim_hat(msg):
        data = json.loads(msg.body)

        account = Account._byID(int(data["user-id"]), data=True)
        if account.f2p != "claiming":
            g.log.warning("%r attempted to claim twice!", account)
            return

        user_team = scores.get_user_team(account)
        promo_id = g.steam_promo_items[user_team]

        g.stats.event_count("f2p.claim_hat", "item_%s" % promo_id)

        response = session.post(GRANT_URL, data={
            "SteamID": data["steam-id"],
            "PromoID": promo_id,
            "key": g.steam_api_key,
            "format": "json",
        })

        # band-aid for requests API change in v1.0.0
        if callable(response.json):
            response_data = response.json()
        else:
            response_data = response.json

        if response_data["result"]["status"] != 1:
            g.log.warning("Steam Promo for %r -> %r failed: %r",
                          account, data["steam-id"],
                          response_data)
            raise Exception

        account.f2p = "claimed"
        account._commit()
    def add_props(cls, user, wrapped):
        user_fullnames = {w.user_fullname for w in wrapped}
        target_fullnames = {w.target_fullname for w in wrapped}

        users = Account._by_fullname(user_fullnames, data=True,
                                     return_dict=True)
        targets = Thing._by_fullname(target_fullnames, data=True,
                                     return_dict=True)

        author_ids = {t.author_id for t in targets.itervalues()
                      if hasattr(t, 'author_id')}
        link_ids = {t.link_id for t in targets.itervalues()
                    if hasattr(t, 'link_id')}
        sr_ids = {t.sr_id for t in targets.itervalues() if hasattr(t, 'sr_id')}

        authors = Account._byID(author_ids, data=True, return_dict=True)
        links = Link._byID(link_ids, data=True, return_dict=True)
        subreddits = Subreddit._byID(sr_ids, data=True, return_dict=True)

        target_things = {}
        for fullname, target in targets.iteritems():
            if isinstance(target, (Comment, Link)):
                author = authors[target.author_id]
                if isinstance(target, Link):
                    subreddit = subreddits[target.sr_id]
                    path = target.make_permalink(subreddit)
                else:
                    link = links[target.link_id]
                    subreddit = subreddits[link.sr_id]
                    path = target.make_permalink(link, subreddit)
                target_things[fullname] = GameLogTarget(target, path, author,
                                                        subreddit)
            elif isinstance(target, Account):
                target_things[fullname] = WrappedUser(target)

        for w in wrapped:
            w.is_self = (c.user_is_loggedin and
                         w.user_fullname == c.user._fullname)
            w.user = WrappedUser(users[w.user_fullname])
            w.target = target_things[w.target_fullname]
            w.item = g.f2pitems[w.item]
            w.user_team = scores.get_user_team(users[w.user_fullname])
            if isinstance(w.target, WrappedUser):
                target_user = targets[w.target.fullname]
            else:
                target_user = authors[targets[w.target_fullname].author_id]
            w.target_team = scores.get_user_team(target_user)
Exemple #5
0
def is_effect_visible(effector, effect_item):
    visibility = effect_item.get("visibility", "all")

    if visibility == "team":
        if c.user_is_loggedin:
            self_team = scores.get_user_team(c.user)
            effector_team = scores.get_userid_team(effector)
            return self_team == effector_team
        else:
            return False
    elif visibility == "self":
        return c.user_is_loggedin and effector == c.user._id
    else:
        return True
def give_trophies(users):
    for fullnames in in_chunks(progress(users, verbosity=50), size=50):
        users = Account._by_fullname(fullnames, return_dict=False)

        for user in users:
            team = get_user_team(user)

            trophy = Award.give_if_needed(
                codename="f2p_orangered" if team == "red" else "f2p_periwinkle",
                user=user,
            )
            if trophy:
                trophy._commit()

        sleep(.5)
Exemple #7
0
 def is_contributor_with_teams(sr, user):
     sr_team = g.team_subreddits.get(sr.name.lower())
     if sr_team:
         return sr_team == scores.get_user_team(user)
     return orig_is_contributor(sr, user)
Exemple #8
0
 def is_contributor_with_teams(sr, user):
     sr_team = g.team_subreddits.get(sr.name.lower())
     if sr_team:
         return sr_team == scores.get_user_team(user)
     return orig_is_contributor(sr, user)