from datetime import datetime from collections import defaultdict import random import locale import baas32 locale.setlocale(locale.LC_TIME, 'nl_NL') STATUS_EMOJI = { 'Niet begonnen': '⏸', 'Begonnen': '▶️', 'Done': '✅', 'Niet Done': '❌' } def stranger_message(name): return f''' Heya, {name}! Cool dat je even komt kijken! Voor nu is deze bot nog even afgesloten voor het publiek, maar kom later vooral een keertje terug. Joe!''' def me_message(user_id): return f''' Dit weet ik over je: svia.nl user_id: {user_id} ''' def tasks_message(tasks, is_group=False, user_name=None): groups = defaultdict(list) for task in tasks: groups[task['group']['id']].append(task) if not user_name: user_name = 'Je' else: user_name += '\'s' if is_group: msg = f'{user_name} taken voor deze groep:\n\n' else: msg = f'{user_name} taken:\n\n' for _, group_tasks in groups.items(): if not group_tasks: continue group_name = group_tasks[0]['group']['name'] if not is_group else None msg += taskset_message(group_name, group_tasks) random_task = baas32.encode(random.choice(tasks)['id']) msg += f'Gebruik /task <task_id> voor meer informatie. ' \ f'Bijvoorbeeld: /task {random_task}' return msg def taskset_message(name, tasks): msg = f'{name}:\n' if name else '' for task in tasks: task_code = baas32.encode(task['id']) emoji = STATUS_EMOJI[task['status']] if len(task['users']) == 2: emoji += ' 👨‍👦' elif len(task['users']) == 3: emoji += ' 👨‍👧‍👦' elif len(task['users']) > 3: emoji += ' 👨‍👩‍👧‍👧' msg += f'• [{task_code}] ' \ f'{emoji} {task["title"].strip()}' msg += '\n' msg += '\n' return msg def task_message(task, is_group): task_code = baas32.encode(task['id']) msg = f'[{task_code}] {task["title"]}\n' timestamp = datetime.strptime(task["timestamp"], "%Y-%m-%dT%H:%M:%S") msg += f'{timestamp.strftime("%d %B %Y, %H:%M")}\n\n' # Print the task group msg += f'Groep: {task["group"]["name"]}\n' # Print the task state msg += f'Status: {task["status"]}\n' # Print task owner(s) users = task['users'] if not users: msg += f'Geen eigenaren\n' elif len(users) == 1: msg += f'Eigenaar: {users[0]["name"]}\n' elif 1 < len(users) <= 2: msg += f'Eigenaren: ' \ f'{users[0]["name"]} en {users[1]["name"]}\n' else: msg += '\nEigenaren:\n' for user in task['users']: msg += f'• {user["name"]}\n' msg += '\n' # Print the description, if available try: msg += f'Beschrijving:\n{task["content"]}\n\n' except KeyError: pass # Print the minute URL, if available try: minute = task['minute'] minute_url = f'http://svia.nl/pimpy/minutes/single/{minute["id"]}/' minute_url += str(minute['line']) if 'line' in minute else '' msg += f'Bijbehorende notulen\n' except KeyError: msg += f'Geen bijbehorende notulen\n' keyboard = [] if task['status'] != 'Niet begonnen': keyboard.append({ 'text': '⏸ Niet begonnen', 'callback_data': f'status unstarted {task["id"]}' }) if task['status'] != 'Begonnen': keyboard.append({ 'text': '▶️ Begonnen', 'callback_data': f'status started {task["id"]}' }) if task['status'] != 'Done': keyboard.append({ 'text': '✅ Done', 'callback_data': f'status done {task["id"]}' }) if task['status'] != 'Niet Done': keyboard.append({ 'text': '❌ Niet Done', 'callback_data': f'status notdone {task["id"]}' }) reply_markup = {'inline_keyboard': [keyboard]} return msg, reply_markup