-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.py
135 lines (116 loc) · 4.92 KB
/
main.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
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
# © BugHunterCodeLabs ™
# © bughunter0
# 2021
# Copyright - https://en.m.wikipedia.org/wiki/Fair_use
import os , glob
from os import error
import logging
import pyrogram
import time
import math
from decouple import config
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.types import User, Message, Sticker, Document
bughunter0 = Client(
"Sticker-Bot",
bot_token = os.environ["BOT_TOKEN"],
api_id = int(os.environ["API_ID"]),
api_hash = os.environ["API_HASH"]
)
START_STRING = """ Hi {}, I'm Sticker Bot.
I can Provide all Kind of Sticker Options Here """
JOIN_BUTTON = InlineKeyboardMarkup(
[[
InlineKeyboardButton('↗ Join Here ↗', url='https://t.me/BughunterBots')
]]
)
DOWNLOAD_LOCATION = os.environ.get("DOWNLOAD_LOCATION", "./DOWNLOADS/")
@bughunter0.on_message(filters.command(["start"]))
async def start(bot, update):
text = START_STRING.format(update.from_user.mention)
reply_markup = JOIN_BUTTON
await update.reply_text(
text=text,
disable_web_page_preview=True,
reply_markup=reply_markup,
quote=True
)
@bughunter0.on_message(filters.command(["ping"]))
async def ping(bot, message):
start_t = time.time()
rm = await message.reply_text("Checking")
end_t = time.time()
time_taken_s = (end_t - start_t) * 1000
await rm.edit(f"Pong!\n{time_taken_s:.3f} ms")
@bughunter0.on_message(filters.private & filters.command(["getsticker"]))
async def getstickerasfile(bot, message):
tx = await message.reply_text("Checking Sticker")
await tx.edit("Validating sticker..")
if message.reply_to_message.sticker is False:
await tx.edit("Not a Sticker File!!")
else :
if message.reply_to_message is None:
tx = await tx.edit("Reply to a Sticker File!")
else :
if message.reply_to_message.sticker.is_animated:
try :
tx = await message.reply_text("Downloading...")
file_path = DOWNLOAD_LOCATION + f"{message.chat.id}.tgs"
await message.reply_to_message.download(file_path)
await tx.edit("Downloaded")
# zip_path= ZipFile.write("")
await tx.edit("Uploading...")
start = time.time()
await message.reply_document(file_path,caption="©@BugHunterBots")
await tx.delete()
os.remove(file_path)
# os.remove(zip_path)
except Exception as error:
print(error)
elif message.reply_to_message.sticker.is_animated is False:
try :
tx = await message.reply_text("Downloading...")
file_path = DOWNLOAD_LOCATION + f"{message.chat.id}.png"
await message.reply_to_message.download(file_path)
await tx.edit("Downloaded")
await tx.edit("Uploading...")
start = time.time()
await message.reply_document(file_path,caption="©@BugHunterBots")
await tx.delete()
os.remove(file_path)
except Exception as error:
print(error)
@bughunter0.on_message(filters.private & filters.command(["clearcache"]))
async def clearcache(bot, message):
# Found some Files showing error while Uploading, So a method to Remove it !!
txt = await message.reply_text("Checking Cache")
await txt.edit("Clearing cache")
dir = DOWNLOAD_LOCATION
filelist = glob.glob(os.path.join(dir, "*"))
for f in filelist :
i =1
os.remove(f)
i=i+1
await txt.edit("Cleared "+ str(i) + "File")
await txt.delete()
@bughunter0.on_message(filters.command(["stickerid"]))
async def stickerid(bot, message):
if message.reply_to_message.sticker:
await message.reply(f"**Sticker ID is** \n `{message.reply_to_message.sticker.file_id}` \n \n ** Unique ID is ** \n\n`{message.reply_to_message.sticker.file_unique_id}`", quote=True)
else:
await message.reply("Oops !! Not a sticker file")
@bughunter0.on_message(filters.private & filters.command(["findsticker"]))
async def findsticker(bot, message):
try:
if message.reply_to_message:
txt = await message.reply_text("Validating Sticker ID")
stickerid = str(message.reply_to_message.text)
chat_id = str(message.chat.id)
await txt.delete()
await bot.send_sticker(chat_id,f"{stickerid}")
else:
await message.reply_text("Please reply to a ID to get its STICKER.")
except Exception as error:
txt = await message.reply_text("Not a Valid File ID")
bughunter0.run()