make blacklist #8
This commit is contained in:
parent
3d28bcc9de
commit
8fc886351f
|
@ -3,3 +3,4 @@ secrets/secrets.txt
|
|||
config.txt
|
||||
__pycache__/*
|
||||
TootHTMLParser.pyc
|
||||
blacklist.json
|
||||
|
|
|
@ -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
|
||||
|
||||
```
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
[
|
||||
"user@domain.tld",
|
||||
"userInYouInstance"
|
||||
]
|
15
bot.py
15
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
|
||||
|
||||
|
|
Reference in New Issue