-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
105 lines (90 loc) · 4.2 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
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
# Copyright (C) 2021 - SLBotsOfficial
# This programme is a part of TRTECHGUIDE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging
import functools
from telethon import TelegramClient, events, Button
from decouple import config
logging.basicConfig(
format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s", level=logging.INFO
)
bottoken = None
# start the bot
print("Starting...")
apiid = 6
apihash = "eb06d4abfb49dc3eeb1aeb98ae0f581e"
try:
bottoken = config("BOT_TOKEN")
except:
print("Environment vars are missing!")
print("Bot is quiting...")
exit()
if bottoken != None:
try:
SLBotsOfficial = TelegramClient("bot", apiid, apihash).start(bot_token=bottoken)
except Exception as e:
print(f"ERROR!\n{str(e)}")
print("Bot is quiting...")
exit()
else:
print("Environment vars are missing! Kindly recheck.")
print("Bot is quiting...")
exit()
@SLBotsOfficial.on(events.NewMessage(pattern="^/start"))
async def start(event):
if event.is_private:
await event.reply("Heya, I'm **Advanced Anonymous Sender** Bot 👨💻\n\nClick on help to find out how to use me\n\n**@trtechguide**",
buttons=[[Button.inline("Help", data="help")],
[Button.url("Channel", url="https://t.me/SLBotsOfficial"), Button.url("Source", url="https://github.com/TR-TECH-GUIDE/AnonymousSenderBot")]])
return
if event.is_group:
await event.reply("Heya, I'm **Advanced Anonymous Sender** Bot 👨💻")
@SLBotsOfficial.on(events.callbackquery.CallbackQuery(data="help"))
async def _(event):
await event.edit("**Help 📖**\n\nUsing me you can anonymize the sender and add or change caption of a media file\n\n**Available Commands 🧐**\n\n- /send (reply to media): Anonymize the sender\n- /send (caption) (reply to media): Add or change the caption and anonymize the sender\n\n*⃣ This bot works on both groups and private, but only admins can use the bot in groups\n\n**@trtechguide**",
buttons=[[Button.inline("Back", data="start")]])
@SLBotsOfficial.on(events.callbackquery.CallbackQuery(data="start"))
async def _(event):
await event.edit("Heya, I'm **Advanced Anonymous Sender** Bot 👨💻\n\nClick on help to find out how to use me\n\n**@trtechguide**",
buttons=[[Button.inline("Help", data="help")],
[Button.url("Channel", url="https://t.me/SLBotsOfficial"), Button.url("Source", url="https://github.com/TR-TECH-GUIDE/AnonymousSenderBot")]])
@SLBotsOfficial.on(events.NewMessage(pattern="^/send ?(.*)"))
async def caption(event):
if event.is_private:
return
a = await event.client.get_permissions(event.chat_id, event.sender_id)
if a.is_admin:
try:
lel = await event.get_reply_message()
cap = event.pattern_match.group(1)
await SLBotsOfficial.send_file(event.chat.id, lel, caption=cap)
except Exception:
await event.reply("Reply to a media file 🥴")
return
if not a.is_admin:
await event.reply("Only admins can execute this command!")
@SLBotsOfficial.on(events.NewMessage(pattern="^/send ?(.*)"))
async def caption(event):
if event.is_group:
return
try:
lel = await event.get_reply_message()
cap = event.pattern_match.group(1)
await SLBotsOfficial.send_file(event.chat.id, lel, caption=cap)
except Exception:
await event.reply("Reply to a media file 🥴")
return
print("Bot has started!")
print("Do visit @trtechguide.")
SLBotsOfficial.run_until_disconnected()