-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetting_storage.py
48 lines (39 loc) · 1.43 KB
/
setting_storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from settings import Settings
from settings import Type
import pickle
import os
settings_dict = {}
target_settings_dict = {}
def settings_from_user_id(user) -> Settings:
if (user.id not in settings_dict):
settings_dict[user.id] = Settings()
settings_dict[user.id].name = user.name
return settings_dict[user.id]
def target_settings_from_user_id(user) -> Settings:
if (user.id not in target_settings_dict):
target_settings_dict[user.id] = Settings()
target_settings_dict[user.id].name = user.name
return target_settings_dict[user.id]
def find_settings_from_name(name) -> Settings:
for settings in settings_dict.values():
if settings.name.lower() == name.lower():
return settings
return None
def get_users_count():
return len(settings_dict.keys())
def get_helpless_users_count():
return len([item for item in settings_dict.values() if item.helpless])
async def save_settings():
output = open('settings.pkl', 'wb')
pickle.dump((settings_dict, target_settings_dict), output)
output.close()
def load_settings():
global settings_dict
global target_settings_dict
if (os.path.isfile('settings.pkl')):
input = open('settings.pkl', 'rb')
(settings_dict, target_settings_dict) = pickle.load(input)
input.close()
else:
settings_dict = {}
target_settings_dict = {}