Skip to content

Commit

Permalink
Added filters option to messages
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielRF committed Jul 25, 2022
1 parent 8d137e8 commit 23ea33f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,37 @@ Defina as variáveis na aba `Secrets` do repositório:

`{EMOJI}`: Emoji escolhido aleatoriamente da lista.

## Filtros

Por padrão, todos os elementos do feed RSS serão enviados. Caso queira filtrar o conteúdo, crie um arquivo chamado `RULES.txt` e adicione as regras desejadas ao arquivo. As regras serão executadas em ordem!

> O valor contido em termo funcionará independente de letras maiúsculas ou minúsculas.
`ACCEPT:ALL`: Todas as mensagens serão enviadas;

`DROP:ALL`: Todas as mensagens não serão enviadas;

`ACCEPT:termo`: A mensagem será enviada se `termo` estiver presente;

`DROP:termo`: A mensagem não será enviada se `termo` estiver presente.

### Exemplos de Filtros:

1. Todos as mensagens serão enviadas, menos as que tiverem o termo `política`:

```
ACCEPT:ALL
DROP:Política
```

2. Nenhuma mensagem será enviada, com exceção das mensagens com os termos `futebol` e `vôlei`:

```
DROP:ALL
ACCEPT:futebol
ACCEPT:vôlei
```

## Uso

Faça um *Fork*, defina as variáveis e habilite a ação em "*Enable workflow*". Pronto!
Expand Down
23 changes: 23 additions & 0 deletions rss2telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ def check_history(link):
conn.close()
return data

def firewall(text):
try:
rules = open(f'RULES.txt', 'r')
except FileNotFoundError:
return True
result = None
for rule in rules.readlines():
opt, arg = rule.split(':')
arg = arg.strip()
if arg == 'ALL' and opt == 'DROP':
result = False
elif arg == 'ALL' and opt == 'ACCEPT':
result = True
elif arg.lower() in text.lower() and opt == 'DROP':
result = False
elif arg.lower() in text.lower() and opt == 'ACCEPT':
result = True
return result

def send_message(topic, button):
if DRYRUN == 'failure':
return
Expand All @@ -51,6 +70,10 @@ def send_message(topic, button):
else:
MESSAGE_TEMPLATE = f'<b>{topic["title"]}</b>'

if not firewall(MESSAGE_TEMPLATE):
print(f'xxx {topic["title"]}')
return

btn_link = button
if button:
btn_link = types.InlineKeyboardMarkup()
Expand Down

0 comments on commit 23ea33f

Please sign in to comment.