Skip to content

Commit

Permalink
add quiet to components as well
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Jul 10, 2024
1 parent 2292990 commit 16e7721
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/pybliotecario/backend/facebook_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,11 @@ def send_file(self, filepath, chat):

if __name__ == "__main__":
from configparser import ConfigParser

logger.info("Testing FB Util")
verify = "your_verify_token"
app_token = "your_app_key"
config = ConfigParser()
config["FACEBOOK"] = {
"verify": verify,
"app_token": app_token
}
config["FACEBOOK"] = {"verify": verify, "app_token": app_token}
fb_util = FacebookUtil(config, debug=True)
fb_util.act_on_updates(lambda x: print(x))
9 changes: 7 additions & 2 deletions src/pybliotecario/components/component_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
the class Component will just pass the text of the msg (or the command)
to the `act_on_command` or `act_on_message` methods.
"""

import logging
import os
import sys
Expand Down Expand Up @@ -138,11 +139,15 @@ def act_on_command(self, content=None):
self.telegram.send_message("Command line argument invoked", self.chat_id)

# Some useful wrappers
def send_msg(self, msg, chat_id=None, markdown=False):
def send_msg(self, msg, chat_id=None, markdown=False, quiet=False):
"""Wrapper around API send_msg, if chat_id is not defined
it will use the chat_id this class was instantiated to"""
it will use the chat_id this class was instantiated to.
If ``quiet`` == True, use `send_quiet_message`
"""
if chat_id is None:
chat_id = self.interaction_chat
if quiet:
return self.telegram.send_quiet_message(msg, chat_id, markdown=markdown)
return self.telegram.send_message(msg, chat_id, markdown=markdown)

def send_img(self, imgpath, chat_id=None, delete=False):
Expand Down
1 change: 1 addition & 0 deletions src/pybliotecario/components/dnd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module implementing some functions useful for playing DnD over the internet
"""

import logging
from random import randint
import re
Expand Down
1 change: 1 addition & 0 deletions src/pybliotecario/components/github_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
and follow the instructions
"""

import datetime
import logging

Expand Down
1 change: 1 addition & 0 deletions src/pybliotecario/components/ip_lookup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Server-helper function to look up the current IP of the program """

import logging
import urllib.request

Expand Down
1 change: 1 addition & 0 deletions src/pybliotecario/components/photocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
It's a companion to https://github.com/scarlehoff/websito/blob/master/views/foto.pug
"""

from datetime import datetime
import json
import logging
Expand Down
3 changes: 2 additions & 1 deletion src/pybliotecario/components/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
For instant, good_morning will call the command defined in
/script good_morning will call the command defined in [SCRIPTS] good_morning
"""

import logging
import pathlib
import shlex
Expand Down Expand Up @@ -148,7 +149,7 @@ def telegram_message(self, msg):
else:
cmd_list = [f"./{command_path.name}"] + script_args
sp.run(cmd_list, check=True, cwd=command_path.parent)
self.send_msg("Command ran")
self.send_msg("Command ran", quiet=True)
except sp.CalledProcessError:
self.send_msg("Command ran but failed")
else:
Expand Down
1 change: 1 addition & 0 deletions src/pybliotecario/components/stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"""

import json
import logging

Expand Down
1 change: 1 addition & 0 deletions src/pybliotecario/components/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This component contains system-commands to be run
remotely
"""

import subprocess as sp

from pybliotecario.components.component_core import Component
Expand Down
1 change: 1 addition & 0 deletions src/pybliotecario/components/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
consumer_secret = <consumer_secret>
```
"""

import logging

import tweepy as tw
Expand Down

0 comments on commit 16e7721

Please sign in to comment.