make blacklist #8
This commit is contained in:
parent
3d28bcc9de
commit
8fc886351f
|
@ -3,3 +3,4 @@ secrets/secrets.txt
|
||||||
config.txt
|
config.txt
|
||||||
__pycache__/*
|
__pycache__/*
|
||||||
TootHTMLParser.pyc
|
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 | Limit send per minute per person | int |
|
||||||
| limit_hour | Limit send par hour 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
|
## 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
|
import requests, os, random, sys, time, json, logging, argparse, re
|
||||||
|
|
||||||
config_file = "config.txt"
|
config_file = "config.txt"
|
||||||
secrets_filepath = "secrets/secrets.txt"
|
secrets_filepath = "secrets/secrets.txt"
|
||||||
log_filepath = "activity.log"
|
log_filepath = "activity.log"
|
||||||
|
blacklist_filepath = "blacklist.json"
|
||||||
log = init_log(log_filepath)
|
log = init_log(log_filepath)
|
||||||
mastodon = init_mastodon(config_file, secrets_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):
|
def post_img(mastodon, text, log, config):
|
||||||
img_path = get_parameter("img_path", config)
|
img_path = get_parameter("img_path", config)
|
||||||
file = random.choice(os.listdir(img_path+"/"))
|
file = random.choice(os.listdir(img_path+"/"))
|
||||||
|
@ -50,6 +56,9 @@ class BotListener(StreamListener):
|
||||||
log.debug("Got a mention")
|
log.debug("Got a mention")
|
||||||
if notification["account"]["bot"] == False:
|
if notification["account"]["bot"] == False:
|
||||||
sender = notification['account']['acct'] # Get sender name
|
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_hour_filename = "limiter/hour/" + sender; # Forge file for limiter
|
||||||
sender_minute_filename = "limiter/minute/" + sender; # Forge file for limiter
|
sender_minute_filename = "limiter/minute/" + sender; # Forge file for limiter
|
||||||
|
|
||||||
|
|
Reference in New Issue