added weights and stubs for all interactions
parent
8eee8a6294
commit
0d0d619b88
|
@ -62,30 +62,9 @@ class Tooter(Mastodon):
|
|||
with item.open('r') as f:
|
||||
cls.files[f.name] = f.readlines()
|
||||
|
||||
def tagged_public_toot(self):
|
||||
message = self.new_message()
|
||||
if( args.dry_run ):
|
||||
print(f"tagged toot message: \"{message}\"")
|
||||
else:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} tagged toots \"{message}\"")
|
||||
|
||||
self.toot(message)
|
||||
return 0
|
||||
|
||||
def plain_public_toot(self):
|
||||
message = self.new_message()
|
||||
if( args.dry_run ):
|
||||
print(f"toot message: \"{message}\"")
|
||||
else:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} toots \"{message}\"")
|
||||
|
||||
self.toot(message)
|
||||
return 0
|
||||
|
||||
@classmethod
|
||||
def new_message(cls):
|
||||
def new_message(cls) -> str:
|
||||
"""Choose a message from all the source texts. Returns the message."""
|
||||
sourcefile = random.choice(list(cls.files.values()))
|
||||
startline = random.randint(0,len(sourcefile))
|
||||
sourceline = ''
|
||||
|
@ -106,11 +85,122 @@ class Tooter(Mastodon):
|
|||
|
||||
return(message)
|
||||
|
||||
def toot_tagged_public(self) -> int:
|
||||
"""Get a random message, pick a small number of words in it to
|
||||
hashtag. Then toot it publicly."""
|
||||
if( args.debug ):
|
||||
print(f"{self.name} toot_tagged_public")
|
||||
rawmessage = self.new_message().split()
|
||||
numtaggable = sum(1 for word in rawmessage if len(word) > 3)
|
||||
# Pick a small number of words to tag, but not greater than the
|
||||
# total number of words there are, nor the total number of taggable
|
||||
# words.
|
||||
tagstodo = min(random.randint(1,6), len(rawmessage), numtaggable)
|
||||
while( tagstodo > 0 ):
|
||||
wordix = random.randrange(0, len(rawmessage))
|
||||
if( len(rawmessage[wordix]) > 3 and rawmessage[wordix][0] != '#' ):
|
||||
rawmessage[wordix] = '#' + rawmessage[wordix]
|
||||
tagstodo -=1
|
||||
|
||||
message = ' '.join(rawmessage)
|
||||
|
||||
if( args.dry_run ):
|
||||
print(f"tagged toot message: \"{message}\"")
|
||||
else:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} tagged toots \"{message}\"")
|
||||
|
||||
self.toot(message)
|
||||
return 0
|
||||
|
||||
def toot_plain_public(self) -> int:
|
||||
"""Toot a random message."""
|
||||
if( args.debug ):
|
||||
print(f"{self.name} toot_plain_public")
|
||||
message = self.new_message()
|
||||
if( args.dry_run ):
|
||||
print(f"toot message: \"{message}\"")
|
||||
else:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} toots \"{message}\"")
|
||||
|
||||
self.toot(message)
|
||||
return 0
|
||||
|
||||
def reply_random_local(self) -> int:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} reply_random_local")
|
||||
return( 0 )
|
||||
|
||||
def reply_random_home(self) -> int:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} reply_random_home")
|
||||
return( 0 )
|
||||
|
||||
def reply_random_federated(self) -> int:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} reply_random_federated")
|
||||
return( 0 )
|
||||
|
||||
def follow_random_local(self) -> int:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} follow_random_local")
|
||||
return( 0 )
|
||||
|
||||
def unfollow_random(self) -> int:
|
||||
if( args.debug ):
|
||||
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")
|
||||
return( 0 )
|
||||
|
||||
def favourite_random_local(self) -> int:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} favourite_random_local")
|
||||
return( 0 )
|
||||
|
||||
def favourite(self) -> int:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} favourite")
|
||||
return( 0 )
|
||||
|
||||
def federated_favourite(self) -> int:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} federated_favourite")
|
||||
return( 0 )
|
||||
|
||||
def report_random_local(self) -> int:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} report_random_local")
|
||||
return( 0 )
|
||||
|
||||
def random_interaction(self):
|
||||
"""Choose one possible interaction according to the weights, and do it."""
|
||||
interactions = [ self.plain_public_toot, self.tagged_public_toot ]
|
||||
weights = [1, 1]
|
||||
chosen = random.choices(population=interactions, weights=weights)[0]
|
||||
interactions = {
|
||||
self.reply_random_local: 1,
|
||||
self.reply_random_home: 1,
|
||||
self.reply_random_federated: 1,
|
||||
self.follow_random_local: 1,
|
||||
self.unfollow_random: 1,
|
||||
self.toot_plain_public: 1,
|
||||
self.toot_tagged_public: 1,
|
||||
self.toot_plain_unlisted: 1,
|
||||
self.boost_random_local: 1,
|
||||
self.favourite_random_local: 1,
|
||||
self.favourite: 1,
|
||||
self.federated_favourite: 1,
|
||||
self.report_random_local: 1
|
||||
}
|
||||
chosen = random.choices(population=list(interactions.keys()),
|
||||
weights=list(interactions.values()))[0]
|
||||
chosen()
|
||||
|
||||
def daemon_main(tooter: Tooter):
|
||||
|
|
Loading…
Reference in New Issue