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'<strong>{user_name} taken voor deze groep:</strong>\n\n' else: msg = f'<strong>{user_name} taken:</strong>\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
async def cmd_actie(message): token = Database.user_tokens.get(str(message.from_user.id)) if not token: msg = messages.stranger_message(message.from_user.first_name) await message.chat.message(msg) return if message.chat.type == 'private': await message.chat.message( 'Deze functie werkt alleen in commissiechats.') return group_id = Database.group_ids.get(str(message.chat.id)) if not group_id: await message.chat.message( 'pimpy is nog niet ingeschakeld voor deze groep :/') return match = re.match(r'^([^:]+): (.*)$', message.args) if not match: match = re.match(r'^([^ ]+) (.*)$', message.args) if match: owner = match.group(1) title = match.group(2) await message.chat.message( f'Incorrecte syntax. Misschien bedoelde je /actie {owner}: {title}?' ) else: await message.chat.message( f'Incorrecte syntax. Probeer eens /actie [naam]: [titel].') return task = await api.add_group_task(token, group_id, match.group(1), match.group(2)) msg, reply_markup = messages.task_message(task, True) task_code = baas32.encode(task['id']) msg = f'Taak <code>[{task_code}]</code> aangemaakt!\n\n' + msg await message.chat.message(msg, parse_mode='HTML', reply_markup=json.dumps(reply_markup), disable_web_page_preview=True)
def taskset_message(name, tasks): msg = f'<strong>{name}:</strong>\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'• <code>[{task_code}]</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'<code>[{task_code}]</code> <strong>{task["title"]}</strong>\n' timestamp = datetime.strptime(task["timestamp"], "%Y-%m-%dT%H:%M:%S") msg += f'<em>{timestamp.strftime("%d %B %Y, %H:%M")}</em>\n\n' # Print the task group msg += f'<strong>Groep:</strong> {task["group"]["name"]}\n' # Print the task state msg += f'<strong>Status:</strong> {task["status"]}\n' # Print task owner(s) users = task['users'] if not users: msg += f'<em>Geen eigenaren</em>\n' elif len(users) == 1: msg += f'<strong>Eigenaar:</strong> {users[0]["name"]}\n' elif 1 < len(users) <= 2: msg += f'<strong>Eigenaren:</strong> ' \ f'{users[0]["name"]} en {users[1]["name"]}\n' else: msg += '\n<strong>Eigenaren:</strong>\n' for user in task['users']: msg += f'• {user["name"]}\n' msg += '\n' # Print the description, if available try: msg += f'<strong>Beschrijving:</strong>\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'<a href="{minute_url}">Bijbehorende notulen</a>\n' except KeyError: msg += f'<em>Geen bijbehorende notulen</em>\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
def base32_id(self): return b32.encode(self.id)
def test_encode(self): self.assertEqual(b32.encode(1234), '16J')
def test_encode_split(self): self.assertEqual(b32.encode(123456, split=2), '3R-J0') self.assertEqual(b32.encode(123456, split=3), '3RJ-0')
def test_encode_float(self): self.assertEqual(b32.encode(4.2), '4')
def test_encode_zero_checksum(self): self.assertEqual(b32.encode(0, checksum=True), '00')
def test_encode_checksum(self): self.assertEqual(b32.encode(1234, checksum=True), '16JD')