Skip to content

Commit

Permalink
You can get an ID number (Telegram)
Browse files Browse the repository at this point in the history
  • Loading branch information
neluckoff committed Sep 24, 2022
1 parent 36f1f67 commit 650bd75
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/telegram_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
tg.set_image('C:/Users/user/Desktop/img.png')
tg.send_message(358984161)

# The second variation of sending a message
tg.send_message(user_id=358984161, message="Hi! I'm using social_spam package",
# The second option for sending a message with ID taken by phone number
user_id = tg.get_id_by_phone('79269019999')
tg.send_message(user_id=user_id, message="Hi! I'm using social_spam package",
image='C:/Users/user/Desktop/img.png')

# Start spamming by user list
Expand Down
30 changes: 30 additions & 0 deletions social_spam/telegram.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import json
import tempfile
import time

from pyrogram import Client
from random import randint
from pathlib import Path
from alive_progress import alive_bar
from pyrogram.types import InputPhoneContact


class Telegram:
Expand Down Expand Up @@ -219,3 +222,30 @@ def send_message(self,
self.user.send_photo(user_id, self.image, caption=self.message)
else:
self.user.send_message(user_id, self.message)

def get_id_by_phone(self, phone_num: str) -> int:
"""
Method for getting a user's ID by his number (adds this contact to you in telegram chats,
and then deletes it - it's better not to test on your contacts)
Args:
phone_num (str): phone number of interest
Return:
str: ID by number
"""
temp_contact_name = tempfile.NamedTemporaryFile().name.split('\\')[-1]
good_res = list()
self.user.import_contacts([InputPhoneContact(phone=phone_num, first_name=temp_contact_name)])
contacts = self.user.get_contacts()
for contact in contacts:
contact_data = json.loads(str(contact))
if contact_data['first_name'] == temp_contact_name:
good_res.append(contact_data)
self.user.delete_contacts(contact_data['id'])

try:
good_res = int(good_res[0]['id'])
except:
good_res = None

return good_res

0 comments on commit 650bd75

Please sign in to comment.