diff --git a/.gitignore b/.gitignore index d1fc789..21986f0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ secrets/secrets.txt config.txt __pycache__/* TootHTMLParser.pyc +blacklist.json diff --git a/README.md b/README.md index 2322de9..861b188 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ If you don't want any "spoiler text", just leave the line empty. | limit | Limit send per minute per person | int | | limit_hour | Limit send par hour per person | int | +Copy `blacklist.sample.json` to `blacklist.json` and replace or add accounts that should not receive any image + ## Use it ``` diff --git a/blacklist.sample.json b/blacklist.sample.json new file mode 100644 index 0000000..24b69b3 --- /dev/null +++ b/blacklist.sample.json @@ -0,0 +1,4 @@ +[ + "user@domain.tld", + "userInYouInstance" +] diff --git a/bot.py b/bot.py index 46e4b17..c0b90e6 100755 --- a/bot.py +++ b/bot.py @@ -11,12 +11,18 @@ from utils.config import get_parameter, init_log, init_mastodon import requests, os, random, sys, time, json, logging, argparse, re -config_file = "config.txt" -secrets_filepath = "secrets/secrets.txt" -log_filepath = "activity.log" +config_file = "config.txt" +secrets_filepath = "secrets/secrets.txt" +log_filepath = "activity.log" +blacklist_filepath = "blacklist.json" log = init_log(log_filepath) mastodon = init_mastodon(config_file, secrets_filepath) +blacklist_file = open(blacklist_filepath,'r') +BLACKLIST = json.loads(blacklist_file.read()) +blacklist_file.close() + + def post_img(mastodon, text, log, config): img_path = get_parameter("img_path", config) file = random.choice(os.listdir(img_path+"/")) @@ -50,6 +56,9 @@ class BotListener(StreamListener): log.debug("Got a mention") if notification["account"]["bot"] == False: sender = notification['account']['acct'] # Get sender name + if sender in BLACKLIST: + log.info("Service refused to %s" % sender) + return sender_hour_filename = "limiter/hour/" + sender; # Forge file for limiter sender_minute_filename = "limiter/minute/" + sender; # Forge file for limiter