FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
DevelopersUserbot/_pyrogram/modules/paste.py at master · TheCodents/DevelopersUserbot · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
TheCodents
/
DevelopersUserbot
Public
Notifications
You must be signed in to change notification settings
Fork
36
Star
25
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
DevelopersUserbot
/
_pyrogram
/
modules
/
paste.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
115 lines (99 loc) · 3.65 KB
Breadcrumbs
DevelopersUserbot
/
_pyrogram
/
modules
/
paste.py
Copy path
File metadata and controls
115 lines (99 loc) · 3.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# This file is Originally wirtten by @SpEcHiDe on GitHub
# The Author (Jayant Kageri) just Ported this for Devloper Userbot
# (C) 2021 Jayant Kageri
import
asyncio
import
aiohttp
import
json
import
os
from
urllib
.
parse
import
urlparse
from
pyrogram
import
Client
,
filters
from
_pyrogram
import
app
,
CMD_HELP
from
config
import
PREFIX
CMD_HELP
.
update
(
{
"Misc"
:
"""
**Misc**
`paste` -> Paste replied content to nekobin.com.
`tr` [lang code] -> Transalte a text to a given language.
`info` [user handle] -> Provides information about the user.
`id` [user handle] -> Give user or chat id
`restart` -> Restart the Clients
`load -p` -> To Install/Load Pyrogram Plugins
`json` -> To Get Message Details
"""
}
)
TMP_DOWNLOAD_DIRECTORY
=
"./_pyrogram/"
@
app
.
on_message
(
filters
.
command
(
"paste"
,
PREFIX
)
&
filters
.
me
)
async
def
pastebin
(
_
,
message
):
await
message
.
edit
(
"..."
)
downloaded_file_name
=
None
if
message
.
reply_to_message
and
message
.
reply_to_message
.
media
:
downloaded_file_name_res
=
await
message
.
reply_to_message
.
download
(
file_name
=
TMP_DOWNLOAD_DIRECTORY
)
m_list
=
None
with
open
(
downloaded_file_name_res
,
"rb"
)
as
fd
:
m_list
=
fd
.
readlines
()
downloaded_file_name
=
""
for
m
in
m_list
:
downloaded_file_name
+=
m
.
decode
(
"UTF-8"
)
os
.
remove
(
downloaded_file_name_res
)
elif
message
.
reply_to_message
:
downloaded_file_name
=
message
.
reply_to_message
.
text
.
html
# elif len(message.command) > 1:
# downloaded_file_name = " ".join(message.command[1:])
else
:
await
message
.
edit
(
"Not said What to do"
)
return
if
downloaded_file_name
is
None
:
await
message
.
edit
(
"Didn't say what to do"
)
return
json_paste_data
=
{
"content"
:
downloaded_file_name
}
# a dictionary to store different pastebin URIs
paste_bin_store_s
=
{
"deldog"
:
"https://del.dog/documents"
,
"nekobin"
:
"https://nekobin.com/api/documents"
}
chosen_store
=
"nekobin"
if
len
(
message
.
command
)
==
2
:
chosen_store
=
message
.
command
[
1
]
# get the required pastebin URI
paste_store_url
=
paste_bin_store_s
.
get
(
chosen_store
,
paste_bin_store_s
[
"nekobin"
]
)
paste_store_base_url_rp
=
urlparse
(
paste_store_url
)
# the pastebin sites, respond with only the "key"
# we need to prepend the BASE_URL of the appropriate site
paste_store_base_url
=
paste_store_base_url_rp
.
scheme
+
"://"
+
\
paste_store_base_url_rp
.
netloc
async
with
aiohttp
.
ClientSession
()
as
session
:
response_d
=
await
session
.
post
(
paste_store_url
,
json
=
json_paste_data
)
response_jn
=
await
response_d
.
json
()
# we got the response from a specific site,
# this dictionary needs to be scrapped
# using bleck megick to find the "key"
t_w_attempt
=
bleck_megick
(
response_jn
)
required_url
=
json
.
dumps
(
t_w_attempt
,
sort_keys
=
True
,
indent
=
4
)
+
"
\n
\n
#ERROR"
if
t_w_attempt
is
not
None
:
required_url
=
"**Patsted to Nekobin**
\n
"
+
paste_store_base_url
+
"/"
+
"raw"
+
"/"
+
t_w_attempt
await
message
.
edit
(
required_url
)
def
bleck_megick
(
dict_rspns
):
# first, try getting "key", dirctly
first_key_r
=
dict_rspns
.
get
(
"key"
)
# this is for the "del.dog" site
if
first_key_r
is
not
None
:
return
first_key_r
check_if_result_ests
=
dict_rspns
.
get
(
"result"
)
if
check_if_result_ests
is
not
None
:
# this is for the "nekobin.com" site
second_key_a
=
check_if_result_ests
.
get
(
"key"
)
if
second_key_a
is
not
None
:
return
second_key_a
# TODO: is there a better way?
return
None
Back
|
FazBrowse Home
|
New Git URL