Example #1
0
def activate_names_requested_in(link):
    tree = get_comment_tree(link)
    acceptable_names = []
    if tree.tree:
        top_level_cids = tree.tree[None]
        comments = chain.from_iterable(Comment._byID(chunk, return_dict=False,
                                                     data=True)
                                       for chunk in in_chunks(top_level_cids))

        for comment in sorted(comments, key=lambda c: c._ups, reverse=True):
            if comment._spam or comment._deleted:
                continue

            sanitized = comment.body.strip()
            match = valid_name_re.search(sanitized)
            if match:
                acceptable_names.append((comment, match.group(1)))

    # we activate one name for each 100% of rev goal met
    names = acceptable_names[:link.revenue_bucket]
    activate_names(link, names)

    activated_names = [name for comment, name in names]
    link.server_names = activated_names
    link.flair_text = ", ".join(activated_names) if names else "/dev/null"
    link.flair_css_class = "goal-bucket-%d" % link.revenue_bucket
    link._commit()
Example #2
0
    def on_use(self, user, target):
        link = Link._byID(target.link_id)
        comment_tree = get_comment_tree(link)
        child_ids = comment_tree.tree[target._id]
        grandchild_ids = []
        for child_id in child_ids:
            grandchild_ids.extend(comment_tree.tree[child_id])

        comments = Comment._byID(child_ids + grandchild_ids, data=True,
                                 return_dict=True)
        children = [comments[cid] for cid in child_ids]
        grandchildren = [comments[cid] for cid in grandchild_ids]

        for comment in itertools.chain([target], children, grandchildren):
            effects.add_effect(user, comment, self.item_name)

        self.apply_damage_and_log(user, [target], self.direct_damage)
        self.apply_damage_and_log(user, children, self.child_damage)
        self.apply_damage_and_log(user, grandchildren, self.grandchild_damage)
Example #3
0
    def on_use(self, user, target):
        link = Link._byID(target.link_id)
        comment_tree = get_comment_tree(link)
        child_ids = comment_tree.tree[target._id]
        grandchild_ids = []
        for child_id in child_ids:
            grandchild_ids.extend(comment_tree.tree[child_id])

        comments = Comment._byID(child_ids + grandchild_ids,
                                 data=True,
                                 return_dict=True)
        children = [comments[cid] for cid in child_ids]
        grandchildren = [comments[cid] for cid in grandchild_ids]

        for comment in itertools.chain([target], children, grandchildren):
            effects.add_effect(user, comment, self.item_name)

        self.apply_damage_and_log(user, [target], self.direct_damage)
        self.apply_damage_and_log(user, children, self.child_damage)
        self.apply_damage_and_log(user, grandchildren, self.grandchild_damage)