Created
March 27, 2018 20:57
-
-
Save Forevka/6e58a511ddf039caba1e3daf1c4f3c37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from getpass import getpass | |
import sys, traceback, time, telebot,random | |
import wget, os | |
from telebot import types | |
from telethon.tl.types import UpdateShortMessage, PeerUser, PeerChannel, UpdateNewChannelMessage | |
from telethon.tl.functions.channels import * | |
import threading | |
from telethon.tl.types import InputPeerChat | |
from telethon import TelegramClient | |
from telethon.errors import SessionPasswordNeededError | |
from telethon.tl.functions.messages import SetBotCallbackAnswerRequest | |
from telethon.tl.functions.messages import GetBotCallbackAnswerRequest | |
from telethon.tl.functions.messages import SendInlineBotResultRequest | |
from telethon.tl.functions.messages import GetInlineBotResultsRequest | |
api_key = "549402493:AAHdf89nPRvnFCVFE3ecKE1artnaq1hzyGk" | |
bot = telebot.TeleBot(api_key) | |
#1200 символов | |
#pool_bot_id=129782279 | |
client=None; | |
to_channel = "@kanal_test_two" | |
def main(): | |
global client | |
session_name = 'session'#environ.get('TG_SESSION', 'session') | |
user_phone = '+380666123545'#environ['TG_PHONE'] | |
client = TelegramClient(session_name, | |
187706,#int(environ['TG_API_ID']), | |
'a1c5bae7b04067f397f4f96400be8718', | |
update_workers=4) | |
print('INFO: Connecting to Telegram Servers...', end='', flush=True) | |
err=client.connect() | |
print(err) | |
print('Done!') | |
if not client.is_user_authorized(): | |
print('INFO: Unauthorized user') | |
client.send_code_request(user_phone) | |
code_ok = False | |
while not code_ok: | |
code = input('Enter the auth code: ') | |
try: | |
code_ok = client.sign_in(user_phone, code) | |
except SessionPasswordNeededError: | |
password = getpass('Two step verification enabled. Please enter your password: ') | |
code_ok = client.sign_in(password=password) | |
print('INFO: Client initialized succesfully!') | |
client.add_update_handler(update_handler) | |
input('Press Enter to stop this!\n') | |
def update_handler(update): | |
#print(client) | |
global client | |
#print(update.stringify()) | |
#print('Press Enter to stop this!') | |
#if update.message=="Отправляй": | |
# client.send_message("@QuanBot", "hi") | |
#print(update) | |
#print(update.message.message) | |
#print(update.message.to_id.channel_id) | |
#print(client.get_entity(to_channel).id) | |
if isinstance(update, UpdateNewChannelMessage) and int(update.message.to_id.channel_id)!=int(client.get_entity(to_channel).id): | |
print("New from channel") | |
#print(update.stringify()) | |
print(update.message.message) | |
bot.send_message(to_channel, update.message.message) | |
return 0; | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment