Ejemplo n.º 1
0
def set_init_balance(message):
    ph_number = message.who.split("@")[0]
    params = message.predicate.split(" ")
    init_point = params[0]
    group_name = " ".join(params[1:])
    # is_in_group = helper.conversationIsGroup(message)
    # if not is_in_group:
    #     mac.send_message("Hello, I can't set your from here, please do it from your group.", message.conversation)
    #     return
    if len(params) < 2:
        mac.send_message(
            "Please specify the default balance and the rtp ammount for your players",
            message.conversation)
        mac.send_message("You can ask for my #help if you are not sure",
                         message.conversation)
        return
    if len(params) > 10:
        mac.send_message(
            "Please check your command again, it seems it contain too much arguments",
            message.conversation)
        mac.send_message(
            "You can ask for my #help if you are not sure how to setup",
            message.conversation)
        return
    is_number_only = helper.isAllNumber(init_point)
    if not is_number_only:
        mac.send_message(
            "Hey, I can't really understand your command. Please only use number for init_point",
            message.conversation)
        return

    mac.send_message("Setting the group..", message.conversation)
    group_id = message.conversation.split("@")[0]
    payload = {
        'wa_ph_number': ph_number,
        'init_point': init_point,
        'wa_group_name': group_name
    }
    set_group_post = requests.post(
        'http://{}/api/whatsappbot/init_balance'.format(BASE_IP), data=payload)
    set_group_data = set_group_post.json()
    if not set_group_data or not set_group_data['message']:
        mac.send_message("I Failed to setup the group, no message field",
                         message.conversation)
        return
    if not helper.isResponseSuccess(set_group_post.status_code):
        mac.send_message(
            'I failed to setup the group, here is the message \n {}'.format(
                set_group_data['message']), message.conversation)
        return
    #mac.send_message(GROUP_FINISH_SETTING, message.conversation)
    mac.send_message(
        'We already set the initial balance of member is {} credit.'.format(
            init_point), message.who)
    mac.send_message(STAKE_MESSAGE, message.who)
Ejemplo n.º 2
0
def create_stake(message):
    params = message.predicate.split(" ")

    if message.conversation == message.who:
        mac.send_message(
            "You can't place a stake from here, please place a stake from the group",
            message.who)
        return
    if len(params) < 2:
        mac.send_message(
            "Too few arguments ! you should specify animal type and the value",
            message.conversation)
        return
    if len(params) > 2:
        mac.send_message(
            "I can't understand your stake, seems it contain too much arguments !",
            message.conversation)
        return
    user_phone = message.who.split("@")[0]
    group_id = message.conversation.split("@")[0]
    stake = params[0]
    value = params[1]

    if not helper.isAllNumber(value):
        mac.send_message(
            'Sorry I cannot understand the currency yet please just use plain number for value',
            message.conversation)
        return

    payload = {
        'wa_group_id': group_id,
        'wa_ph_number': user_phone,
        'stake': stake,
        'value': value
    }
    stake_post = requests.post(
        'http://{}/trivia/api/whatsappbot/stakes'.format(BASE_IP),
        data=payload)
    stake_post_data = stake_post.json()
    is_successful = helper.isResponseSuccess(stake_post.status_code)
    if not stake_post_data or not stake_post_data['message']:
        mac.send_message('ERROR connecting to server', message.conversation)
        return
    if not is_successful:
        mac.send_message(stake_post_data['message'], message.who)
        return
    mac.send_message("💰 {} place a stake!".format(message.who_name),
                     message.conversation)
    mac.send_message(
        "{} your stake is {}".format(stake_post_data['message'],
                                     message.predicate), message.who)
Ejemplo n.º 3
0
def set_group(message):
    params = message.predicate.split(" ")
    is_in_group = helper.conversationIsGroup(message)
    if not is_in_group:
        mac.send_message(
            "Hello, I can't set your from here, please do it from your group.",
            message.conversation)
        return
    if len(params) < 2:
        mac.send_message(
            "Please specify the default balance and the rtp ammount for your players",
            message.conversation)
        mac.send_message("You can ask for my #help if you are not sure",
                         message.conversation)
        return
    if len(params) > 2:
        mac.send_message(
            "Please check your command again, it seems it contain too much arguments",
            message.conversation)
        mac.send_message(
            "You can ask for my #help if you are not sure how to setup",
            message.conversation)
        return
    for param in params:
        is_number_only = helper.isAllNumber(param)
        if not is_number_only:
            mac.send_message(
                "Hey, I can't really understand your command. Please only use number for balance and rtp",
                message.conversation)
            return

    mac.send_message("Setting the group..", message.conversation)
    group_id = message.conversation.split("@")[0]
    (balance, rtp) = params
    payload = {'wa_group_id': group_id, 'init_point': balance, 'rtp': rtp}
    set_group_post = requests.post(
        'http://{}/trivia/api/whatsappbot/update_point'.format(BASE_IP),
        data=payload)
    set_group_data = set_group_post.json()
    if not set_group_data or not set_group_data['message']:
        mac.send_message("I Failed to setup the group, no message field",
                         message.conversation)
        return
    if not helper.isResponseSuccess(set_group_post.status_code):
        mac.send_message(
            'I failed to setup the group, here is the message \n {}'.format(
                set_group_data['message']), message.conversation)
        return
    mac.send_message(GROUP_FINISH_SETTING, message.conversation)
Ejemplo n.º 4
0
def set_game(message):
    ph_number = message.who.split("@")[0]
    params = message.predicate.split(" ")
    rtp = params[0]
    hours = params[1]
    group_name = " ".join(params[2:])

    if len(params) > 10:
        mac.send_message("I Failed to setup the game", message.who)

    if not helper.isAllNumber(rtp):
        mac.send_message(
            'Sorry there is something wrong in your stake command!',
            message.who)
        return

    if int(rtp) > 101:
        mac.send_message(
            'Sorry there is something wrong in your stake command! \n Please set rtp between 1 and 100',
            message.who)
        return

    group_id = message.conversation.split("@")[0]
    payload = {
        'rtp': rtp,
        'hours': hours,
        'wa_ph_number': ph_number,
        'wa_group_name': group_name
    }
    start_game_post = requests.post(
        "http://{}/api/whatsappbot/game".format(BASE_IP), data=payload)
    start_game_data = start_game_post.json()
    if not start_game_data or not start_game_data['message']:
        mac.send_message(
            "I failed to start the game session, no message field",
            message.conversation)
        return
    if not helper.isResponseSuccess(start_game_post.status_code):
        mac.send_message(
            'I failed to start the game, here some error \n {}'.format(
                start_game_data['message']), message.conversation)
        return
    #print(start_game_data['message'])
    mac.send_message(start_game_data['message'], message.who)
Ejemplo n.º 5
0
def create_stake(message):
    params = message.predicate.split(" ")

    def is_admin(result):
        if result:
            mac.send_message(
                "Sorry, you can not place a stake in your own group",
                message.who)
        return

    check_group(message, callback=is_admin)

    if message.conversation == message.who:
        mac.send_message(
            "You can't place a stake from here, please place a stake from the group",
            message.who)
        return

    if len(params) == 1:
        mac.send_message(HELP_MESSAGE, message.who)
        return

    if len(params) < 2:
        mac.send_message(
            "Too few arguments ! you should specify animal type and the value",
            message.who)
        return

    if len(params) > 2:
        mac.send_message(
            "I can't understand your stake, seems it contain too much arguments !",
            message.who)
        return

    (stake, value) = params

    user_phone = message.who.split("@")[0]
    user_phone_star = user_phone[:5] + "****"
    group_id = message.conversation.split("@")[0]

    if not helper.isAllNumber(value):
        mac.send_message(
            'Sorry there is something wrong in your stake command! \n Please use #stake [animal name] [amount]',
            message.who)
        return

    if int(value) < 1:
        mac.send_message(
            'Sorry there is something wrong in your stake command! \n Please use #stake [animal name] [amount]',
            message.who)
        return

    if not stake in ALLANIMALS:
        mac.send_message(
            'Sorry there is something wrong in your stake command! \n Please use #stake [animal name] [amount]',
            message.who)
        return

    payload = {
        'wa_group_id': group_id,
        'wa_ph_number': user_phone,
        'stake': stake,
        'value': value
    }
    stake_post = requests.post(
        'http://{}/api/whatsappbot/stakes'.format(BASE_IP), data=payload)
    stake_post_data = stake_post.json()
    is_successful = helper.isResponseSuccess(stake_post.status_code)
    if not stake_post_data or not stake_post_data['message']:
        mac.send_message('ERROR connecting to server', message.conversation)
        return
    if not is_successful:
        mac.send_message(stake_post_data['message'], message.who)
        return
    mac.send_message("💰 {} place a stake!".format(user_phone_star),
                     message.conversation)
    mac.send_message("{}".format(stake_post_data['message']), message.who)