sender(id, 'Баланс\n\nНаличные: {}\nАлмазы: {}'.format(money, ruby), balance)
NameError: name 'money' is not defined
class User():
def __init__(self, id, money, ruby, ruderalis, vip):
self.id = id
self.money = money
self.ruby = ruby
self.ruderalis = ruderalis
self.vip = vip
def save_bd(users):
lines = []
for user in users:
lines.append(f'"id" : {user.id}, "money" : {user.money}, "ruby" : {user.ruby}, "ruderalis" : {user.ruderalis}, "vip" : {user.vip}')
lines = '\n'.join(lines)
with open(f'{tdir(__file__)}/data.txt'.replace('\\', '/').replace('main.py/', ''), 'w', encoding = 'utf-8') as file:
file.write(lines)
file.close()
def read_bd():
users = []
with open(f'{tdir(__file__)}/data.txt'.replace('\\', '/').replace('main.py/', ''), 'r', encoding = 'utf-8') as file:
lines = [x.replace('\n', '') for x in file.readlines()]
file.close()
for line in lines:
line = eval('{' + line + '}')
if line != '{}':
users.append(User(id = line['id'], money = line['money'], ruby = line['ruby'], ruderalis = line['ruderalis'], vip = line['vip']))
return users
users = read_bd()
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
id = event.user_id
msg = event.text.lower()
elif msg.find('баланс') != -1:
sender(id, f'Баланс\n\nНаличные: {money}\nАлмазы: {ruby}', balance)