|
|
@ -11,25 +11,24 @@ from pprint import pprint |
|
|
|
|
|
|
|
# Mastodon Stream Listener defines functions to react when something happens on Mastodon. We inherit it. |
|
|
|
class BotListener(StreamListener): |
|
|
|
def __init__(self, mastodon): |
|
|
|
print("init") |
|
|
|
StreamListener.__init__(self) |
|
|
|
def __init__(self, mastodon, log): |
|
|
|
log.debug("initialisation step") |
|
|
|
#StreamListener.__init__(self) |
|
|
|
self.mastodon = mastodon |
|
|
|
pprint(vars(mastodon.stream_user(StreamListener))) |
|
|
|
|
|
|
|
def handle_mention(self, status): |
|
|
|
log.debug('Got a mention!') |
|
|
|
self.log = log |
|
|
|
super() |
|
|
|
#pprint(vars(mastodon.stream_user(StreamListener))) |
|
|
|
|
|
|
|
def on_notification(self, notification): |
|
|
|
log.debug("here") |
|
|
|
for thread in self.threads: |
|
|
|
if(not thread.is_alive()): |
|
|
|
logging.info("removing thread" + str(thread)) |
|
|
|
self.threads.remove(thread) |
|
|
|
log.debug("Got a notification!") |
|
|
|
#for thread in self.threads: |
|
|
|
# if(not thread.is_alive()): |
|
|
|
# logging.info("removing thread" + str(thread)) |
|
|
|
# self.threads.remove(thread) |
|
|
|
|
|
|
|
#We react to mentions only |
|
|
|
if(notification['type'] != 'mention'): |
|
|
|
log.info("nevermind, it's not a mention") |
|
|
|
log.debug("nevermind, it's not a mention") |
|
|
|
return |
|
|
|
|
|
|
|
#So there is a toot ! |
|
|
@ -48,6 +47,9 @@ class BotListener(StreamListener): |
|
|
|
#If the toot is not in answer to a drawing |
|
|
|
answerTo = status["in_reply_to_id"] |
|
|
|
|
|
|
|
def on_update(self, status): |
|
|
|
log.debug("update ! ") |
|
|
|
|
|
|
|
def get_parameter( parameter, file_path ): |
|
|
|
# Check if secrets file exists |
|
|
|
if not os.path.isfile(file_path): |
|
|
@ -98,6 +100,8 @@ def init_log(log_filepath): |
|
|
|
stream_handler.setLevel(logging.DEBUG) |
|
|
|
log.addHandler(stream_handler) |
|
|
|
|
|
|
|
return log |
|
|
|
|
|
|
|
def init_mastodon(config, secrets): |
|
|
|
uc_client_id = get_parameter("client_id", secrets) |
|
|
|
uc_client_secret = get_parameter("client_secret", secrets) |
|
|
@ -114,10 +118,10 @@ def init_mastodon(config, secrets): |
|
|
|
|
|
|
|
|
|
|
|
def run(mastodon, log): |
|
|
|
pprint(log) |
|
|
|
log.info("Start streaming") |
|
|
|
listener = BotListener(mastodon, logging) |
|
|
|
mastodon.stream_user(listener) |
|
|
|
#post_img(mastodon, "NSFW", 1) |
|
|
|
listener = BotListener(mastodon, log) |
|
|
|
mastodon.stream_public(listener) |
|
|
|
|
|
|
|
def main(): |
|
|
|
config_file = "config.txt" |
|
|
|