Skip to content

Commit

Permalink
treewide: more code improvement & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
HitaloM committed Apr 23, 2022
1 parent 86ecaf8 commit 2274874
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion eduu/database/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logger = logging.getLogger(__name__)


class Database(object):
class Database:
def __init__(self):
self.conn: aiosqlite.Connection = None
self.path: str = DATABASE_PATH
Expand Down
3 changes: 3 additions & 0 deletions eduu/plugins/admins/bans.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2022 Amano Team

from pyrogram import Client, filters
from pyrogram.types import Message

Expand Down
1 change: 0 additions & 1 deletion eduu/plugins/admins/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) 2018-2022 Amano Team

import asyncio
from typing import Optional

from pyrogram import Client, filters
from pyrogram.types import Message
Expand Down
3 changes: 3 additions & 0 deletions eduu/plugins/admins/mutes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2022 Amano Team

from pyrogram import Client, filters
from pyrogram.types import ChatPermissions, Message

Expand Down
3 changes: 3 additions & 0 deletions eduu/plugins/admins/pins.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2022 Amano Team

from pyrogram import Client, filters
from pyrogram.types import Message

Expand Down
42 changes: 15 additions & 27 deletions eduu/plugins/sudos.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from eduu.database.restarted import set_restarted
from eduu.utils import sudofilter
from eduu.utils.localization import use_chat_lang
from eduu.utils.utils import shell_exec

prefix: Union[list, str] = "!"

Expand All @@ -43,42 +44,26 @@ async def run_cmd(c: Client, m: Message, strings):
if re.match("(?i)poweroff|halt|shutdown|reboot", cmd):
res = strings("forbidden_command")
else:
proc = await asyncio.create_subprocess_shell(
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await proc.communicate()
stdout, stderr = await shell_exec(cmd)
res = (
"<b>Output:</b>\n<code>{}</code>".format(
html.escape(stdout.decode().strip())
)
"<b>Output:</b>\n<code>{}</code>".format(html.escape(stdout))
if stdout
else ""
) + (
"\n<b>Errors:</b>\n<code>{}</code>".format(
html.escape(stderr.decode().strip())
)
if stderr
else ""
)
) + ("\n<b>Errors:</b>\n<code>{}</code>".format(stderr) if stderr else "")
await m.reply_text(res)


@Client.on_message(filters.command("upgrade", prefix) & sudofilter)
@use_chat_lang()
async def upgrade(c: Client, m: Message, strings):
sm = await m.reply_text("Upgrading sources...")
proc = await asyncio.create_subprocess_shell(
"git pull --no-edit",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
)
stdout = (await proc.communicate())[0]
stdout, proc = await shell_exec("git pull --no-edit")
if proc.returncode == 0:
if "Already up to date." in stdout.decode():
if "Already up to date." in stdout:
await sm.edit_text("There's nothing to upgrade.")
else:
await sm.edit_text(strings("restarting"))
set_restarted(sm.chat.id, sm.message_id)
await set_restarted(sm.chat.id, sm.message_id)
await conn.commit()
args = [sys.executable, "-m", "eduu"]
os.execv(sys.executable, args) # skipcq: BAN-B606
Expand All @@ -95,13 +80,13 @@ async def evals(c: Client, m: Message):
text = m.text.split(maxsplit=1)[1]
try:
res = await meval(text, globals(), **locals())
except: # skipcq
except BaseException: # skipcq
ev = traceback.format_exc()
await m.reply_text(f"<code>{html.escape(ev)}</code>")
else:
try:
await m.reply_text(f"<code>{html.escape(str(res))}</code>")
except Exception as e: # skipcq
except BaseException as e: # skipcq
await m.reply_text(str(e))


Expand All @@ -115,7 +100,7 @@ async def execs(c: Client, m: Message):
with redirect_stdout(strio):
try:
await locals()["__ex"](c, m)
except: # skipcq
except BaseException: # skipcq
return await m.reply_text(html.escape(traceback.format_exc()))

if strio.getvalue().strip():
Expand Down Expand Up @@ -233,14 +218,17 @@ async def getbotstats(c: Client, m: Message):

@Client.on_message(filters.command("del", prefix) & sudofilter)
async def del_message(c: Client, m: Message):
err = ""
try:
await c.delete_messages(m.chat.id, m.reply_to_message.message_id)
except RPCError as e:
print(e)
err += e
try:
await c.delete_messages(m.chat.id, m.message_id)
except RPCError as e:
print(e)
err += e

await m.reply_text(err)


@Client.on_message(
Expand Down
2 changes: 0 additions & 2 deletions eduu/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@

__all__: List[str] = [
"EMOJI_PATTERN",
"add_chat",
"aiowrap",
"button_parser",
"chat_exists",
"check_perms",
"commands",
"get_emoji_regex",
Expand Down

0 comments on commit 2274874

Please sign in to comment.