Browse Source

make blacklist #8

tags/1.3
Dryusdan 1 year ago
parent
commit
8fc886351f
4 changed files with 19 additions and 3 deletions
  1. +1
    -0
      .gitignore
  2. +2
    -0
      README.md
  3. +4
    -0
      blacklist.sample.json
  4. +12
    -3
      bot.py

+ 1
- 0
.gitignore View File

@@ -3,3 +3,4 @@ secrets/secrets.txt
config.txt
__pycache__/*
TootHTMLParser.pyc
blacklist.json

+ 2
- 0
README.md View File

@@ -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

```


+ 4
- 0
blacklist.sample.json View File

@@ -0,0 +1,4 @@
[
"user@domain.tld",
"userInYouInstance"
]

+ 12
- 3
bot.py View File

@@ -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


Loading…
Cancel
Save