Beispiel #1
0
def check_tag_access(server_id, tag_data, tag_name, user_id, need_owner=False):
    """Ensures that the given user is author of the tag (or a bot admin) if the tag is private, otherwise throw an exception."""
    if (tag_data['private'] or need_owner) and (tag_data['author_id'] != user_id and not servermanager.is_admin(server_id, user_id)):
        tag_author = usermanager.get_name(server_id, tag_data['author_id'])
        if need_owner:
            raise bot_exception(EXCEPT_TYPE, "User is not the author of tag '{tag_name}', created by {tag_author}".format(tag_name=tag_name, tag_author=tag_author))
        else:
            raise bot_exception(EXCEPT_TYPE, "The tag '{tag_name}' was made private by the author, {tag_author}".format(tag_name=tag_name, tag_author=tag_author))
def list_sound_tags(server_id, user_id=''):
    """Lists either all sound tags or sound tags made by a specific user."""
    initial_text = "Listing all sound tags:"
    if user_id:
        initial_text = "Listing sound tags created by {}:".format(usermanager.get_name(server_id, user_id))
    sound_tags = servermanager.servers_data[server_id]['sound_tags']
    found_list = []
    for sound_tag_name, sound_tag_data in sound_tags.items():
        if not user_id or user_id == sound_tag_data['author_id']:
            found_list.append(sound_tag_data['full_name'])
    return process_found_list(initial_text, found_list)
Beispiel #3
0
def list_sound_tags(server_id, user_id=''):
    """Lists either all sound tags or sound tags made by a specific user."""
    initial_text = "Listing all sound tags:"
    if user_id:
        initial_text = "Listing sound tags created by {}:".format(
            usermanager.get_name(server_id, user_id))
    sound_tags = servermanager.servers_data[server_id]['sound_tags']
    found_list = []
    for sound_tag_name, sound_tag_data in sound_tags.items():
        if not user_id or user_id == sound_tag_data['author_id']:
            found_list.append(sound_tag_data['full_name'])
    return process_found_list(initial_text, found_list)
Beispiel #4
0
def get_info(server_id, tag_name):
    """Builds a string listing known information of given tag."""
    tag_data = get_tag_data(server_id, tag_name)
    author_name = usermanager.get_name(server_id, tag_data['author_id'])
    to_return = """Tag information for {tag_data[full_name]}:
```
Author: {author_name}
Private: {tag_data[private]}
Hits: {tag_data[hits]}
Date created: {tag_data[date_created]}
```""".format(author_name=author_name, tag_data=tag_data)
    return to_return # Placeholder if this will be modified later
Beispiel #5
0
def get_info(server_id, tag_name):
    """Builds a string listing known information of given tag."""
    tag_data = get_tag_data(server_id, tag_name)
    author_name = usermanager.get_name(server_id, tag_data['author_id'])
    to_return = """Tag information for {tag_data[full_name]}:
```
Author: {author_name}
Private: {tag_data[private]}
Hits: {tag_data[hits]}
Date created: {tag_data[date_created]}
```""".format(author_name=author_name, tag_data=tag_data)
    return to_return  # Placeholder if this will be modified later
Beispiel #6
0
def get_random_number(minimum=1, maximum=100, is_private=True, **kwargs):
    """Obtains a random number with the specified minimum and maximum values. Same keyword arguments as flip_coin."""
    try: # Typecheck minimum and maximum values
        minimum = int(minimum)
        maximum = int(maximum)
    except:
        raise bot_exception(EXCEPT_TYPE, "Inputs are not valid integers")
    if (minimum == maximum):
        return "You must think you're really clever."
    if (minimum > maximum):
        minimum, maximum = maximum, minimum
    return "{identifier} got {result}.".format(
        identifier="You" if is_private else usermanager.get_name(kwargs['server_id'], kwargs['user_id']),
        result=random.randint(minimum, maximum))
Beispiel #7
0
def roll_die(faces=6, is_private=True, **kwargs):
    """Rolls a 6 sided die unless specified. Same keyword arguments as flip_coin."""
    try: # Typecheck faces value
        faces = int(faces)
    except:
        raise bot_exception(EXCEPT_TYPE, "Input is not a valid integer")
    to_return = "You" if is_private else usermanager.get_name(kwargs['server_id'], kwargs['user_id'])
    if (faces == 1):
        to_return += " rolled a {}. Just kidding.".format(random.randint(1,2147483647))
    elif (faces <= 0):
        return "Look, I can't roll something that breaks the laws of physics."
    else: # Valid roll
        to_return += " rolled a {}.".format(random.randint(1, faces))
    return to_return
def get_sound_info(server_id, sound_tag_name):
    """Builds a string listing known information of the given sound tag."""
    sound_tag_data = get_sound_tag_data(server_id, sound_tag_name)
    author_name = usermanager.get_name(server_id, sound_tag_data['author_id'])
    to_return = """Sound tag information for {sound_tag_data[full_name]}:
```
Author: {author_name}
Private: {sound_tag_data[private]}
Hits: {sound_tag_data[hits]}
Date created: {sound_tag_data[date_created]}
Sound URL: {sound_tag_data[url]}
Type: {sound_tag_data[type]}
Length: {sound_tag_data[length]} second(s)
```""".format(author_name=author_name, sound_tag_data=sound_tag_data)
    return to_return # Placeholder if this will be modified later
Beispiel #9
0
def get_sound_info(server_id, sound_tag_name):
    """Builds a string listing known information of the given sound tag."""
    sound_tag_data = get_sound_tag_data(server_id, sound_tag_name)
    author_name = usermanager.get_name(server_id, sound_tag_data['author_id'])
    to_return = """Sound tag information for {sound_tag_data[full_name]}:
```
Author: {author_name}
Private: {sound_tag_data[private]}
Hits: {sound_tag_data[hits]}
Date created: {sound_tag_data[date_created]}
Sound URL: {sound_tag_data[url]}
Type: {sound_tag_data[type]}
Length: {sound_tag_data[length]} second(s)
```""".format(author_name=author_name, sound_tag_data=sound_tag_data)
    return to_return  # Placeholder if this will be modified later
Beispiel #10
0
def get_random_number(minimum=1, maximum=100, is_private=True, **kwargs):
    """Obtains a random number with the specified minimum and maximum values. Same keyword arguments as flip_coin."""
    try:  # Typecheck minimum and maximum values
        minimum = int(minimum)
        maximum = int(maximum)
    except:
        raise bot_exception(EXCEPT_TYPE, "Inputs are not valid integers")
    if (minimum == maximum):
        return "You must think you're really clever."
    if (minimum > maximum):
        minimum, maximum = maximum, minimum
    return "{identifier} got {result}.".format(
        identifier="You" if is_private else usermanager.get_name(
            kwargs['server_id'], kwargs['user_id']),
        result=random.randint(minimum, maximum))
Beispiel #11
0
def flip_coin(is_private=True, **kwargs):
    """Flips a coin and returns a text result.
    
    Keyword arguments:
    is_private -- determines whether a name should be obtained
    server_id -- ID of the server requesting the flip
    user_id -- ID of the user requesting the flip
    """
    to_return = "You" if is_private else usermanager.get_name(kwargs['server_id'], kwargs['user_id'])
    to_return += " flipped a coin: It's "
    if (random.randint(0,1) == 0):
        to_return += "heads! Ⓗ "
    else:
        to_return += "tails! Ⓣ"
    return to_return
Beispiel #12
0
def roll_die(faces=6, is_private=True, **kwargs):
    """Rolls a 6 sided die unless specified. Same keyword arguments as flip_coin."""
    try:  # Typecheck faces value
        faces = int(faces)
    except:
        raise bot_exception(EXCEPT_TYPE, "Input is not a valid integer")
    to_return = "You" if is_private else usermanager.get_name(
        kwargs['server_id'], kwargs['user_id'])
    if (faces == 1):
        to_return += " rolled a {}. Just kidding.".format(
            random.randint(1, 2147483647))
    elif (faces <= 0):
        return "Look, I can't roll something that breaks the laws of physics."
    else:  # Valid roll
        to_return += " rolled a {}.".format(random.randint(1, faces))
    return to_return
Beispiel #13
0
def flip_coin(is_private=True, **kwargs):
    """Flips a coin and returns a text result.
    
    Keyword arguments:
    is_private -- determines whether a name should be obtained
    server_id -- ID of the server requesting the flip
    user_id -- ID of the user requesting the flip
    """
    to_return = "You" if is_private else usermanager.get_name(
        kwargs['server_id'], kwargs['user_id'])
    to_return += " flipped a coin: It's "
    if (random.randint(0, 1) == 0):
        to_return += "heads! Ⓗ "
    else:
        to_return += "tails! Ⓣ"
    return to_return
Beispiel #14
0
def check_tag_access(server_id, tag_data, tag_name, user_id, need_owner=False):
    """Ensures that the given user is author of the tag (or a bot admin) if the tag is private, otherwise throw an exception."""
    if (tag_data['private'] or need_owner) and (
            tag_data['author_id'] != user_id
            and not servermanager.is_admin(server_id, user_id)):
        tag_author = usermanager.get_name(server_id, tag_data['author_id'])
        if need_owner:
            raise bot_exception(
                EXCEPT_TYPE,
                "User is not the author of tag '{tag_name}', created by {tag_author}"
                .format(tag_name=tag_name, tag_author=tag_author))
        else:
            raise bot_exception(
                EXCEPT_TYPE,
                "The tag '{tag_name}' was made private by the author, {tag_author}"
                .format(tag_name=tag_name, tag_author=tag_author))