balance.py 2.1 KB

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