-
Notifications
You must be signed in to change notification settings - Fork 1
/
_core.py
185 lines (169 loc) ยท 7.87 KB
/
_core.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
import asyncio
from datetime import datetime
import io
import os
from pathlib import Path
from telethon import events, functions, types
from telethon.tl.types import InputMessagesFilterDocument
from . import *
@bot.on(d3vil_cmd(pattern=r"cmds"))
@bot.on(sudo_cmd(pattern=r"cmds", allow_sudo=True))
async def kk(event):
if event.fwd_from:
return
reply_to_id = event.message.id
if event.reply_to_msg_id:
reply_to_id = event.reply_to_msg_id
cmd = "ls d3vilbot/plugins"
thumb = d3vil_logo
process = await asyncio.create_subprocess_sd3vil(
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
o = stdout.decode()
_o = o.split("\n")
o = "\n".join(_o)
OUTPUT = f"๐ซ๐๐๐ ๐๐ฟ ๐ฏ๐
๐๐๐๐๐ ๐๐ ๐ป๐๐ :- \n\n{o}\n\n<><><><><><><><><><><><><><><><><><><><><><><><>\nHELP:- ๐จ๐ฟ ๐๐๐ ๐๐บ๐๐ ๐๐ ๐๐๐๐ ๐๐๐พ ๐ผ๐๐๐๐บ๐๐ฝ๐ ๐ฟ๐๐ ๐บ ๐๐
๐๐๐๐, ๐ฝ๐ :- \n.plinfo <๐๐
๐๐๐๐ ๐๐บ๐๐พ> ๐๐๐๐๐๐๐ ๐๐๐พ < > ๐ป๐๐บ๐ผ๐๐พ๐๐. \๐๐ฉ๐๐๐ {d3vil_grp} ๐ฟ๐๐ ๐๐๐พ๐๐."
if len(OUTPUT) > 69:
with io.BytesIO(str.encode(OUTPUT)) as out_file:
out_file.name = "cmd_list.text"
d3vil_file = await bot.send_file(
event.chat_id,
out_file,
force_document=True,
allow_cache=False,
thumb=thumb,
reply_to=reply_to_id,
)
await edit_or_reply(d3vil_file, f"Output Too Large. This is the file for the list of plugins in bot.\n\n**BY :-** {D3VIL_USER}")
await event.delete()
@bot.on(d3vil_cmd(pattern=r"send (?P<shortname>\w+)", outgoing=True))
@bot.on(sudo_cmd(pattern=r"send (?P<shortname>\w+)", allow_sudo=True))
async def send(event):
if event.fwd_from:
return
message_id = event.message.id
thumb = d3vil_logo
input_str = event.pattern_match.group(1)
omk = f"**โข แดสแดษขษชษด ษดแดแดแด โ** `{input_str}`\n**โข แดแดสแดแดแด
แดแด
สส โ** {d3vil_mention}\n\nโก **[สษษขษีผษaสส แดา แดแดแดแด แด
3แด ษชส]({chnl_link})** โก"
the_plugin_file = "./d3vilbot/plugins/{}.py".format(input_str)
if os.path.exists(the_plugin_file):
lauda = await event.client.send_file(
event.chat_id,
the_plugin_file,
thumb=thumb,
caption=omk,
force_document=True,
allow_cache=False,
reply_to=message_id,
)
await event.delete()
else:
await eod(event, "๐ฅ๐๐
๐พ ๐๐๐ ๐ฟ๐๐๐๐ฝ..... ๐ช๐พ๐")
@bot.on(d3vil_cmd(pattern="install ?(.*)"))
@bot.on(sudo_cmd(pattern="install ?(.*)", allow_sudo=True))
async def install(event):
if event.fwd_from:
return
b = 1
owo = event.text[9:]
d3vil = await eor(event, "__Installing.__")
if event.reply_to_msg_id:
try:
downloaded_file_name = await event.client.download_media( # pylint:disable=E0602
await event.get_reply_message(),
"./d3vilbot/plugins/" # pylint:disable=E0602
)
if owo != "-f":
op = open(downloaded_file_name, "r")
rd = op.read()
op.close()
try:
for harm in HARMFUL:
if harm in rd:
os.remove(downloaded_file_name)
return await d3vil.edit(f"**โ ๏ธ WARNING !!** \n\n__Replied plugin file contains some harmful & hacking codes. Please consider checking the file. If you still want to install then use__ `{hl}install -f`. \n\n**Codes Detected :** \nโข {harm}")
except BaseException:
pass
if "(" not in downloaded_file_name:
path1 = Path(downloaded_file_name)
shortname = path1.stem
load_module(shortname.replace(".py", ""))
if shortname in CMD_LIST:
string = "**Commands found in** `{}`\n".format((os.path.basename(downloaded_file_name)))
for i in CMD_LIST[shortname]:
string += " โข `" + i
string += "`\n"
if b == 1:
a = "__Installing..__"
b = 2
else:
a = "__Installing...__"
b = 1
await d3vil.edit(a)
return await d3vil.edit(f"โ๏ธ **๐ธ๐๐๐๐๐๐๐๐ ๐๐๐๐๐๐** :- `{shortname}` \nโจ ๐ฑ๐ :- {d3vil_mention}\n\n{string}\n\n โก **[สษษขษีผษaสส แดา แดแดแดแด แด
3แด ษชส]({chnl_link})** โก", link_preview=False)
return await d3vil.edit(f"Installed module `{os.path.basename(downloaded_file_name)}`")
else:
os.remove(downloaded_file_name)
return await eod(d3vil, f"**Failed to Install** \n`Error`\nModule already installed or unknown format")
except Exception as e:
await eod(d3vil, f"**Failed to Install** \n`Error`\n{str(e)}")
return os.remove(downloaded_file_name)
@bot.on(d3vil_cmd(pattern=r"uninstall (?P<shortname>\w+)", outgoing=True))
@bot.on(sudo_cmd(pattern=r"uninstall (?P<shortname>\w+)", allow_sudo=True))
async def uninstall(d3vilkrish):
if d3vilkrish.fwd_from:
return
shortname = d3vilkrish.pattern_match["shortname"]
dir_path =f"./d3vilbot/plugins/{shortname}.py"
try:
remove_plugin(shortname)
os.remove(dir_path)
await eod(d3vilkrish, f"Uninstalled `{shortname}` successfully")
except OSError as e:
await d3vilkrish.edit("Error: %s : %s" % (dir_path, e.strerror))
@bot.on(d3vil_cmd(pattern=r"unload (?P<shortname>\w+)$"))
@bot.on(sudo_cmd(pattern=r"unload (?P<shortname>\w+)$", allow_sudo=True))
async def unload(event):
if event.fwd_from:
return
shortname = event.pattern_match["shortname"]
try:
remove_plugin(shortname)
await event.edit(f"๐ฒ๐๐ผ๐ผ๐พ๐๐๐ฟ๐๐
๐
๐ ๐๐๐
๐๐บ๐ฝ๐พ๐ฝ `{shortname}`")
except Exception as e:
await event.edit(
"Successfully unloaded {shortname}\n{}".format(
shortname, str(e)
)
)
@bot.on(d3vil_cmd(pattern=r"load (?P<shortname>\w+)$"))
@bot.on(sudo_cmd(pattern=r"load (?P<shortname>\w+)$", allow_sudo=True))
async def load(event):
if event.fwd_from:
return
shortname = event.pattern_match["shortname"]
try:
try:
remove_plugin(shortname)
except BaseException:
pass
load_module(shortname)
await event.edit(f"๐ฒ๐๐ผ๐ผ๐พ๐๐๐ฟ๐๐
๐
๐ ๐
๐๐บ๐ฝ๐พ๐ฝ `{shortname}`")
except Exception as e:
await event.edit(
f"Sorry, could not load {shortname} because of the following error.\n{str(e)}"
)
CmdHelp("core").add_command(
"install", "<reply to a .py file>", "Installs the replied python file if suitable to ๐3๐ณ๐ฆ๐ฉ๐
๐ฌ๐ฑ's codes."
).add_command(
"uninstall", "<plugin name>", "Uninstalls the given plugin from ๐3๐ณ๐ฆ๐ฉ๐
๐ฌ๐ฑ. To get that again do .restart", "uninstall alive"
).add_command(
"load", "<plugin name>", "Loades the unloaded plugin to your userbot", "load alive"
).add_command(
"unload", "<plugin name>", "Unloads the plugin from your userbot", "unload alive"
).add_command(
"send", "<file name>", "Sends the given file from your userbot server, if any.", "send alive"
).add_command(
"cmds", None, "Gives out the list of modules in D3vilBot."
).add()