-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFile Uploader.py
167 lines (145 loc) · 5.27 KB
/
File Uploader.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
# ---------------------------------------------------------------------------------
# /\_/\ 🌐 This module was loaded through https://t.me/hikkamods_bot
# ( o.o ) 🔓 Not licensed.
# > ^ < ⚠️ Owner of heta.hikariatama.ru doesn't take any responsibilities or intellectual property rights regarding this script
# ---------------------------------------------------------------------------------
# Name: file_uploader
# Description: Uploader
# Author: GeekTG
# Commands:
# .x0 | .telegraph | .imgur
# ---------------------------------------------------------------------------------
# -*- coding: utf-8 -*-
# Module author: @GovnoCodules
import io
import logging
from io import BytesIO
import requests
from PIL import Image
from requests import post
from telethon import events
from telethon.errors.rpcerrorlist import YouBlockedUserError
from telethon.tl.types import DocumentAttributeFilename
from .. import loader, utils
logger = logging.getLogger(__name__)
@loader.tds
class FileUploaderMod(loader.Module):
"""Uploader"""
strings = {"name": "File Uploader"}
async def client_ready(self, client, db):
self.client = client
@loader.sudo
async def x0cmd(self, message):
"""Upload to x0"""
await message.edit("<b>Uploading...</b>")
reply = await message.get_reply_message()
if not reply:
await message.edit("<b>Reply to message!</b>")
return
media = reply.media
if not media:
file = io.BytesIO(bytes(reply.raw_text, "utf-8"))
file.name = "txt.txt"
else:
file = io.BytesIO(await self.client.download_file(media))
file.name = reply.file.name or reply.file.id + reply.file.ext
try:
x0at = post("https://x0.at", files={"file": file})
except ConnectionError as e:
await message.edit("<b>Error</b>")
return
url = x0at.text
output = f'<a href="{url}">URL: </a><code>{url}</code>'
await message.edit(output)
async def telegraphcmd(self, message):
""".ph <reply photo or video>"""
if message.is_reply:
reply_message = await message.get_reply_message()
data = await check_media(reply_message)
if isinstance(data, bool):
await message.edit("<b>Reply to photo or video/gif</b>")
return
else:
await message.edit("<b>Reply to photo or video/gif</b>")
return
file = await message.client.download_media(data, bytes)
path = requests.post(
"https://te.legra.ph/upload", files={"file": ("file", file, None)}
).json()
try:
link = "https://te.legra.ph" + path[0]["src"]
except KeyError:
link = path["error"]
await message.edit("<b>" + link + "</b>")
async def imgurcmd(self, message):
"""Upload to imgur"""
chat = "@imgur_linkbot"
reply = await message.get_reply_message()
async with message.client.conversation(chat) as conv:
if not reply:
await message.edit("<b>Reply to photo</b>")
return
else:
pic = await check_mediaa(message, reply)
if not pic:
await utils.answer(message, "<b>Reply to photo</b>")
return
await message.edit("<b>Uploading...</b>")
try:
what = lol(pic)
response = conv.wait_event(
events.NewMessage(incoming=True, from_users=1634387438)
)
await message.client.send_file(chat, what)
response = await response
except YouBlockedUserError:
await message.edit("<code>Разблокируй @imgur_linkbot</code>")
return
await message.edit("<b>Imgur link - </b>" + response.text)
async def check_media(reply_message):
if reply_message and reply_message.media:
if reply_message.photo:
data = reply_message.photo
elif reply_message.document:
if (
DocumentAttributeFilename(file_name="AnimatedSticker.tgs")
in reply_message.media.document.attributes
):
return False
if reply_message.audio or reply_message.voice:
return False
data = reply_message.media.document
else:
return False
else:
return False
if not data or data is None:
return False
else:
return data
def lol(reply):
scrrrra = Image.open(BytesIO(reply))
out = io.BytesIO()
out.name = "outsider.png"
scrrrra.save(out)
return out.getvalue()
async def check_mediaa(message, reply):
if reply and reply.media:
if reply.photo:
data = reply.photo
elif reply.document:
if reply.gif or reply.video or reply.audio or reply.voice:
return None
data = reply.media.document
else:
return None
else:
return None
if not data or data is None:
return None
data = await message.client.download_file(data, bytes)
try:
Image.open(io.BytesIO(data))
return data
except:
return None