-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
148 lines (129 loc) · 4.16 KB
/
main.py
File metadata and controls
148 lines (129 loc) · 4.16 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import os
from dotenv import load_dotenv
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
load_dotenv()
# chat details
FROM_CHANNELS = set(int(x)
for x in os.environ.get("FROM_CHANNELS", "").split())
TO_CHATS = set(int(x) for x in os.environ.get("TO_CHATS", "").split())
# filters for auto post
FILTER_TEXT = bool(os.environ.get("FILTER_TEXT", True))
FILTER_AUDIO = bool(os.environ.get("FILTER_AUDIO", True))
FILTER_DOCUMENT = bool(os.environ.get("FILTER_DOCUMENT", True))
FILTER_PHOTO = bool(os.environ.get("FILTER_PHOTO", True))
FILTER_STICKER = bool(os.environ.get("FILTER_STICKER", True))
FILTER_VIDEO = bool(os.environ.get("FILTER_VIDEO", True))
FILTER_ANIMATION = bool(os.environ.get("FILTER_ANIMATION", True))
FILTER_VOICE = bool(os.environ.get("FILTER_VOICE", True))
FILTER_VIDEO_NOTE = bool(os.environ.get("FILTER_VIDEO_NOTE", True))
FILTER_CONTACT = bool(os.environ.get("FILTER_CONTACT", True))
FILTER_LOCATION = bool(os.environ.get("FILTER_LOCATION", True))
FILTER_VENUE = bool(os.environ.get("FILTER_VENUE", True))
FILTER_POLL = bool(os.environ.get("FILTER_POLL", True))
FILTER_GAME = bool(os.environ.get("FILTER_GAME", True))
# for copy
AS_COPY = bool(os.environ.get("AS_COPY", True))
REPLY_MARKUP = bool(os.environ.get("REPLY_MARKUP", False))
# bot informations
BOT_TOKEN = os.environ.get("BOT_TOKEN")
API_ID = int(os.environ.get("API_ID"))
API_HASH = os.environ.get("API_HASH")
Bot = Client(
"Channel Auto Post Bot",
bot_token=BOT_TOKEN,
api_id=API_ID,
api_hash=API_HASH
)
START_TEXT = """Hello {}, \
I am a channel auto post telegram bot.
Made by @FayasNoushad"""
BUTTONS = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
'Channel', url='https://telegram.me/FayasNoushad'),
InlineKeyboardButton(
'Feedback', url='https://telegram.me/TheFayas')
],
[
InlineKeyboardButton(
'Source Code', url='https://github.com/FayasNoushad/Channel-Auto-Post-Bot')
]
]
)
@Bot.on_message(filters.private & filters.command("start"))
async def start(_, message):
await message.reply_text(
text=START_TEXT.format(message.from_user.mention),
disable_web_page_preview=True,
reply_markup=BUTTONS
)
@Bot.on_message(
filters.channel & (
filters.text |
filters.audio |
filters.document |
filters.photo |
filters.sticker |
filters.video |
filters.animation |
filters.voice |
filters.video_note |
filters.contact |
filters.location |
filters.venue |
filters.poll |
filters.game
)
)
async def autopost(_, message):
if len(FROM_CHANNELS) == 0 or len(TO_CHATS) == 0 or message.chat.id not in FROM_CHANNELS:
return
if not (
(
message.text and FILTER_TEXT
) or (
message.audio and FILTER_AUDIO
) or (
message.document and FILTER_DOCUMENT
) or (
message.photo and FILTER_PHOTO
) or (
message.sticker and FILTER_STICKER
) or (
message.video and FILTER_VIDEO
) or (
message.animation and FILTER_ANIMATION
) or (
message.voice and FILTER_VOICE
) or (
message.video_note and FILTER_VIDEO_NOTE
) or (
message.contact and FILTER_CONTACT
) or (
message.location and FILTER_LOCATION
) or (
message.venue and FILTER_VENUE
) or (
message.poll and FILTER_POLL
) or (
message.game and FILTER_GAME
)
):
return
try:
for chat_id in TO_CHATS:
if AS_COPY:
if REPLY_MARKUP:
await message.copy(
chat_id=chat_id,
reply_markup=message.reply_markup
)
else:
await message.copy(chat_id=chat_id)
else:
await message.forward(chat_id=chat_id)
except Exception as error:
print(error)
Bot.run()