Python backend for a Slack's kudos plugin.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: merge

+172 -9
+18
.pre-commit-config.yaml
··· 1 + repos: 2 + - repo: "https://github.com/pycqa/isort" 3 + rev: 5.10.0 4 + hooks: 5 + - id: isort 6 + args: 7 + - "--profile" 8 + - black 9 + name: isort 10 + - repo: "https://github.com/ambv/black" 11 + rev: 21.10b0 12 + hooks: 13 + - id: black 14 + language_version: python3 15 + - repo: "https://github.com/pre-commit/mirrors-mypy" 16 + rev: v0.910 17 + hooks: 18 + - id: mypy
+5 -3
kefi/routers/commands.py
··· 4 4 from sqlmodel import Session, select 5 5 6 6 from kefi.dependencies import SlashCommandParams, get_session 7 - from kefi.models import engine 8 7 from kefi.models.users import User 9 8 from kefi.templates import template_command_not_found, template_command_wallet 10 9 ··· 34 33 session.commit() 35 34 36 35 if Commands.WALLET in command.text.lower(): 37 - amount = random.randint(1, 100) 38 - return template_command_wallet(command.user_name, amount) 36 + remaining_amount = random.randint(0, 100) 37 + received_amount = random.randint(0, 100) 38 + return template_command_wallet( 39 + command.user_name, remaining_amount, received_amount 40 + ) 39 41 return template_command_not_found()
+147 -4
kefi/templates.py
··· 1 1 from typing import Dict 2 2 3 3 4 - def template_command_wallet(user_name: str, amount: int) -> Dict: 4 + def template_command_wallet( 5 + user_name: str, remaining_amount: int, received_amount: int 6 + ) -> Dict: 5 7 return { 6 8 "blocks": [ 7 9 { ··· 13 15 "fields": [ 14 16 { 15 17 "type": "mrkdwn", 16 - "text": f"*Pendiente gastar:*\n {amount} dekas", 18 + "text": f"*Pendiente gastar:*\n {remaining_amount} dekas", 19 + } 20 + ], 21 + }, 22 + { 23 + "type": "section", 24 + "fields": [ 25 + { 26 + "type": "mrkdwn", 27 + "text": f"*Recibidos:*\n {received_amount} dekas", 28 + } 29 + ], 30 + }, 31 + ] 32 + } 33 + 34 + 35 + def template_command_congrats( 36 + user_name_sends: str, user_name_receives: str, message: str 37 + ) -> Dict: 38 + return { 39 + "blocks": [ 40 + { 41 + "type": "header", 42 + "text": { 43 + "type": "plain_text", 44 + "text": f"¡Enhorabuena @{user_name_receives}! :trophy:", 45 + "emoji": True, 46 + }, 47 + }, 48 + { 49 + "type": "section", 50 + "text": { 51 + "type": "mrkdwn", 52 + "text": f'Mensaje de *{user_name_sends}*: \n "{message}"', 53 + }, 54 + "accessory": { 55 + "type": "image", 56 + "image_url": "", 57 + "alt_text": "¡Enhorabuena!", 58 + }, 59 + }, 60 + { 61 + "type": "context", 62 + "elements": [ 63 + { 64 + "type": "mrkdwn", 65 + "text": f":moneybag: *{user_name_sends}* le da a *{user_name_receives}* 25 kefis.", 66 + } 67 + ], 68 + }, 69 + ] 70 + } 71 + 72 + 73 + def template_command_kudos( 74 + user_name_sends: str, user_name_receives: str, message: str 75 + ) -> Dict: 76 + return { 77 + "blocks": [ 78 + { 79 + "type": "header", 80 + "text": { 81 + "type": "plain_text", 82 + "text": f"¡Gracias @{user_name_receives}! :loveparrot:", 83 + "emoji": True, 84 + }, 85 + }, 86 + { 87 + "type": "section", 88 + "text": { 89 + "type": "mrkdwn", 90 + "text": f'Mensaje de *{user_name_sends}*: \n "{message}"', 91 + }, 92 + "accessory": { 93 + "type": "image", 94 + "image_url": "", 95 + "alt_text": "¡Gracias!", 96 + }, 97 + }, 98 + { 99 + "type": "context", 100 + "elements": [ 101 + { 102 + "type": "mrkdwn", 103 + "text": f":moneybag: *{user_name_sends}* le da a *{user_name_receives}* 100 kefis.", 104 + } 105 + ], 106 + }, 107 + ] 108 + } 109 + 110 + 111 + def template_command_high_five( 112 + user_name_sends: str, user_name_receives: str, message: str 113 + ) -> Dict: 114 + return { 115 + "blocks": [ 116 + { 117 + "type": "header", 118 + "text": { 119 + "type": "plain_text", 120 + "text": f"¡{user_name_sends} le envía un high five a {user_name_receives}! :hand:", 121 + "emoji": True, 122 + }, 123 + }, 124 + { 125 + "type": "section", 126 + "text": {"type": "plain_text", "text": f'*"{message}"'}, 127 + "accessory": { 128 + "type": "image", 129 + "image_url": "", 130 + "alt_text": "High five!", 131 + }, 132 + }, 133 + { 134 + "type": "context", 135 + "elements": [ 136 + { 137 + "type": "mrkdwn", 138 + "text": f":moneybag: *{user_name_receives}* recibe 5 kefis de *{user_name_sends}*", 17 139 } 18 140 ], 19 141 }, ··· 21 143 } 22 144 23 145 24 - def template_command_not_found() -> str: 25 - return "Comando no reconocido" 146 + def template_command_deposit(amount: int) -> Dict: 147 + return { 148 + "blocks": [ 149 + { 150 + "type": "section", 151 + "text": { 152 + "type": "mrkdwn", 153 + "text": f"*¡Buenas noticias!* \n Acabamos de ingresar {amount} kefis en tu cartera. ", 154 + }, 155 + } 156 + ] 157 + } 158 + 159 + 160 + def template_command_not_found() -> Dict: 161 + return { 162 + "blocks": [ 163 + { 164 + "type": "section", 165 + "text": {"type": "plain_text", "text": "No he entendido el comando."}, 166 + } 167 + ] 168 + }
+2 -2
kefi/tests/test_commands.py
··· 1 1 from faker import Faker 2 2 from fastapi.testclient import TestClient 3 3 4 + 4 5 fake = Faker() 5 6 6 7 ··· 24 25 "api_app_id": "api_app_id", 25 26 }, 26 27 ) 27 - assert response.status_code == 28 - 28 + assert response.status_code == 200 29 29 30 30 31 31 def test_wallet_commad(client: TestClient):