Skip to content

Commit

Permalink
add a ignore_unknown option
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Jul 10, 2024
1 parent fcc0c4f commit 6d3879a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pybliotecario.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ main_folder = /home/<username>/.local/share/pybliotecario
# quiet defaults to false, whether the bot should always reply back
quiet = false
# when chivato is true, the bot will write to the main chat_id whenever an user not in chat_id writes to the bot
chivato = false #
chivato = false
# if true, messages from chat ids not included in `chat_id` will be ignored
ignore_unknown = false

[FACEBOOK]
verify = <verify token from fb>
Expand Down
13 changes: 9 additions & 4 deletions src/pybliotecario/core_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def main_loop(tele_api, config=None, clear=False):
accepted_ids = config.getidlist("DEFAULT", "chat_id")
main_id = config.getmainid("DEFAULT", "chat_id")
chivato = config.getboolean("DEFAULT", "chivato", fallback=False)
ignore_unknown = config.getboolean("DEFAULT", "ignore_unknown", fallback=False)

global except_counter
except_counter = 0
Expand All @@ -96,10 +97,14 @@ def act_on_message(message):
chat_id = message.chat_id

# In "chivato" mode, send a message to the main chat_id if sender is not recognized
if chivato and chat_id not in accepted_ids:
chivato_msg = f"""El usuario @{message.username} ({chat_id=}) ha enviado el siguiente mensaje:
{message.raw}"""
tele_api.send_message(chivato_msg, main_id)
if chat_id not in accepted_ids:
if chivato:
chivato_msg = f"""El usuario @{message.username} ({chat_id=}) ha enviado el siguiente mensaje:
{message.raw}"""
tele_api.send_message(chivato_msg, main_id)
if ignore_unknown:
logger.info(f"Chat id {chat_id} not known, ignoring")
return

if message.is_command:
# Call the selected command and act on the message
Expand Down

0 comments on commit 6d3879a

Please sign in to comment.