Skip to content

Instantly share code, notes, and snippets.

@Forevka
Last active September 22, 2018 18:56
Show Gist options
  • Save Forevka/89e82da4b0254babe6e40a1bfe366025 to your computer and use it in GitHub Desktop.
Save Forevka/89e82da4b0254babe6e40a1bfe366025 to your computer and use it in GitHub Desktop.
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
##FROM ONE CHANNEL - TO CHANNEL
#@Crypto_Deals2_bot
api_key = "515044302:AAFqNBYfIeiZERpvpN9sb59_IFIqnfnK4to"
bot = telebot.TeleBot(api_key)
#1200 символов
#pool_bot_id=129782279
client=None;
to_channel = "-1001313865586"#"@kanal_test_two"
def main():
global client
session_name = 'session'#environ.get('TG_SESSION', 'session')
user_phone = '++380982360604'#environ['TG_PHONE']
client = TelegramClient(session_name,
247218,#int(environ['TG_API_ID']),
'88bf0296b37f76bf21a55ba047aaa28c',
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)
try:
bot.send_message(int(to_channel), update.message.message)
except Exception as e:
print(e)
return 0;
if __name__ == '__main__':
#bot.send_message(383492784, "here")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment