Skip to content

Commit 0775222

Browse files
Merge branch 'main' into assistente-ia
2 parents fd90e41 + f5e32bc commit 0775222

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

.github/workflows/issue-trigger.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
run: python src/automations/main.py
2222
env:
2323
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
24+
TELEGRAM_USERS_MAP: ${{ env.TELEGRAM_USERS_MAP }}
2425
ISSUE_NUMBER: ${{ github.event.issue.number }}
2526
ISSUE_TITLE: ${{ github.event.issue.title }}
2627
ISSUE_URL: ${{ github.event.issue.html_url }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.claude
44
CLAUDE.md
55
.DS_Store
6+
venv

src/automations/main.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import httpx
21
import os
2+
import re
3+
import httpx
34
from urllib.parse import quote
45

56
TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
@@ -8,8 +9,20 @@
89
COMMENT_USER = os.getenv("COMMENT_USER")
910
COMMENT_BODY = os.getenv("COMMENT_BODY")
1011
COMMENT_URL = os.getenv("COMMENT_URL")
12+
13+
# carrega a lista de usuários do Telegram a partir da variável de ambiente TELEGRAM_USERS_MAP
14+
# ex: @github-user:@telegram_user,@github-user2:@telegram_user2,...
15+
16+
TELEGRAM_USERS_MAP = os.getenv("TELEGRAM_USERS_MAP")
17+
18+
# Gera o mapa de usuários do Telegram a partir da variável de ambiente
19+
TELEGRAM_USERS_MAP = dict(
20+
user.split(":") for user in TELEGRAM_USERS_MAP.split(",") if ":" in user
21+
)
22+
1123
CHAT_ID = "-1002120660974"
1224
THREAD_ID = 1888
25+
1326
# url = f"https://api.telegram.org/bot{TOKEN}/getUpdates"
1427

1528

@@ -28,6 +41,21 @@ def main():
2841
*Texto do comentário*:
2942
{comment_body_escaped}
3043
""".strip()
44+
45+
# Verifica se o mapa de usuários do Telegram não está vazio para realizar a substituição
46+
if(TELEGRAM_USERS_MAP):
47+
48+
# percorre cada palavra do corpo do comentário
49+
for palavra in COMMENT_BODY.split():
50+
51+
# se a palavra começa com @ e tem mais de 3 caracteres, verifica se está no mapa de usuários do Telegram
52+
if palavra.startswith("@") and len(palavra) > 3 and palavra in TELEGRAM_USERS_MAP.keys():
53+
54+
# se a palavra está no mapa de usuários do Telegram, substitui pelo id do usuário do Telegram
55+
56+
telegram_user = re.sub(r'([_*\[\]()~`>#+\-=|{}.!])', r'\\\1', TELEGRAM_USERS_MAP[palavra])
57+
message += f"\n{telegram_user}"
58+
3159
params = {
3260
"chat_id": CHAT_ID,
3361
"message_thread_id": THREAD_ID,
@@ -38,7 +66,7 @@ def main():
3866
url = f"https://api.telegram.org/bot{TOKEN}/sendMessage"
3967
response = httpx.get(url, params=params)
4068
status_code = response.status_code
41-
69+
4270
if status_code != 200:
4371
print(f"Erro {status_code}: {response.json()}")
4472
raise Exception

0 commit comments

Comments
 (0)