Client.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import time
  2. import socks
  3. from telethon import TelegramClient
  4. from database import get_all_data
  5. from socks import SOCKS4
  6. from settings import ADMINS
  7. import asyncio
  8. # SESSION, API_ID, API_HASH
  9. class Client(TelegramClient):
  10. def __init__(self, session, api_id, api_hash, is_active, user_id, wallet, phone_number=None):
  11. super().__init__(session, api_id, api_hash)
  12. self.id = user_id
  13. self.wallet = wallet
  14. self.is_active = bool(is_active)
  15. self.phone_number = phone_number
  16. @staticmethod
  17. def get_url_from_button(message):
  18. return message.reply_markup.rows[0].buttons[0].url
  19. async def notify_admins(self, message):
  20. for admin in ADMINS:
  21. await self.send_message(admin, message)
  22. async def find_dialog(self, dialog_title):
  23. dialogs = await self.get_dialogs()
  24. for dlg in dialogs:
  25. if dlg.title == dialog_title:
  26. return dlg
  27. return None
  28. def create_clients():
  29. res = []
  30. for el in get_all_data():
  31. session = el[0]
  32. api_id = el[1]
  33. api_hash = el[2]
  34. is_active = el[3]
  35. wallet = el[4]
  36. user_id = el[5]
  37. phone_number = el[6]
  38. if is_active == 1:
  39. res.append(Client(session=session, api_id=api_id, api_hash=api_hash, is_active=is_active, wallet=wallet, user_id= user_id, phone_number=phone_number))
  40. return res
  41. async def process():
  42. cl = create_clients()
  43. print(len(cl))
  44. for el in cl:
  45. await el.start()
  46. time.sleep(0.2)
  47. #await el.send_message("BCH_clickbot ", "/start")
  48. await el.disconnect()
  49. time.sleep(0.2)
  50. if __name__ == '__main__':
  51. asyncio.run(process())