Ejemplo n.º 1
0
def send(payload):
    '''
    function to take a payload, create a new mesaage, fill
    in the parameters and append it to the channels messages
    store as well as the gloabal message_store
    '''
    user = get_user_from('token', payload['token'])
    channel = get_channel(payload['channel_id'])
    if not test_in_channel(user['u_id'], channel):
        raise AccessError(description='User is not in channel')

    # create a message data type, and fill in details
    # then append to the channels list of messages
    txt = payload['message']
    if len(txt) > 1000:
        raise InputError(description='Message is more than 1000 characters')

    # create the message dictionary
    new_message = create_message()
    new_message['u_id'] = user['u_id']
    new_message['message'] = txt
    new_message['channel_id'] = payload['channel_id']

    channel['messages'].append(new_message)

    if txt == '/hangman':
        if not channel['hangman_active']:
            hangman.start(channel)
            channel['hangman_active'] = True
        else:
            hangman.message(channel, 'There is already an active game running')
            hangman.message(channel, hangman.display_hangman())

    if txt.split()[0] == '/guess':
        if not channel['hangman_active']:
            hangman.message(
                channel, 'There is not a current game of hangman running.\n' +
                r'If you would like to start one, type \hangman into the chat')
        else:
            if len(txt.split()) == 2:
                new_guess = txt.split()[1]
                if new_guess in r'!@#$%^&*()_+-=[]\;<>?/~`:':
                    hangman.message(channel, 'Invalid guess, guess again')
                else:
                    hangman.guess(channel, new_guess)
            else:
                hangman.message(channel, 'Invalid guess, guess again')

    # append it to the messages_store
    messages = get_messages_store()
    messages.append(new_message)
    save_messages_store()

    # append it to the channels file
    save_channel_store()

    return new_message
Ejemplo n.º 2
0
def oneGame():
    print "ONEGAME"
    startGame()
    index = 25
    while True:
        response = guess(LETTERS[index])
        if response["status"] == "DEAD" or response["status"] == "FREE":
            mine(response["lyrics"])
            return
        index = index - 1
Ejemplo n.º 3
0
def message_send(token, channel_id, message):
    """
    Adds a new message to the messages in a channel

    Parameters:
        token(string): An authorisation hash
        channel_id(int): The channel_id of the channel the message is being added too
        message(string): The message of the message being added

    Returns:
        message_id(int): An identifier for the new message
    """
    # Check that the token is valid
    user_input_id = validation.check_valid_token(token)

    # Check that the message is valid.
    validation.valid_message(message)

    # Check that the channel_id is valid
    validation.check_valid_channel_id(channel_id)

    # Check that user is in channel
    validation.check_user_in_channel(user_input_id, channel_id)

    new_message_id = data.make_message_id()
    new_message = {}
    new_message["message"] = message
    new_message["u_id"] = user_input_id
    new_message["time_created"] = datetime.datetime.now().replace().timestamp()
    new_message["message_id"] = new_message_id
    new_message["is_pinned"] = False
    new_message["reacts"] = [{
        "react_id": 1,
        "u_ids": []
    }, {
        "react_id": 2,
        "u_ids": []
    }, {
        "react_id": 3,
        "u_ids": []
    }, {
        "react_id": 4,
        "u_ids": []
    }]

    # Check if message is calling weather API
    if validation.check_weather_call(message):
        new_message['message'] = weather.get_weather(message)

    # Check if message will start a hangman session
    if validation.check_start_hangman(channel_id, message):
        return hangman.start(user_input_id, channel_id, new_message,
                             new_message_id)

    # Check if hangman is active and message is a guess
    if validation.check_if_hangman(channel_id, message):
        hangman.guess(user_input_id, channel_id, message)

    # Check if hangman should stop (/hangman stop)
    if validation.check_if_stop_message(message):
        return hangman.stop(user_input_id, channel_id)

    if message.startswith("/KAHIO/END"):
        new_message["message"] = kahio.kahio_end(user_input_id, channel_id)
    elif message.startswith("/KAHIO"):
        new_message["message"] = kahio.start_kahio(user_input_id, channel_id,
                                                   message)
    elif data.check_kahio_running(channel_id):
        return kahio.kahio_guess(user_input_id, channel_id, new_message)

    data.add_message(new_message, channel_id)

    return {
        "message_id": new_message_id,
    }
Ejemplo n.º 4
0
def test_guess_multiple():
    assert guess(list("____"), "abcb", "b") == list("_b_b")
Ejemplo n.º 5
0
def test_guess_single():
    assert guess(list("____"), "abcb", "a") == list("a___")
Ejemplo n.º 6
0
import hangman
#-------------------------------------------------------------------------------
# Name:        main
# Purpose:     Runs the hangman Game
#
# Author:      iestyn
#
# Created:     28/07/2019
# Copyright:   (c) iestyn 2019
# Licence:     MIT
#-------------------------------------------------------------------------------

#Main Loop
while (hangman.check()):
    hangman.printHint()
    hangman.hint = hangman.guess()
    if (hangman.guessLeft == 0):
        break

if (hangman.check() == False):
    print("Congratulations you guessed the correct word which is:" +
          hangman.word)
else:
    print("Unfortunately you couldn't guess the word which is:" + hangman.word)