Пример #1
0
def link(message):
    """Link a WhatsApp group

    Message has the following format:

        /link <group_id>

    Args:
        message: Received Telegram message.
    """
    if message.chat.type not in ['group', 'supergroup']:
        tgbot.reply_to(message, 'This operation can be done only in a group')
        return

    # Get name and message
    wa_group_id = telebot.util.extract_arguments(message.text)
    wa_group_name = wa_id_to_name(wa_group_id)

    if not wa_group_id:
        tgbot.reply_to(message, 'Syntax: /link <groupID>')
        return

    # Add to database
    db_add_contact(wa_group_name, wa_group_id)

    # Add to database
    db_set_group(wa_group_name, message.chat.id)

    tgbot.reply_to(
        message,
        'Bridge Connected. Please subscribe to @WhatAppStatus for the bridge server informations.'
    )
Пример #2
0
def link(message):
    """Link a WhatsApp group

    Message has the following format:

        /link <group_id>

    Args:
        message: Received Telegram message.
    """
    if message.chat.type not in ['group', 'supergroup']:
        tgbot.reply_to(message, 'This operation can be done only in a group')
        return

    # Get name and message
    wa_group_id = telebot.util.extract_arguments(message.text)
    wa_group_name = wa_id_to_name(wa_group_id)

    if not wa_group_id:
        tgbot.reply_to(message, 'Syntax: /link <groupID>')
        return

    # Add to database
    db_add_contact(wa_group_name, wa_group_id)

    # Add to database
    db_set_group(wa_group_name, message.chat.id)

    tgbot.reply_to(
        message,
        'Bridge Connected. Please subscribe to @WhatAppStatus for the bridge server informations. \r\n While this service is free, I still have to pay for the servers, so please consider becoming a supporter at https://buymeacoff.ee/SpEcHiDe \r\n This message won\'t appear again! Enjoy the \'free\' service!!'
    )
Пример #3
0
def bind(message):
    """Bind a contact to a group.

    Message has the following format:

        /bind <name> <group id>

    Args:
        message: Received Telegram message.
    """
    if message.chat.id != SETTINGS['owner']:
        tgbot.reply_to(message, 'You are not the owner of this bot')
        return

    # Get name and phone
    args = telebot.util.extract_arguments(message.text)
    name, group_id = args.split(maxsplit=1)

    if not name or not group_id:
        tgbot.reply_to(message, 'Syntax: /bind <name> <group id>')
        return

    group_id = safe_cast(group_id, int)
    if not group_id:
        tgbot.reply_to(message, 'Group id has to be a number')
        return

    # Ensure contact exists
    if not get_phone(name):
        tgbot.reply_to(message, 'No contact found with that name')
        return

    # Check if it already exists
    current = db_get_contact_by_group(group_id)
    if current:
        tgbot.reply_to(message, 'This group is already bound to ' + current)
        return

    # Add to database
    db_set_group(name, group_id)

    tgbot.reply_to(message, 'Bound to group')
Пример #4
0
def unbind(message):
    """Unbind a contact from his group.

    Message has the following format:

        /unbind <name>

    Args:
        message: Received Telegram message.
    """
    if message.chat.id != SETTINGS['owner']:
        tgbot.reply_to(message, 'You are not the owner of this bot')
        return

    # Get name and phone
    name = telebot.util.extract_arguments(message.text)

    if not name:
        tgbot.reply_to(message, 'Syntax: /unbind <name>')
        return

    # Ensure contact exists
    if not get_phone(name):
        tgbot.reply_to(message, 'No contact found with that name')
        return

    # Check if it already exists
    group = db_get_group(name)
    if not group:
        tgbot.reply_to(message, 'Contact was not bound to a group')
        return

    # Add to database
    db_set_group(name, None)

    tgbot.reply_to(message, 'Unbound from group')