use config file
This commit is contained in:
parent
e7463a3f6c
commit
a7da455862
|
@ -7,7 +7,7 @@ Remplissez le fichier `secrets/secrets.txt` et remplissez le avec les code que v
|
|||
|
||||
## Configure it
|
||||
|
||||
replace `bot_name` variable in `bot.py` with name of your bot without domain
|
||||
Copy `config.sample.txt` to `config.txt` and replace data by your data
|
||||
|
||||
## Use it
|
||||
|
||||
|
|
14
bot.py
14
bot.py
|
@ -1,7 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
# coding: utf-8
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# A Fediverse (decentralized social network, for instance using Mastodon) bot
|
||||
|
||||
from mastodon import StreamListener
|
||||
|
@ -16,10 +15,9 @@ config_file = "config.txt"
|
|||
secrets_filepath = "secrets/secrets.txt"
|
||||
log_filepath = "activity.log"
|
||||
log = init_log(log_filepath)
|
||||
bot_name = "nosafe"
|
||||
mastodon = init_mastodon(config_file, secrets_filepath)
|
||||
|
||||
def post_img(mastodon, text, visibility, log, config):
|
||||
def post_img(mastodon, text, log, config):
|
||||
img_path = get_parameter("img_path", config)
|
||||
file = random.choice(os.listdir(img_path+"/"))
|
||||
image_byte = open(img_path+"/"+file, "rb").read()
|
||||
|
@ -87,11 +85,11 @@ class BotListener(StreamListener):
|
|||
mentions = notification['status']['mentions']
|
||||
text = "@" + notification['status']["account"]["acct"] + " "
|
||||
for mention in mentions:
|
||||
if mention["acct"] != bot_name:
|
||||
if mention["acct"] != get_parameter("name_bot", config_file):
|
||||
text = text + "@" + mention["acct"] + " "
|
||||
|
||||
media_dict = post_img(mastodon, "NSFW", 1, log, config_file)
|
||||
mastodon.status_post(text, in_reply_to_id=id, media_ids=[media_dict], sensitive=True, visibility=visibility, spoiler_text="#NSFW")
|
||||
media_dict = post_img(mastodon, get_parameter("default_tag", config_file), log, config_file)
|
||||
mastodon.status_post(text, in_reply_to_id=id, media_ids=[media_dict], sensitive=get_parameter("sensitive", config_file), visibility=visibility, spoiler_text=get_parameter("spoiler_text", config_file))
|
||||
else:
|
||||
log.debug("no picture send :(")
|
||||
pass
|
||||
|
@ -106,8 +104,8 @@ def main():
|
|||
parser.add_argument("-s", "--stream", action="store_true", help="stream user profile")
|
||||
args = parser.parse_args()
|
||||
if args.img:
|
||||
media_dict = post_img(mastodon, "NSFW", 1, log, config_file)
|
||||
mastodon.status_post("", None, media_ids=[media_dict], sensitive=True, visibility='public', spoiler_text="#NSFW")
|
||||
media_dict = post_img(mastodon, get_parameter("default_tag", config_file), log, config_file)
|
||||
mastodon.status_post(get_parameter("default_text", config_file), None, media_ids=[media_dict], sensitive=get_parameter("sensitive", config_file), visibility='public', spoiler_text=get_parameter("spoiler_text", config_file))
|
||||
sys.exit()
|
||||
elif args.stream:
|
||||
stream = BotListener();
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
img_path: uri_path
|
||||
name_bot: "bot"
|
||||
sensitive: False
|
||||
default_text: "some text here"
|
||||
spoiler_text: "some text here"
|
||||
default_tag: "tag"
|
||||
|
||||
|
|
Reference in a new issue