File size: 5,245 Bytes
80287e2 |
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 |
import asyncio
import os
import shutil
import socket
from datetime import datetime
import urllib3
from git import Repo
from git.exc import GitCommandError, InvalidGitRepositoryError
from pyrogram import filters
import config
from Devine import app
from Devine.misc import HAPP, SUDOERS, XCB
from Devine.utils.database import (
get_active_chats,
remove_active_chat,
remove_active_video_chat,
)
from Devine.utils.decorators.language import language
from Devine.utils.pastebin import AnonyBin
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
async def is_heroku():
return "heroku" in socket.getfqdn()
@app.on_message(filters.command(["gts"]) & SUDOERS)
@language
async def log_(client, message, _):
try:
await message.reply_document(document="log.txt")
except:
await message.reply_text(_["server_1"])
@app.on_message(filters.command(["update", "gitpull"]) & SUDOERS)
@language
async def update_(client, message, _):
if await is_heroku():
if HAPP is None:
return await message.reply_text(_["server_2"])
response = await message.reply_text(_["server_3"])
try:
repo = Repo()
except GitCommandError:
return await response.edit(_["server_4"])
except InvalidGitRepositoryError:
return await response.edit(_["server_5"])
to_exc = f"git fetch origin {config.UPSTREAM_BRANCH} &> /dev/null"
os.system(to_exc)
await asyncio.sleep(7)
verification = ""
REPO_ = repo.remotes.origin.url.split(".git")[0]
for checks in repo.iter_commits(f"HEAD..origin/{config.UPSTREAM_BRANCH}"):
verification = str(checks.count())
if verification == "":
return await response.edit(_["server_6"])
updates = ""
ordinal = lambda format: "%d%s" % (
format,
"tsnrhtdd"[(format // 10 % 10 != 1) * (format % 10 < 4) * format % 10 :: 4],
)
for info in repo.iter_commits(f"HEAD..origin/{config.UPSTREAM_BRANCH}"):
updates += f"#{info.count()}: <a href={REPO_}/commit/{info}>{info.summary}</a> ʙʏ -> {info.author}</b>\n\t\t\t\t<b>ᴄᴏᴍᴍɪᴛᴇᴅ ᴏɴ :</b> {ordinal(int(datetime.fromtimestamp(info.committed_date).strftime('%d')))} {datetime.fromtimestamp(info.committed_date).strftime('%b')}, {datetime.fromtimestamp(info.committed_date).strftime('%Y')}\n\n"
_update_response_ = "ᴀ ɴᴇᴡ ᴜᴩᴅᴀᴛᴇ ɪs ᴀᴠᴀɪʟᴀʙʟᴇ ғᴏʀ ᴛʜᴇ ʙᴏᴛ !\n\nᴩᴜsʜɪɴɢ ᴜᴩᴅᴀᴛᴇs ɴᴏᴡ\n\nᴜᴩᴅᴀᴛᴇs:\n\n"
_final_updates_ = _update_response_ + updates
if len(_final_updates_) > 4096:
url = await AnonyBin(updates)
nrs = await response.edit(
f"ᴀ ɴᴇᴡ ᴜᴩᴅᴀᴛᴇ ɪs ᴀᴠᴀɪʟᴀʙʟᴇ ғᴏʀ ᴛʜᴇ ʙᴏᴛ !\n\nᴩᴜsʜɪɴɢ ᴜᴩᴅᴀᴛᴇs ɴᴏᴡ\n\nᴜᴩᴅᴀᴛᴇs :\n\n<a href={url}>ᴄʜᴇᴄᴋ ᴜᴩᴅᴀᴛᴇs</a>"
)
else:
nrs = await response.edit(_final_updates_, disable_web_page_preview=True)
os.system("git stash &> /dev/null && git pull")
try:
served_chats = await get_active_chats()
for x in served_chats:
try:
await app.send_message(
chat_id=int(x),
text=_["server_8"].format(app.mention),
)
await remove_active_chat(x)
await remove_active_video_chat(x)
except:
pass
await response.edit(f"{nrs.text}\n\n{_['server_7']}")
except:
pass
if await is_heroku():
try:
os.system(
f"{XCB[5]} {XCB[7]} {XCB[9]}{XCB[4]}{XCB[0]*2}{XCB[6]}{XCB[4]}{XCB[8]}{XCB[1]}{XCB[5]}{XCB[2]}{XCB[6]}{XCB[2]}{XCB[3]}{XCB[0]}{XCB[10]}{XCB[2]}{XCB[5]} {XCB[11]}{XCB[4]}{XCB[12]}"
)
return
except Exception as err:
await response.edit(f"{nrs.text}\n\n{_['server_9']}")
return await app.send_message(
chat_id=config.LOGGER_ID,
text=_["server_10"].format(err),
)
else:
os.system("pip3 install -r requirements.txt")
os.system(f"kill -9 {os.getpid()} && bash start")
exit()
@app.on_message(filters.command(["restart"]) & SUDOERS)
async def restart_(_, message):
response = await message.reply_text("ʀᴇsᴛᴀʀᴛɪɴɢ...")
ac_chats = await get_active_chats()
for x in ac_chats:
try:
await app.send_message(
chat_id=int(x),
text=f"{app.mention} ɪs ʀᴇsᴛᴀʀᴛɪɴɢ...\n\nʏᴏᴜ ᴄᴀɴ sᴛᴀʀᴛ ᴩʟᴀʏɪɴɢ ᴀɢᴀɪɴ ᴀғᴛᴇʀ 15-20 sᴇᴄᴏɴᴅs.",
)
await remove_active_chat(x)
await remove_active_video_chat(x)
except:
pass
try:
shutil.rmtree("downloads")
shutil.rmtree("raw_files")
shutil.rmtree("cache")
except:
pass
await response.edit_text(
"ʀᴇsᴛᴀʀᴛ ᴘʀᴏᴄᴇss sᴛᴀʀᴛᴇᴅ, ᴘʟᴇᴀsᴇ ᴡᴀɪᴛ ғᴏʀ ғᴇᴡ sᴇᴄᴏɴᴅs ᴜɴᴛɪʟ ᴛʜᴇ ʙᴏᴛ sᴛᴀʀᴛs..."
)
os.system(f"kill -9 {os.getpid()} && bash start")
|