Refresh config json

Hello is there any way i can make the bot refresh the json config file? like “save settings” in sbot? I want to change a value in the config file and with the help of some forum posts from [JellyBitz] and the api guide for plugins i could replace the config file with my file where i changed a value but it cannot be loaded “live” into the bot. Is there a way to make it work without restarting the bot?

Cheers,
rbrt

You can reload it from Python by calling set_profile('default').

1 Like

Event current profile is already default?

Yes. I will add a custom function called reload_profile which has the same functionality as what I posted above.

set_profile('default') worked well! thanks. I found the set_profile(‘default’) in the guide before as im very new to python and phbot plugins the wording were a little bit confusing to me. I searched for “Profiles” inside of phbot but havent found one so i thought it were something from an older Version. Anyways, i know want to loop the config change. Ive tried def event_loop(): but that didnt worked. I dont know if a “def” can be looped? if i try to loop def event_loop(): log(‘loop’) it does work, but with the changing config def from JellyBitz it does not. Can you help me out again?

Cheers,
rbrt

Here is the code

from phBot import *
import shutil
import os

log('Plugin: xAutoConfig successfully loaded.')

# Called when the user successfully selects a character. No character data has been loaded yet.
def joined_game():
	# JSON config not found
	if not os.path.exists(get_config_path()):
		# Looking for JSON default configs
		defaultConfig = get_config_dir()+"config2"
		# Loading JSON default configs
		if os.path.exists(defaultConfig):
			shutil.copyfile(defaultConfig,get_config_path())
			log("Plugin: Default JSON configurations successfully loaded (xAutoConfig)")
set_profile('config2')

log('[%s] Loaded' % __name__)

Alright, with set_profile(‘default’) most of the code is redundent. I just understood that. But this does not loop somehow:

from phBot import *
import os

log('Plugin:  settings changed')
def event_loop():
	set_profile('config2')

log('[%s] Loaded' % __name__)

It only changes the profile if your character is selected.

1 Like

thanks man, works like a charm. How can i change the 500ms interval? 500ms is kind of overkill

Thanks,
rbrt

You don’t. You will need to keep track of how much time has passed since the last reload.