diff --git a/tootapalooza/cli.py b/tootapalooza/cli.py index 939d968..53e4d0c 100644 --- a/tootapalooza/cli.py +++ b/tootapalooza/cli.py @@ -126,22 +126,59 @@ class Tooter(Mastodon): self.toot(message) return 0 + + def toot_plain_unlisted(self) -> int: + """Toot a random message unlisted.""" + message = self.new_message() + if( args.dry_run ): + print(f"toot unlisted message: \"{message}\"") + else: + if( args.debug ): + print(f"{self.name} toots unlisted \"{message}\"") + self.status_post( message, visibility='private' ) + return( 0 ) def reply_random_local(self) -> int: if( args.debug ): print(f"{self.name} reply_random_local") - return( 0 ) + + return(self._reply_random('local')) def reply_random_home(self) -> int: if( args.debug ): print(f"{self.name} reply_random_home") - return( 0 ) + + return(self._reply_random('home')) - def reply_random_federated(self) -> int: + def reply_random_public(self) -> int: if( args.debug ): - print(f"{self.name} reply_random_federated") - return( 0 ) - + print(f"{self.name} reply_random_public") + + return(self._reply_random('public')) + + def _reply_random(self, timeline: str) -> int: + """Read the given timeline, pick a post at random, reply to it. + Updates the read marker for that timeline.""" + chunk_size = 20 + max_posts = 100 + timeline_list = [] + while( len(timeline_list) < max_posts ): + posts_received = self.timeline(timeline=timeline, limit=chunk_size) + if( len(posts_received) == 0 ): + break + timeline_list.extend(posts_received) + + reply_post = random.choice(timeline_list) + message = self.new_message() + + if( args.dry_run ): + print(f"{self.name} replied to {timeline} {reply_post.id}") + else: + if( args.debug ): + print(f"{self.name} replied to {reply_post.account.acct} {reply_post.uri}") + self.markers_set([timeline], [reply_post.id]) + self.status_post( message, in_reply_to_id=reply_post.id, visibility='public' ) + def follow_random_local(self) -> int: if( args.debug ): print(f"{self.name} follow_random_local") @@ -152,11 +189,6 @@ class Tooter(Mastodon): print(f"{self.name} unfollow_random") return( 0 ) - def toot_plain_unlisted(self) -> int: - if( args.debug ): - print(f"{self.name} toot_plain_unlisted") - return( 0 ) - def boost_random_local(self) -> int: if( args.debug ): print(f"{self.name} boost_random_local") @@ -185,9 +217,9 @@ class Tooter(Mastodon): def random_interaction(self): """Choose one possible interaction according to the weights, and do it.""" interactions = { - self.reply_random_local: 1, - self.reply_random_home: 1, - self.reply_random_federated: 1, + self.reply_random_local: 4, + self.reply_random_home: 0, + self.reply_random_public: 0, self.follow_random_local: 1, self.unfollow_random: 1, self.toot_plain_public: 1,