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
def handle_report_ban(session, context): """Handle the ban button of voting tasks in maintenance channels.""" task = session.query(Task).get(context.payload) if CallbackResult(context.action).name == 'ban': task.sticker_set.banned = True call_tg_func(context.query, 'answer', ['Set tagged as nsfw']) else: task.sticker_set.banned = False call_tg_func(context.query, 'answer', ['Set no longer tagged as nsfw']) session.commit() keyboard = get_report_keyboard(task) call_tg_func(context.query.message, 'edit_reply_markup', [], {'reply_markup': keyboard})
def handle_report_ban(session, context): """Handle the ban button of voting tasks in maintenance channels.""" task = session.query(Task).get(context.payload) if CallbackResult(context.action).name == "ban": task.sticker_set.banned = True context.query.answer("Set tagged as nsfw") else: task.sticker_set.banned = False context.query.answer("Set no longer tagged as nsfw") session.commit() keyboard = get_report_keyboard(task) context.query.message.edit_reply_markup(reply_markup=keyboard)
def handle_report_furry(session, context): """Handle the furry button of voting tasks in maintenance channels.""" task = session.query(Task).get(context.payload) if CallbackResult(context.action).name == "ban": task.sticker_set.furry = True call_tg_func(context.query, "answer", ["Set tagged as furry"]) else: task.sticker_set.furry = False call_tg_func(context.query, "answer", ["Set tagged as furry"]) session.commit() keyboard = get_report_keyboard(task) call_tg_func(context.query.message, "edit_reply_markup", [], {"reply_markup": keyboard})
def check_maintenance_chat(session, tg_chat, chat, job=False): """Get the next task and send it to the maintenance channel.""" task = session.query(Task) \ .filter(Task.reviewed.is_(False)) \ .filter(Task.type.in_([ Task.CHECK_USER_TAGS, Task.REPORT, ])) \ .order_by(Task.created_at.asc()) \ .limit(1) \ .one_or_none() if task is None: chat.current_task = None # Don't send messages if we are calling this from a job. if job: return tg_chat.send_message('There are no more tasks for processing.') return chat.current_task = task if task.type == Task.CHECK_USER_TAGS: changes = task.changes_to_check # Compile task text text = [ f'User {task.user.username} ({task.user.id}) tagged {len(changes)} sticker' ] text.append(f'Detected at {task.created_at}: \n') for change in changes: if len(change.added_tags) > 0: text.append(f'Added: {change.added_tags_as_text()}') if len(change.removed_tags) > 0: text.append(f'Removed: {change.removed_tags_as_text()}') keyboard = check_user_tags_keyboard(task) elif task.type == Task.REPORT: # Compile task text text = ['Ban sticker set? \n'] for ban in task.sticker_set.reports: text.append(ban.reason) keyboard = get_report_keyboard(task) # Send first sticker of the set call_tg_func(tg_chat, 'send_sticker', args=[task.sticker_set.stickers[0].file_id]) text_chunks = split_text(text) while len(text_chunks) > 0: chunk = text_chunks.pop(0) # First chunks, just send the text if len(text_chunks) > 0: call_tg_func(tg_chat, 'send_message', args=[chunk]) # Last chunk. Send the text and the inline keyboard else: call_tg_func(tg_chat, 'send_message', args=[chunk], kwargs={'reply_markup': keyboard}) return True