コード例 #1
0
ファイル: core.py プロジェクト: phoneman13/hivemind
def create_post_as(comment: dict) -> str:
    """ Given a new Steem post/comment, add it to appropriate community.
    
    For a comment to be valid, these conditions apply:
        - Post must be new (edits don't count)
        - Author is allowed to post in this community (membership & privacy)
        - Author is not muted in this community
        
    
    Args:
        comment (dict): Operation with the post to add.
        
    Returns:
        name (str): If all conditions apply, community name we're posting into.
                    Otherwise, authors own name (blog) is returned.
    """

    if comment['json_metadata'] == "":
        return None

    md = None
    try:
        md = json.loads(comment['json_metadata'])
    except:
        return None

    if md is not dict or 'community' not in md:
        return None

    author = comment['author']
    community = md['community']
    community_props = get_community(community)

    if not community_props:
        return None

    if is_author_muted(author, community):
        return None

    privacy = privacy_map[community_props['privacy']]
    if privacy == 'open':
        pass
    elif privacy == 'restricted':
        # guests cannot create top-level posts in restricted communities
        if comment['parent_author'] == "" and get_user_role(
                author, community) == 'guest':
            return None
    elif privacy == 'closed':
        # we need at least member permissions to post or comment
        if get_user_role(author, community) == 'guest':
            return None

    return community
コード例 #2
0
ファイル: community.py プロジェクト: random-labs/hivemind
def is_community_post_valid(community, comment: dict) -> str:
    """ Given a new Steem post/comment, check if valid as per community rules
    
    For a comment to be valid, these conditions apply:
        - Post must be new (edits don't count)
        - Author is allowed to post in this community (membership & privacy)
        - Author is not muted in this community
        
    
    Args:
        community (str): Community intended for this post op
        comment (dict): Raw post operation
        
    Returns:
        is_valid (bool): If all checks pass, true
    """

    if not community:
        raise Exception("no community specified")

    author = comment['author']
    if author == community:
        return True

    community_props = get_community(community)
    if not community_props:
        # if this is not a defined community, it's free to post in.
        return True

    if is_author_muted(author, community):
        return False

    privacy = privacy_map[community_props['privacy']]
    if privacy == 'open':
        pass
    elif privacy == 'restricted':
        # guests cannot create top-level posts in restricted communities
        if comment['parent_author'] == "" and get_user_role(
                author, community) == 'guest':
            return False
    elif privacy == 'closed':
        # we need at least member permissions to post or comment
        if get_user_role(author, community) == 'guest':
            return False

    return True
コード例 #3
0
ファイル: community.py プロジェクト: random-labs/hivemind
def is_author_muted(author_name: str, community_name: str) -> bool:
    return get_user_role(author_name, community_name) is 'muted'