-
Notifications
You must be signed in to change notification settings - Fork 1
/
protecc.py
151 lines (138 loc) · 5.33 KB
/
protecc.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
import asyncio
import os
import datetime
import lottie
import urllib
import requests
from asyncio import sleep
from bs4 import BeautifulSoup
from d3vilbot.sql.waifu_sql import is_harem, add_grp, rm_grp, get_all_grp
from . import *
qt = "A qt waifu appeared!"
def progress(current, total):
logger.info(
"Downloaded {} of {}\nCompleted {}".format(
current, total, (current / total) * 100
)
)
@bot.on(d3vil_cmd(pattern="pt ?(.*)"))
@bot.on(sudo_cmd(pattern="pt ?(.*)", allow_sudo=True))
async def _(event):
if event.fwd_from:
return
d3vil = await eor(event, "Hmm..")
BASE_URL = "http://images.google.com"
if event.reply_to_msg_id:
previous_message = await event.get_reply_message()
previous_message_text = previous_message.message
if previous_message.media:
downloaded_file_name = await bot.download_media(
previous_message, Config.TMP_DOWNLOAD_DIRECTORY
)
SEARCH_URL = "{}/searchbyimage/upload".format(BASE_URL)
multipart = {
"encoded_image": (
downloaded_file_name,
open(downloaded_file_name, "rb"),
),
"image_content": "",
}
google_rs_response = requests.post(
SEARCH_URL, files=multipart, allow_redirects=False
)
the_location = google_rs_response.headers.get("Location")
os.remove(downloaded_file_name)
else:
previous_message_text = previous_message.message
SEARCH_URL = "{}/searchbyimage?image_url={}"
request_url = SEARCH_URL.format(BASE_URL, previous_message_text)
google_rs_response = requests.get(request_url, allow_redirects=False)
the_location = google_rs_response.headers.get("Location")
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0"
}
response = requests.get(the_location, headers=headers)
soup = BeautifulSoup(response.text, "html.parser")
prs_div = soup.find_all("div", {"class": "r5a77d"})[0]
prs_anchor_element = prs_div.find("a")
prs_url = BASE_URL + prs_anchor_element.get("href")
prs_text = prs_anchor_element.text
img_size_div = soup.find(id="jHnbRc")
img_size = img_size_div.find_all("div")
OUTPUT_STR = """/protecc {prs_text}""".format(
**locals())
await d3vil.edit(OUTPUT_STR, parse_mode="HTML", link_preview=False)
@bot.on(events.NewMessage(incoming=True))
async def _(event):
if not event.media:
return
if not qt in event.text:
return
if not event.sender_id == 792028928:
return
if Config.WAIFU_CATCHER != "TRUE":
return
all_grp = get_all_grp()
if len(all_grp) == 0:
return
for grps in all_grp:
try:
dl = await bot.download_media(event.media, "resources/")
file = {"encoded_image": (dl, open(dl, "rb"))}
grs = requests.post(
"https://www.google.com/searchbyimage/upload", files=file, allow_redirects=False
)
loc = grs.headers.get("Location")
response = requests.get(
loc,
headers={
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0"
},
)
qtt = BeautifulSoup(response.text, "html.parser")
div = qtt.find_all("div", {"class": "r5a77d"})[0]
alls = div.find("a")
text = alls.text
try:
if "cg" in text:
return
if "fictional character" in text:
return
except:
pass
if int(grps.chat_id) == event.chat_id:
hell = await bot.send_message(event.chat_id, f"/protecc@loli_harem_bot {text}")
await sleep(2)
await hell.delete()
os.remove(dl)
except:
return
@bot.on(d3vil_cmd(pattern="adwaifu ?(.*)"))
@bot.on(sudo_cmd(pattern="adwaifu ?(.*)", allow_sudo=True))
async def _(event):
if not event.is_group:
await eod(event, "Autowaifu works in Groups Only !!")
return
if is_harem(str(event.chat_id)):
await eod(event, "This Chat is Has Already In AutoWaifu Database !!")
return
add_grp(str(event.chat_id))
await eod(event, f"**Added Chat** {event.chat.title} **With Id** `{event.chat_id}` **To Autowaifu Database.**")
@bot.on(d3vil_cmd(pattern="rmwaifu ?(.*)"))
@bot.on(sudo_cmd(pattern="rmwaifu ?(.*)", allow_sudo=True))
async def _(event):
if not event.is_group:
await eod(event, "Autowaifu works in groups only !!")
return
if not is_harem(str(event.chat_id)):
await eod(event, "Autowaifu was already disabled here.")
return
rm_grp(str(event.chat_id))
await eod(event, f"**Removed Chat** {event.chat.title} **With Id** `{event.chat_id}` **From AutoWaifu Database.**")
CmdHelp("protecc").add_command(
"pt", "<reply>", "Auto Protecc the waifu."
).add_command(
"adwaifu", None, "Adds the current group to AutoWaifu Database. Need to setup WAIFU_CATCHER var with value TRUE."
).add_command(
"rmwaifu", None, "Removes the group from AutoWaifu Database."
).add()