main.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import time
  2. import re
  3. from settings import LTC_BOT_NAME, AD_MESSAGE, MAX_FAILURES, ACTIVATE_SENDING_MESSAGE, DELAY_BETWEEN_SESSIONS, \
  4. STANDART_DELAY
  5. from Console import console
  6. from Client import create_clients
  7. from proxy import Proxy_controller, get_all_proxys
  8. from automatization import add_clicking, send_to_bots, add_to_the_group, leave_all_old_groups, begin
  9. import asyncio
  10. from telethon.tl.functions.channels import JoinChannelRequest, LeaveChannelRequest
  11. from random import randint
  12. from balance import check_balance
  13. async def work_with_one(client, Proxy = None, BOT_NAME=LTC_BOT_NAME):
  14. if Proxy:
  15. client.set_proxy(Proxy.telethon_proxy())
  16. http_prx = Proxy.selenium_proxy() if Proxy else None
  17. if http_prx:
  18. console.send_notification("Using http proxy: {}".format(http_prx))
  19. await client.start()
  20. dialogs = await client.get_dialogs()
  21. bot_chat = None
  22. for dlg in dialogs:
  23. if dlg.title == BOT_NAME:
  24. bot_chat = dlg
  25. if not bot_chat:
  26. console.send_alert("No chat was found for {}, finishing for account {}".format(BOT_NAME, client.api_id))
  27. client.disconnect()
  28. return
  29. await begin(client, BOT_NAME)
  30. console.send_notification("Leaving old channels")
  31. await leave_all_old_groups(client)
  32. console.send_notification("Working with adds")
  33. await add_clicking(client, bot_chat, BOT_NAME, http_prx)
  34. console.send_notification("Working with bots")
  35. await send_to_bots(client, bot_chat, BOT_NAME, http_prx)
  36. console.send_notification("Working with channels and groups")
  37. await add_to_the_group(client, bot_chat, BOT_NAME, http_prx)
  38. await client.disconnect()
  39. async def main_process():
  40. pos = 0
  41. clients = create_clients()
  42. console.debug("Working with {} accounts".format(len(clients)))
  43. if len(clients) == 0:
  44. console.send_critical("Add accounts first")
  45. raise IndexError
  46. end = len(clients)
  47. Controller = Proxy_controller(get_all_proxys())
  48. while True:
  49. client = clients[pos]
  50. end = len(clients)
  51. await work_with_one(client, Proxy=Controller.get_proxy())
  52. # after exiting from previous account:
  53. pos += 1
  54. if pos == end:
  55. pos = 0
  56. delay = randint(DELAY_BETWEEN_SESSIONS[0], DELAY_BETWEEN_SESSIONS[1])
  57. console.send_notification("Sleeping for {} minutes".format(delay))
  58. await check_balance()
  59. time.sleep(delay * 60)
  60. console.send_notification("Switching to next account")
  61. if __name__ == '__main__':
  62. while True:
  63. try:
  64. asyncio.run(main_process())
  65. except IndexError:
  66. break
  67. except Exception as e:
  68. console.send_critical("Error occured in main process: {}".format(e))