Пример #1
0
def handle_check_user(session, bot, context):
    """Handle all actions from the check_user task."""
    task = session.query(Task).get(context.payload)
    # Ban the user
    if CallbackResult(context.action).name == 'ban':
        task.user.banned = True
        call_tg_func(context.query, 'answer', ['User banned'])
    elif CallbackResult(context.action).name == 'unban':
        task.user.banned = False
        call_tg_func(context.query, 'answer', ['User ban reverted'])
        message = f'Your ban has been lifted.'
        call_tg_func(bot, 'send_message', [task.user.id, message], {'reply_markup': get_main_keyboard(task.user)})

    # Revert user changes
    elif CallbackResult(context.action).name == 'revert':
        task.reverted = True
        revert_user_changes(session, task.user)
        call_tg_func(context.query, 'answer', ['All user changes reverted'])
    elif CallbackResult(context.action).name == 'undo_revert':
        task.reverted = False
        undo_user_changes_revert(session, task.user)
        call_tg_func(context.query, 'answer', ['User changes revert undone'])

    # Change the language of all changes of this task.
    elif CallbackResult(context.action).name == 'change_language':
        change_language_of_task_changes(session, task)
        call_tg_func(context.query, 'answer', ['Language changed'])

    elif CallbackResult(context.action).name == 'ok':
        if not task.reviewed:
            task.reviewed = True
            check_maintenance_chat(session, context.tg_chat, context.chat)

    keyboard = check_user_tags_keyboard(task)
    call_tg_func(context.query.message, 'edit_reply_markup', [], {'reply_markup': keyboard})
Пример #2
0
def handle_report_next(session, context):
    """Handle the nextbutton of voting tasks in maintenance channels."""
    task = session.query(Task).get(context.payload)

    if not task.reviewed:
        task.reviewed = True
        check_maintenance_chat(session, context.tg_chat, context.chat)

    try:
        keyboard = get_report_keyboard(task)
        call_tg_func(context.query.message, 'edit_reply_markup', [], {'reply_markup': keyboard})
    except: # noqa
        return
Пример #3
0
def start_tasks(bot, update, session, chat, user):
    """Start the handling of tasks."""
    if not chat.is_maintenance and not chat.is_newsfeed:
        update.message.chat.send_message(
            "The chat is neither a maintenance nor a newsfeed chat")
        return

    elif chat.current_task:
        return "There already is a task active for this chat."

    if chat.is_maintenance:
        check_maintenance_chat(session, update.message.chat, chat)

    if chat.is_newsfeed:
        check_newsfeed_chat(bot, session, chat)
Пример #4
0
def start_tasks(bot, update, session, chat, user):
    """Start the handling of tasks."""
    if not chat.is_maintenance and not chat.is_newsfeed:
        call_tg_func(update.message.chat, 'send_message',
                     ['The chat is neither a maintenance nor a newsfeed chat'],
                     {'reply_markup': get_main_keyboard(admin=True)})
        return

    elif chat.current_task:
        return 'There already is a task active for this chat.'

    if chat.is_maintenance:
        check_maintenance_chat(session, update.message.chat, chat)

    if chat.is_newsfeed:
        check_newsfeed_chat(bot, session, chat)
Пример #5
0
def handle_check_user(session, context):
    """Handle all actions from the check_user task."""
    task = session.query(Task).get(context.payload)
    # Ban the user
    if CallbackResult(context.action).name == "ban":
        task.user.banned = True
        call_tg_func(context.query, "answer", ["User banned"])
    elif CallbackResult(context.action).name == "unban":
        task.user.banned = False
        call_tg_func(context.query, "answer", ["User ban reverted"])
        message = f"Your ban has been lifted."
        context.bot.send_message(task.user.id,
                                 message,
                                 reply_markup=get_main_keyboard(task.user))

    # Revert user changes
    elif CallbackResult(context.action).name == "revert":
        task.reverted = True
        revert_user_changes(session, task.user)
        call_tg_func(context.query, "answer", ["All user changes reverted"])
    elif CallbackResult(context.action).name == "undo_revert":
        task.reverted = False
        undo_user_changes_revert(session, task.user)
        call_tg_func(context.query, "answer", ["User changes revert undone"])

    # Change the language of all changes of this task.
    elif CallbackResult(context.action).name == "change_language":
        change_language_of_task_changes(session, task)
        call_tg_func(context.query, "answer", ["Language changed"])

    elif CallbackResult(context.action).name == "ok":
        if not task.reviewed:
            task.reviewed = True
            check_maintenance_chat(session, context.tg_chat, context.chat)

    keyboard = check_user_tags_keyboard(task)
    call_tg_func(context.query.message, "edit_reply_markup", [],
                 {"reply_markup": keyboard})