-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.py
351 lines (244 loc) Β· 11 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# Repo -> https://github.com/NoOneLuvMe/theimagebot
# Dev -> t.me/no_one_luv_me
# channel -> https://t.me/theostrich
# support -> https://t.me/ostrichdiscussion
import requests
import pytesseract
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from PIL import ImageFilter
from telegram.ext import Updater, CommandHandler
import carbonsh
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
TOKEN = os.getenv("TOKEN")
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
def imagetotext(update, context):
context.bot.get_file(update.message.reply_to_message.photo[-1]).download(custom_path="./PicToImage/PictoText.jpg")
username = update.message.chat.username
print("started By : ", username)
messa = '''<b>
Please Wait For Few Minutes π§ββοΈ
Generating π§ Text From The Image π
Please Don't Spam π₯Ί
</b>'''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=messa, parse_mode='html')
pytesseract.pytesseract.tesseract_cmd = "/app/.apt/usr/bin/tesseract"
# Method to process the blue band
def pixelProcBlue(intensity):
return intensity
imageObject = Image.open('PicToImage/PictoText.jpg')
multiBands = imageObject.split()
blueBand = multiBands[2].point(pixelProcBlue)
image_to_text = pytesseract.image_to_string(blueBand, lang='eng')
image_to_text += '''
Text from Image By @theimagebot β€
'''
context.bot.send_message(chat_id=update.effective_chat.id, text=image_to_text)
imagetotext_handeler = CommandHandler('imagetotext', imagetotext)
dispatcher.add_handler(imagetotext_handeler)
def addwatermark(update, context):
text_watermark_from_user = context.args
username = update.message.chat.username
print("addwatermark By : ", username)
watermark_text = str(text_watermark_from_user).split(":")[0].strip().replace("'", "").replace(",", "").replace("[",
"").replace(
"]", "")
size_ = int(
str(text_watermark_from_user).split(":")[1].strip().replace("'", "").replace(",", "").replace("[", "").replace(
"]", ""))
if size_ < 100:
context.bot.get_file(update.message.reply_to_message.photo[-1]).download(
custom_path="./Watermark/@theimagebot.png")
messa = '''<b>
Please Wait For Few Seconds π§ββοΈ
Adding Watermark π to the image Image π
Please Don't Spam π₯Ί
</b>'''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=messa, parse_mode='html')
photo = Image.open("./Watermark/@theimagebot.png")
# make the image editable
width, height = photo.size
draw = ImageDraw.Draw(photo)
text = watermark_text
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf', int(size_))
textwidth, textheight = draw.textsize(text, font)
# calculate the x,y coordinates of the text
margin = 5
x = width - textwidth - margin
y = height - textheight - margin
# draw watermark in the bottom right corner
draw.text((x, y), text, font=font)
photo.save('./Watermark/@theimagebot.png')
caption = "<b>Watermark Added By <a herf=\"http://t.me/theimagebot\">@theimagebot</a></b>β€οΈ"
context.bot.send_document(chat_id=update.effective_chat.id,
document=open('./Watermark/@theimagebot.png', 'rb'),
caption=caption, parse_mode="html")
else:
messa = '''
*Size Must Be < 100 π
Use /help If U don't Know How to Use Me*
'''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=messa, parse_mode='markdown')
addwatermark_handeler = CommandHandler('addwatermark', addwatermark)
dispatcher.add_handler(addwatermark_handeler)
def blur(update, context):
username = update.message.chat.username
print("Blured By : ", username)
context.bot.get_file(update.message.reply_to_message.photo[-1]).download(
custom_path="./Editing/@theimagebot.png")
blur_radious = int(context.args[0])
if blur_radious < 100:
messa = '''<b>
Please Wait For Few Seconds π§ββοΈ
Start Bluring π§ββοΈ the image Image π
Please Don't Spam π₯Ί
</b>'''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=messa, parse_mode='html')
Photo = Image.open("./Editing/@theimagebot.png")
photo = Photo.filter(ImageFilter.GaussianBlur(radius=blur_radious))
photo.save('./Editing/@theimagebot.png')
caption = "<b>Blured By <a herf=\"http://t.me/theimagebot\">@theimagebot</a></b> β€οΈ"
context.bot.send_document(chat_id=update.effective_chat.id,
document=open('./Editing/@theimagebot.png', 'rb'),
caption=caption, parse_mode="html")
else:
messa = '''
*Blur Value Must Be < 100 π
Use /help If U don't Know How to Use Me* '''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=messa, parse_mode='markdown')
blur_handeler = CommandHandler('blur', blur)
dispatcher.add_handler(blur_handeler)
def reverse(update, context):
username = update.message.chat.username
print("Reverse By : ", username)
context.bot.get_file(update.message.reply_to_message.photo[-1]).download(
custom_path="./Reverse/@theimagebot.png")
messa = '''<b>
Please Wait For Few Seconds π§ββοΈ
Reversing π the image
Please Don't Spam π₯Ί
</b>'''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=messa, parse_mode='html')
filePath = "./Reverse/@theimagebot.png"
searchUrl = 'http://www.google.hr/searchbyimage/upload'
multipart = {'encoded_image': (filePath, open(filePath, 'rb')), 'image_content': ''}
response = requests.post(searchUrl, files=multipart, allow_redirects=False)
fetchUrl = response.headers['Location']
link = f'''
<b>Your Search Result π </b>
{fetchUrl}
<b>Reversed ByοΈ
<a herf=\"http://t.me/theimagebot\">@theimagebot</a></b> β€
'''
context.bot.send_message(chat_id=update.effective_chat.id, text=link, parse_mode='html')
reverse_handeler = CommandHandler('reverse', reverse)
dispatcher.add_handler(reverse_handeler)
def start(update, context):
username = update.message.chat.username
print("started By : ", username)
welcome = f'''
<b>Hey @{username} π
I'm <a herf=\"http://t.me/theimagebot\">@theimagebot</a>
I'm a Open Source Bot
/source_code to Get Repo Link π
I Can Do Many Things
π« β I Can Carbonized A Code
π« β I Can Extract Text From An Image
π« β I Can Reverse Search An Image
π« β I Can Add Watermark to An Image
π« β I Can Blur A Image
Hit /help If You Don't Know How to Use Me
Developer : <a href=\"t.me/no_one_luv_me\"> ΰ·΄ δΉ(β§β½β¦) δΉ ΰ·΄ </a>π§βπ»
Support Group : <a href=\"https://t.me/ostrichdiscussion\">Ostrich Discussion</a> π¦ΈββοΈ
Made By <a href=\"https://t.me/theostrich\"> Ostrich </a> β€οΈ
</b>
'''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=welcome, parse_mode='html',
disable_web_page_preview=True)
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
def help(update, context):
help_ = '''
*You Don't Know How to Use Me ? ok
To Get text from that image πββοΈ
replay to an image with /imagetotext
To Reverse search a image π
replay to an image with /reverse
To Carbonized a Code π±
replay to a Message with /carbon
To Add watermark to an image ποΈββ
οΈ
replay to an image with /addwatermark {text to be watermark}:{watermark size}
example: /addwatermark @ostrichdiscussion:30
To Blur A Image π΅ββοΈ
replay to an image with /blur {blur value}
example: /blur 40
I'm a Open Source Bot
/source_code to Get Repo Link π
*
'''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=help_, parse_mode='markdown')
def carbon(update, context):
username = update.message.chat.username
print("Carbon By : ", username)
messa = '''<b>
Please Wait For Few Seconds π§ββοΈ
Carbonizing πΏ the Your Code π¨βπ»
Please Don't Spam π₯Ί
</b>'''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=messa, parse_mode='html')
code = update.message.reply_to_message.text
config = carbonsh.Config(language=carbonsh.languages.AUTO)
# returns >>> 'https://carbon.now.sh/?bg=rgba(...'
carbon_url = carbonsh.code_to_url(code, config)
options = webdriver.ChromeOptions()
prefs = {
"download.default_directory": "./Carbon/",
"download.prompt_for_download": False,
"download.directory_upgrade": True
}
options.add_experimental_option('prefs', prefs)
options.add_argument("--window-size=1920,1080")
options.add_argument("--start-maximized")
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), chrome_options=options)
driver.get(carbon_url)
import time
time.sleep(5)
button = driver.find_element_by_xpath("//button[@class='jsx-1730877631 ']")
button.click()
time.sleep(5)
caption = "<b>Carbonized By <a herf=\"http://t.me/theimagebot\">@theimagebot</a></b>β€οΈ"
context.bot.send_document(chat_id=update.effective_chat.id,
document=open('./Carbon/carbon.png', 'rb'),
caption=caption, parse_mode="html")
driver.close()
carbon_handeler = CommandHandler('carbon', carbon)
dispatcher.add_handler(carbon_handeler)
help_handler = CommandHandler('help', help)
dispatcher.add_handler(help_handler)
def source_code(update, context):
username = update.message.chat.username
print("Source : ", username)
source = '''
Developer : <a href=\"t.me/no_one_luv_me\"> ΰ·΄ δΉ(β§β½β¦) δΉ ΰ·΄ </a>π§βπ»
Repository Link : https://github.com/NoOneLuvMe/theimagebot
<b>Give a π if you liked the repo β€οΈ</b>
Support Group : <a href=\"https://t.me/ostrichdiscussion\">Ostrich Discussion</a> π¦ΈββοΈ
Made By <a href=\"https://t.me/theostrich\"> Ostrich </a> β€οΈ
'''
update.message.reply_text(reply_to_message_id=update.message.message_id, text=source, parse_mode='html',
disable_web_page_preview=True)
source_code_handeler = CommandHandler('source_code', source_code)
dispatcher.add_handler(source_code_handeler)
updater.start_polling()
# Dev -> t.me/no_one_luv_me
# channel -> https://t.me/theostrich
# support -> https://t.me/ostrichdiscussion