Spaces:
Paused
Paused
File size: 4,766 Bytes
d7854c4 b5409bb d7854c4 b5409bb d7854c4 b5409bb d7854c4 b5409bb d7854c4 b5409bb d7854c4 b5409bb d7854c4 b5409bb d7854c4 b5409bb d7854c4 b5409bb d7854c4 |
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 |
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://github.com/TeamUltroid/pyUltroid/blob/main/LICENSE>.
import os, subprocess
from shutil import rmtree
from decouple import config
from git import Repo
from .. import *
from ..dB._core import HELP
from ..loader import Loader
from . import *
from .utils import load_addons
def _after_load(loader, module, plugin_name=""):
if not module or plugin_name.startswith("_"):
return
from strings import get_help
if doc_ := get_help(plugin_name) or module.__doc__:
try:
doc = doc_.format(i=HNDLR)
except Exception as er:
loader._logger.exception(er)
loader._logger.info(f"Error in {plugin_name}: {module}")
return
if loader.key in HELP.keys():
update_cmd = HELP[loader.key]
try:
update_cmd.update({plugin_name: doc})
except BaseException as er:
loader._logger.exception(er)
else:
try:
HELP.update({loader.key: {plugin_name: doc}})
except BaseException as em:
loader._logger.exception(em)
def load_other_plugins(addons=None, pmbot=None, manager=None, vcbot=None):
# for official
_exclude = udB.get_key("EXCLUDE_OFFICIAL") or config("EXCLUDE_OFFICIAL", None)
_exclude = _exclude.split() if _exclude else []
# "INCLUDE_ONLY" was added to reduce Big List in "EXCLUDE_OFFICIAL" Plugin
_in_only = udB.get_key("INCLUDE_ONLY") or config("INCLUDE_ONLY", None)
_in_only = _in_only.split() if _in_only else []
Loader().load(include=_in_only, exclude=_exclude, after_load=_after_load)
# for assistant
if not udB.get_key("DISABLE_AST_PLUGINS"):
_ast_exc = ["pmbot"]
if _in_only and "games" not in _in_only:
_ast_exc.append("games")
Loader(path="assistant").load(
log=False, exclude=_ast_exc, after_load=_after_load
)
# for addons
if addons:
if url := udB.get_key("ADDONS_URL"):
subprocess.run(f"git clone -q {url} addons", shell=True)
if os.path.exists("addons") and not os.path.exists("addons/.git"):
rmtree("addons")
if not os.path.exists("addons"):
subprocess.run(
f"git clone -q -b {Repo().active_branch} https://github.com/TeamUltroid/UltroidAddons.git addons",
shell=True,
)
else:
subprocess.run("cd addons && git pull -q && cd ..", shell=True)
if not os.path.exists("addons"):
subprocess.run(
"git clone -q https://github.com/TeamUltroid/UltroidAddons.git addons",
shell=True,
)
if os.path.exists("addons/addons.txt"):
# generally addons req already there so it won't take much time
# subprocess.run(
# "rm -rf /usr/local/lib/python3.*/site-packages/pip/_vendor/.wh*"
# )
subprocess.run("pip3 install --no-cache-dir -q -r ./addons/addons.txt", shell=True)
_exclude = udB.get_key("EXCLUDE_ADDONS")
_exclude = _exclude.split() if _exclude else []
_in_only = udB.get_key("INCLUDE_ADDONS")
_in_only = _in_only.split() if _in_only else []
Loader(path="addons", key="Addons").load(
func=load_addons,
include=_in_only,
exclude=_exclude,
after_load=_after_load,
load_all=True,
)
# group manager
if manager:
Loader(path="assistant/manager", key="Group Manager").load()
# chat via assistant
if pmbot:
Loader(path="assistant/pmbot.py").load_single(log=False)
# vc bot
if vcbot and not vcClient._bot:
try:
import pytgcalls # ignore: pylint
if os.path.exists("vcbot"):
if os.path.exists("vcbot/.git"):
subprocess.run("cd vcbot && git pull", shell=True)
else:
rmtree("vcbot")
if not os.path.exists("vcbot"):
subprocess.run("git clone https://github.com/TeamUltroid/VcBot vcbot", shell=True)
try:
if not os.path.exists("vcbot/downloads"):
os.mkdir("vcbot/downloads")
Loader(path="vcbot", key="VCBot").load(after_load=_after_load)
except FileNotFoundError as e:
LOGS.error(f"{e} Skipping VCBot Installation.")
except ModuleNotFoundError:
LOGS.error("'pytgcalls' not installed!\nSkipping load of VcBot.")
|