Example #1
0
def handle_add_whitelist(message):
    """Add a user to the whitelist.

    Expects a message with the format:

        /addwhitelist <name> <id>
    """
    if not nekowat.is_owner(message.chat.id):
        nekowat.reply_to(message, 'You do not have permission to do that')
        return

    args = telebot.util.extract_arguments(message.text).split(' ')

    if len(args) != 2:
        nekowat.reply_to(message, '/addwhitelist <name> <id>')
        return

    try:
        name = args[0]
        user_id = int(args[1])

    except:
        nekowat.reply_to(message, '/addwhitelist <name> <id>')
        return

    if nekowat.add_whitelist(name, user_id):
        nekowat.reply_to(message, 'User added to whitelist!')
        return

    nekowat.reply_to(message, 'Failed to add user to whitelist')
Example #2
0
def handle_add(message):
    """Add a new WAT to the bot.

    Expects a message with the format:

        /add <name>
    """
    chat_id = message.chat.id

    if not nekowat.is_owner(chat_id):
        nekowat.reply_to(message, 'You do not have permission to do that')
        return

    name = telebot.util.extract_arguments(message.text)

    if not name:
        nekowat.reply_to(message, '/add <name>')
        return

    if nekowat.wat_exists(name):
        nekowat.reply_to(message, 'There is already a WAT with that name')
        return

    msg = nekowat.send_message(chat_id, 'Please send the image for this WAT')

    nekowat.register_next_step_handler(msg,
                                       lambda m: process_add_image(m, name))
Example #3
0
def handle_set_expressions(message):
    """Sets expressions for a WAT.

    This shows all wats by name and then displays the expressions of the
    WAT that was chosen.
    """
    chat_id = message.chat.id

    if not nekowat.is_owner(chat_id):
        nekowat.reply_to(message, 'You do not have permission to do that')
        return

    markup = telebot.types.ReplyKeyboardMarkup(row_width=2)

    for w in nekowat.get_all_wats():
        markup.add(telebot.types.KeyboardButton(w['name']))

    # Add cancel
    markup.add(telebot.types.KeyboardButton('/cancel'))

    msg = nekowat.send_message(chat_id,
                               'Choose a WAT to modify',
                               reply_markup=markup)

    nekowat.register_next_step_handler(msg,
                                       lambda m: process_get_expressions(m))
Example #4
0
def handle_show_whitelist(message):
    """Show current whitelist."""
    if not nekowat.is_owner(message.chat.id):
        nekowat.reply_to(message, 'You do not have permission to do that')
        return

    msg = 'Whitelisted users:\n\n'
    for name, uid in nekowat.whitelist.items():
        msg += '- %s (%d)\n' % (name, uid)

    nekowat.reply_to(message, msg)
Example #5
0
def handle_toggle_whitelist(message):
    """Toggle use of whitelist."""
    if not nekowat.is_owner(message.chat.id):
        nekowat.reply_to(message, 'You do not have permission to do that')
        return

    nekowat.toggle_whitelist()

    if nekowat.use_whitelist:
        status = 'ON'

    else:
        status = 'OFF'

    nekowat.reply_to(message, 'Whitelist is %s' % status)
Example #6
0
def handle_rm_whitelist(message):
    """Remove a user from the whitelist.

    Expects a message with the format:

        /rm-whitelist <name>
    """
    if not nekowat.is_owner(message.chat.id):
        nekowat.reply_to(message, 'You do not have permission to do that')
        return

    name = telebot.util.extract_arguments(message.text)

    if nekowat.rm_whitelist(name):
        nekowat.reply_to(message, 'User removed from whitelist!')
        return

    nekowat.reply_to(message, 'Failed to remove user from whitelist')
Example #7
0
def handle_remove(message):
    """Handle removing a WAT.

    This shows all wats by name.
    """
    chat_id = message.chat.id

    if not nekowat.is_owner(chat_id):
        nekowat.reply_to(message, 'You do not have permission to do that')
        return

    markup = telebot.types.ReplyKeyboardMarkup(row_width=2)

    for w in nekowat.get_all_wats():
        markup.add(telebot.types.KeyboardButton(w['name']))

    # Add cancel
    markup.add(telebot.types.KeyboardButton('/cancel'))

    msg = nekowat.send_message(chat_id,
                               'Choose a WAT to delete',
                               reply_markup=markup)

    nekowat.register_next_step_handler(msg, lambda m: process_remove_wat(m))