mirror of
https://git.phreedom.club/localhost_frssoft/FMN_bot.git
synced 2025-04-07 03:46:30 +02:00
Lower read\write in states file No attempt force upload attachment (server issues) More logger catchers
33 lines
732 B
Python
33 lines
732 B
Python
import json
|
|
from loguru import logger
|
|
|
|
states_file = 'fmn_states.json'
|
|
|
|
class states_stor:
|
|
states = None
|
|
|
|
|
|
@logger.catch
|
|
def read_states():
|
|
try:
|
|
with open(states_file, 'rt') as f:
|
|
current_states = json.loads(f.read())
|
|
except:
|
|
logger.warning('Стейты не найдены, создание плейсхолдера')
|
|
write_states()
|
|
current_states = {}
|
|
return current_states
|
|
|
|
|
|
@logger.catch
|
|
def write_states(new_states={}):
|
|
with open(states_file, 'wt') as f:
|
|
f.write(json.dumps(new_states, indent=4))
|
|
if new_states == {}:
|
|
logger.info('states empty wrote')
|
|
return new_states
|
|
|
|
|
|
if not states_stor.states:
|
|
states_stor.states = read_states()
|