Skip to content

Instantly share code, notes, and snippets.

@Kylmakalle
Last active September 14, 2017 14:48
Show Gist options
  • Save Kylmakalle/59daa23c5a97c0bdcc1fc9cae6c1e94d to your computer and use it in GitHub Desktop.
Save Kylmakalle/59daa23c5a97c0bdcc1fc9cae6c1e94d to your computer and use it in GitHub Desktop.
Backup Group Butler's chat settings
api_id = 111337 # my.telegram.org
api_hash = 'blblbla12317823123789127809'
phone_number = '+79991488228'
from telethon import TelegramClient
import sys
import time
from telethon.tl.functions.channels import DeleteMessagesRequest
from telethon.tl.functions.messages import SendMessageRequest
from telethon.tl.types import MessageEntityItalic
from telethon.utils import get_input_peer
from credentials import api_id, api_hash, phone_number
try:
client = TelegramClient('gbbackup', api_id, api_hash) # feel free to edit %sessionname% as you want
client.connect() # logining and connecting to Telegram servers
except:
sys.exit("Cant't connect, check connection parameters!")
if not client.is_user_authorized(): # authorization (if there is no .session file created before)
client.send_code_request(phone_number)
client.sign_in(phone_number, input('Enter the code: '))
dialogs, entities = client.get_dialogs(25)
gbb = 261244309
text = 'Автобэкап выполнен'
def is_mobi_hw(chat):
if 'title' in dir(chat) and 'username' in dir(chat) and (
chat.username == 'ru2chmobi' or chat.username == 'ru2chhw'):
return True
else:
return False
for i in range(len(entities)):
if is_mobi_hw(entities[i]):
client.send_message(entities[i], '!snap')
time.sleep(1)
for i in range(len(entities)):
if is_mobi_hw(entities[i]):
for message in client.get_message_history(entities[i], limit=5)[1]:
if 'message' in dir(message):
if (message.from_id == gbb and message.message == 'Sent in private') \
or message.message == '!snap':
client.invoke(DeleteMessagesRequest(entities[i], [message.id]))
client.invoke(SendMessageRequest(
peer=get_input_peer(entities[i]),
message=text,
entities=[MessageEntityItalic(0, len(text))],
no_webpage=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment