Updated to use 2d matrix for post setting
This commit is contained in:
parent
e84c82067d
commit
0e82467772
@ -42,7 +42,8 @@ def main():
|
||||
parser.add_argument("--debug", help="Same as --dry-run", action="store_true")
|
||||
parser.add_argument("-c", "--config", help="Set custom config file (Default: {})".format(default_cfg), default=default_cfg)
|
||||
parser.add_argument("-k", "--keyfile", help="Keyfile used for decryption")
|
||||
parser.add_argument("-i", "--index", help="Start at index (only matters if profile is set to sequential", default=0)
|
||||
parser.add_argument("-i", "--index", help="Start at index (only matters if profile is set to sequential)", default=0)
|
||||
parser.add_argument("-s", "--state", help="Set comma seperated state (only matters if profile is set to sequential)", default=None)
|
||||
parser.add_argument("remainder", help=argparse.SUPPRESS, nargs=argparse.REMAINDER)
|
||||
arguments = parser.parse_args()
|
||||
|
||||
@ -67,6 +68,12 @@ def main():
|
||||
)
|
||||
|
||||
yandere.currentIndexCount = int(arguments.index)
|
||||
if arguments.state:
|
||||
state = arguments.state.split(",")
|
||||
if len(state) != len(yandere_config.settings_post):
|
||||
print("State length does not match profile length. Ignoring...")
|
||||
else:
|
||||
yandere.currentProfileIndex = list(map(int, state))
|
||||
|
||||
# Setup exit calls
|
||||
# Must be done after we declare our bot(s), otherwise this will be called if quitting on decrypting settings )
|
||||
|
@ -24,6 +24,7 @@ import shutil
|
||||
import importlib
|
||||
import magic
|
||||
import random
|
||||
import copy
|
||||
from threading import Event
|
||||
from mastodon import Mastodon, MastodonIllegalArgumentError, MastodonAPIError, MastodonVersionError
|
||||
|
||||
@ -49,6 +50,7 @@ class YandereBot:
|
||||
consecutive_failed_uploads = 0
|
||||
currentSessionCount = 0
|
||||
currentIndexCount = 0
|
||||
currentProfileIndex = tuple()
|
||||
debug_mode = False
|
||||
primed = False
|
||||
decrypted = False
|
||||
@ -62,6 +64,7 @@ class YandereBot:
|
||||
self.load_settings(self.cfg)
|
||||
self.debug_mode = debug_mode or self.settings_behavior["debug"]
|
||||
self.settings_encrypt["keyfile"] = keyfile or self.settings_encrypt["keyfile"]
|
||||
self.currentProfileIndex = [0]*len(self.settings_post)
|
||||
random.seed(os.urandom(16))
|
||||
if prime_bot:
|
||||
self.prime_bot()
|
||||
@ -125,11 +128,18 @@ class YandereBot:
|
||||
url = picked["file_url"] if picked else None
|
||||
path = picked["full_path"] if picked else None
|
||||
nsfw = picked["nsfw"] if picked else None
|
||||
index = (self.currentIndexCount - int(self.currentSessionCount > 0)) % len(self.settings_post)
|
||||
|
||||
posted_once = int(self.currentSessionCount > 0)
|
||||
index = (self.currentIndexCount - posted_once) % len(self.settings_post)
|
||||
state_print = copy.copy(self.currentProfileIndex)
|
||||
state_print[index] = state_print[index] - posted_once
|
||||
|
||||
state_print = [state_print[i] % len(self.settings_post[i]) for i in range(0, len(self.currentProfileIndex))]
|
||||
|
||||
print("Profile: {} | Index: {} | NSFW: {} | Path: {} | URL: {}".format(
|
||||
profile, index, nsfw, path, url
|
||||
))
|
||||
print("State: {}".format(','.join(map(str, state_print))))
|
||||
|
||||
# Returns a list of media paths (without the hashes)
|
||||
def download_media(self, picked_profile):
|
||||
@ -235,15 +245,22 @@ class YandereBot:
|
||||
return picked
|
||||
|
||||
|
||||
def pick_index(self, mode, current_index, length):
|
||||
if mode == "random":
|
||||
return random.randint(0, length - 1)
|
||||
elif mode == "sequential":
|
||||
return current_index % length
|
||||
|
||||
|
||||
def pick_profile(self):
|
||||
profiles = self.settings_post
|
||||
tag_select = self.settings_behavior["tag_select"].lower()
|
||||
pick_index = None
|
||||
if tag_select == "random":
|
||||
pick_index = random.randint(0, len(profiles) - 1)
|
||||
elif tag_select == "sequential":
|
||||
pick_index = self.currentIndexCount % len(profiles)
|
||||
return profiles[pick_index]
|
||||
# Get x and y
|
||||
mode = self.settings_behavior["tag_select"].lower()
|
||||
posts = self.settings_post
|
||||
x = self.pick_index(mode, self.currentIndexCount, len(posts))
|
||||
y = self.pick_index(mode, self.currentProfileIndex[x], len(posts[x]))
|
||||
|
||||
# Return the Profile
|
||||
return x, y
|
||||
|
||||
|
||||
# The main post function
|
||||
@ -260,7 +277,8 @@ class YandereBot:
|
||||
# Attempt post
|
||||
try:
|
||||
# Post
|
||||
picked_profile = self.pick_profile()
|
||||
x, y = self.pick_profile()
|
||||
picked_profile = self.settings_post[x][y]
|
||||
picked = self.download_media(picked_profile)
|
||||
self._post(picked)
|
||||
|
||||
@ -269,6 +287,9 @@ class YandereBot:
|
||||
# After a successful post
|
||||
self.currentSessionCount += 1
|
||||
self.consecutive_failed_uploads = 0
|
||||
|
||||
# Set indexes
|
||||
self.currentProfileIndex[x] += 1
|
||||
self.currentIndexCount += 1
|
||||
|
||||
# The post was successful
|
||||
@ -362,7 +383,3 @@ class FailedLogin(Exception):
|
||||
|
||||
class BadCfgFile(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class MissingMasterList(Exception):
|
||||
pass
|
||||
|
Reference in New Issue
Block a user