Minor refactor

This commit is contained in:
Anon 2022-10-28 20:26:14 -07:00
parent 42ee67a107
commit e2c26d5b46

View File

@ -165,7 +165,7 @@ class YandereBot:
# Return a list of hashes with profiles
try:
for f in self.settings_behavior["master_list"]:
add_list = get_list_of_hashes_with_profiles(f, self.settings_post, self.settings_post_default, get_profile)
add_list = get_list_of_hashes_with_profiles(f, self.settings_post, self.settings_post_default)
list_pictures.extend(add_list)
except IOError as e:
print(e)
@ -325,6 +325,8 @@ class YandereBot:
# [BEGIN THE PROGRAM]
def prime_bot(self):
if self.primed:
return
self.load_picture_list()
self.validate_post_settings()
if not self.debug_mode:
@ -332,10 +334,8 @@ class YandereBot:
self.login()
self.primed = True
def start(self, delay=0):
# Prime bot if not already primed.
if not self.primed:
self.prime_bot()
def start(self):
self.prime_bot()
# Begin posting
self.main_loop()
@ -380,16 +380,11 @@ def get_profile(hash_obj, profiles, profiles_default):
# @param profiles List of profiles -> self.settings_post
# @param profiles_default The default profile to apply
# @param callback_get_profile Callback function -> should return a single profile. Default: get_profile()
def get_list_of_hashes_with_profiles(f_name, profiles, profiles_default, callback_get_profile):
def get_list_of_hashes_with_profiles(f_name, profiles, profile_default):
r = []
with open(f_name, "r") as f:
for _line in f:
line = _line.strip()
if not yanlib.is_valid_hash(line):
continue
hash_obj = yanlib.HashObject(line)
post_setting = callback_get_profile(hash_obj, profiles, profiles_default)
r.append(YanBotHash(hash_obj, post_setting))
for item in yanlib.get_hash_list(f_name):
post_setting = get_profile(item, profiles, profile_default)
r.append(YanBotHash(item, post_setting))
return r