balance.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from Client import create_clients
  2. from settings import LTC_BOT_NAME
  3. from time import sleep
  4. import asyncio
  5. from Console import console
  6. async def for_one(client, BOT_NAME, send_money=False, proxy=None):
  7. if proxy:
  8. client.set_proxy(proxy)
  9. await client.start()
  10. dialog = None
  11. for dlg in await client.get_dialogs():
  12. if dlg.title == BOT_NAME:
  13. dialog = dlg
  14. if not dialog:
  15. return 0
  16. await client.send_message(BOT_NAME, '/balance')
  17. sleep(3)
  18. msgs = await client.get_messages(dialog, limit=1)
  19. cur = 0
  20. sleep(3)
  21. try:
  22. for mes in msgs:
  23. str_a = str(mes.message)
  24. zz = str_a.replace('Available balance: ', '')
  25. qq = zz.replace(' LTC', '')
  26. console.send_notification(str(client.phone_number) + ' - ' + qq)
  27. cur = float(qq)
  28. if send_money and cur > 0.0001:
  29. await client.send_message(BOT_NAME, '/withdraw')
  30. sleep(2)
  31. await client.send_message(BOT_NAME, client.wallet)
  32. sleep(1)
  33. console.send_alert("Sending {} LTC from {} to {} wallet".format(cur, client.phone_number, client.wallet))
  34. await client.send_message(BOT_NAME, str(cur))
  35. sleep(1)
  36. await client.send_message(BOT_NAME, "✔️ Confirm")
  37. cur = 0
  38. except Exception as e:
  39. console.send_critical("Error occurred: {}".format(e))
  40. cur = 0
  41. await client.disconnect()
  42. return cur
  43. async def send_total_balance(client, total):
  44. await client.connect()
  45. await client.notify_admins("Total LTC: {}".format(total))
  46. await client.disconnect()
  47. async def check_balance():
  48. clients = create_clients()
  49. total = 0
  50. for i in range(len(clients)):
  51. cur = await for_one(clients[i], BOT_NAME=LTC_BOT_NAME)
  52. total += cur
  53. sleep(1)
  54. await send_total_balance(clients[0], "Total LTC: {}".format(total))
  55. console.send_notification("Total: {}".format(total))
  56. if __name__ == '__main__':
  57. asyncio.run(check_balance())