forked from Ayush7445/telegram-forwarder_auto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
52 lines (44 loc) · 1.6 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright (c) 2021 Ayush
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# License can be found in < https://github.com/Ayush7445/telegram-auto_forwarder/blob/main/License > .
from telethon import TelegramClient, events
from decouple import config
import logging
from telethon.sessions import StringSession
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', level=logging.WARNING)
print("Starting...")
# Basics
APP_ID = config("APP_ID", default=None, cast=int)
API_HASH = config("API_HASH", default=None)
SESSION = config("SESSION")
FROM_ = config("FROM_CHANNEL")
TO_ = config("TO_CHANNEL")
FROM = [int(i) for i in FROM_.split()]
TO = [int(i) for i in TO_.split()]
try:
BotzHubUser = TelegramClient(StringSession(SESSION), APP_ID, API_HASH)
BotzHubUser.start()
except Exception as ap:
print(f"ERROR - {ap}")
exit(1)
@BotzHubUser.on(events.NewMessage(incoming=True, chats=FROM))
async def sender_bH(event):
for i in TO:
try:
await BotzHubUser.send_message(
i,
event.message
)
except Exception as e:
print(e)
print("Bot has started.")
BotzHubUser.run_until_disconnected()