added file

This commit is contained in:
Godnessli committed 2026-10-18 15:44:55 +03:00
1 parent cc433bd065
commit c07cd997c9
10 files changed
+754 -1

No files matched your search

+84
View File
@@ -0,0 +1,84 @@
import time
import json
class Person:
__ACCOUNTS_FILE = "accounts.json"
__DOMAIN = "godnessli.ru"
def __init__(self, account: str, admin = False):
if self.__check_person(account):
self.__read_person(account)
else:
self.__create_person(account, admin)
def get_account(self) -> str:
return self.__account
def get_unknown_answers(self) -> int:
return self.__unknown_count
def clear_answers(self):
self.__unknown_count = 0
def incr_account(self):
self.__unknown_count += 1
def __check_person(self, account: str) -> bool:
accounts = None
try:
accounts = self.__get_accounts()
except FileNotFoundError:
return False
for acc in accounts:
if acc == account:
return True
return False
def __read_person(self, account: str):
accounts = self.__get_accounts()
acc = accounts[account]
self.__nick_name = acc["nick"]
self.__admin = acc["admin"]
self.__unknown_counter = acc["u_count"]
self.__whether_counter = acc["w_count"]
self.__ideas = acc["ideas"]
def __create_person(self, account: str, admin: bool):
accounts = None
try:
accounts = self.__get_accounts()
except FileNotFoundError:
pass
with open(self.__ACCOUNTS_FILE, 'w', encoding = 'utf-8') as p_file:
begin = account.find("@")
end = account.find(self.__DOMAIN)
accounts[account] = {
"nick" : account[begin:end],
"admin" : admin,
"u_count" : 0,
"w_count" : 0,
"ideas" : []
}
p_file.write(accounts)
acc = accounts[account]
self.__nick = acc["nick"]
self.__admin = acc["admin"]
self.__unknown_counter = acc["u_count"]
self.__whether_counter = acc["w_count"]
self.__ideas = acc["ideas"]
def __get_accounts(self) -> dict:
with open(self.__ACCOUNTS_FILE, 'r', encoding = 'utf-8') as p_file:
accounts = json.load(p_file)
p_file.close()
return accounts
tema = Person("@tema:godnessli")