Refactor module loading
This commit is contained in:
47
.github/workflows/update_modules.yml
vendored
47
.github/workflows/update_modules.yml
vendored
@@ -1,47 +0,0 @@
|
|||||||
name: Update Modules
|
|
||||||
|
|
||||||
on:
|
|
||||||
repository_dispatch:
|
|
||||||
types:
|
|
||||||
- custom-modules-updated
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
update-modules:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout Main repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Checkout Modules repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
repository: The-MoonTg-project/custom_modules
|
|
||||||
path: custom_modules
|
|
||||||
|
|
||||||
- name: Update file
|
|
||||||
run: |
|
|
||||||
ls -R
|
|
||||||
cd custom_modules
|
|
||||||
printf "%s\n" "$(ls -d */*)" | sed 's/\.py$//' > ../modules/full.txt
|
|
||||||
cd ..
|
|
||||||
rm -rf custom_modules/
|
|
||||||
|
|
||||||
- name: Commit changes
|
|
||||||
run: |
|
|
||||||
git add ./modules/full.txt
|
|
||||||
if git diff --cached --quiet; then
|
|
||||||
echo "No changes to commit."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
echo "new_modules_available=true" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Create Pull Request
|
|
||||||
if: success() && env.new_modules_available == 'true'
|
|
||||||
uses: peter-evans/create-pull-request@v5
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
commit-message: "Update modules/full.txt"
|
|
||||||
branch: update-modules-file
|
|
||||||
title: "Update for custom_modules"
|
|
||||||
body: "This PR updates the modules/full.txt file with the latest changes."
|
|
||||||
9
main.py
9
main.py
@@ -91,8 +91,13 @@ def load_missing_modules():
|
|||||||
custom_modules_path = f"{SCRIPT_PATH}/modules/custom_modules"
|
custom_modules_path = f"{SCRIPT_PATH}/modules/custom_modules"
|
||||||
os.makedirs(custom_modules_path, exist_ok=True)
|
os.makedirs(custom_modules_path, exist_ok=True)
|
||||||
|
|
||||||
with open("modules/full.txt", "r") as f:
|
try:
|
||||||
modules_dict = {line.split("/")[-1].split()[0]: line.strip() for line in f}
|
f = requests.get(
|
||||||
|
"https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt"
|
||||||
|
).text
|
||||||
|
except Exception:
|
||||||
|
return logging.error("Failed to fetch custom modules list")
|
||||||
|
modules_dict = {line.split("/")[-1].split()[0]: line.strip() for line in f.splitlines()}
|
||||||
|
|
||||||
for module_name in all_modules:
|
for module_name in all_modules:
|
||||||
module_path = f"{custom_modules_path}/{module_name}.py"
|
module_path = f"{custom_modules_path}/{module_name}.py"
|
||||||
|
|||||||
136
modules/full.txt
136
modules/full.txt
@@ -1,136 +0,0 @@
|
|||||||
admin/approveall
|
|
||||||
admin/banall
|
|
||||||
admin/blacklist
|
|
||||||
admin/gmute
|
|
||||||
ai/aimage
|
|
||||||
ai/blackbox
|
|
||||||
ai/cdxl
|
|
||||||
ai/chatbot
|
|
||||||
ai/cohere
|
|
||||||
ai/flux
|
|
||||||
ai/gemini
|
|
||||||
ai/gpt
|
|
||||||
ai/grokai
|
|
||||||
ai/huggingface
|
|
||||||
ai/markitdown
|
|
||||||
ai/midai
|
|
||||||
ai/pdf2md
|
|
||||||
ai/sdxl
|
|
||||||
anime/anilist
|
|
||||||
anime/anime
|
|
||||||
anime/neko
|
|
||||||
dl/aria2p
|
|
||||||
dl/ebook
|
|
||||||
dl/repo
|
|
||||||
dl/spotdl
|
|
||||||
dl/ytdl
|
|
||||||
fun/1000-7
|
|
||||||
fun/amogus
|
|
||||||
fun/animations
|
|
||||||
fun/aniquotes
|
|
||||||
fun/circle
|
|
||||||
fun/demotivator
|
|
||||||
fun/destroy
|
|
||||||
fun/dice
|
|
||||||
fun/durov
|
|
||||||
fun/f
|
|
||||||
fun/fakeactions
|
|
||||||
fun/fliptext
|
|
||||||
fun/hearts
|
|
||||||
fun/jac
|
|
||||||
fun/mafia
|
|
||||||
fun/mirror_flip
|
|
||||||
fun/perfectrussian
|
|
||||||
fun/reactionspam
|
|
||||||
fun/scr
|
|
||||||
fun/socialstalk
|
|
||||||
fun/spin
|
|
||||||
fun/type
|
|
||||||
images/icons
|
|
||||||
images/imgur
|
|
||||||
images/ncode
|
|
||||||
images/pinterest
|
|
||||||
images/risearch
|
|
||||||
images/unsplash
|
|
||||||
images/unsplash2
|
|
||||||
info/apksearch
|
|
||||||
info/covidinfo
|
|
||||||
info/forecast
|
|
||||||
info/gsm
|
|
||||||
info/ifsc
|
|
||||||
info/injob
|
|
||||||
info/mdict
|
|
||||||
info/mediainfo
|
|
||||||
info/medinfo
|
|
||||||
info/nasa
|
|
||||||
info/npm
|
|
||||||
info/pypi
|
|
||||||
info/qrcode
|
|
||||||
info/satellite
|
|
||||||
info/score
|
|
||||||
info/serverinfo
|
|
||||||
info/specs
|
|
||||||
info/weather
|
|
||||||
info/xtrend
|
|
||||||
misc/autobackup
|
|
||||||
misc/autofwd
|
|
||||||
misc/backup
|
|
||||||
misc/cama
|
|
||||||
misc/mlog
|
|
||||||
misc/prayer
|
|
||||||
misc/safone
|
|
||||||
misc/sarethai
|
|
||||||
misc/search
|
|
||||||
misc/summary
|
|
||||||
misc/switch
|
|
||||||
misc/transcribeyt
|
|
||||||
music/lastfm
|
|
||||||
music/musicbot
|
|
||||||
music/song
|
|
||||||
music/tiktok
|
|
||||||
music/voice_chat
|
|
||||||
music/yt_preview
|
|
||||||
news/aionews
|
|
||||||
news/dailyepaper
|
|
||||||
news/news
|
|
||||||
paste/haste
|
|
||||||
rev/apkid
|
|
||||||
rev/dexrepair
|
|
||||||
rev/rasm
|
|
||||||
tts/edge-tts
|
|
||||||
tts/playht
|
|
||||||
tts/tts
|
|
||||||
utils/alive
|
|
||||||
utils/auto_comment
|
|
||||||
utils/calculator
|
|
||||||
utils/compress
|
|
||||||
utils/currency
|
|
||||||
utils/date
|
|
||||||
utils/domaininfo
|
|
||||||
utils/duckduckgo
|
|
||||||
utils/fedutils
|
|
||||||
utils/files
|
|
||||||
utils/fwdall
|
|
||||||
utils/gcast
|
|
||||||
utils/getmsg
|
|
||||||
utils/google
|
|
||||||
utils/in
|
|
||||||
utils/ipinfo
|
|
||||||
utils/joindate
|
|
||||||
utils/kill
|
|
||||||
utils/leave_chat
|
|
||||||
utils/log_tag
|
|
||||||
utils/mediasaver
|
|
||||||
utils/messaging
|
|
||||||
utils/notifier
|
|
||||||
utils/ocr
|
|
||||||
utils/rdl
|
|
||||||
utils/rename
|
|
||||||
utils/session
|
|
||||||
utils/shift
|
|
||||||
utils/similarsites
|
|
||||||
utils/tagall
|
|
||||||
utils/time
|
|
||||||
utils/translator
|
|
||||||
utils/uplud
|
|
||||||
utils/wikipedia
|
|
||||||
@@ -80,6 +80,7 @@ async def loadmod(_, message: Message):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if len(message.command) > 1:
|
if len(message.command) > 1:
|
||||||
|
await message.edit("<b>Fetching module...</b>")
|
||||||
url = message.command[1].lower()
|
url = message.command[1].lower()
|
||||||
|
|
||||||
if url.startswith(
|
if url.startswith(
|
||||||
@@ -88,10 +89,13 @@ async def loadmod(_, message: Message):
|
|||||||
module_name = url.split("/")[-1].split(".")[0]
|
module_name = url.split("/")[-1].split(".")[0]
|
||||||
elif "." not in url:
|
elif "." not in url:
|
||||||
module_name = url.lower()
|
module_name = url.lower()
|
||||||
with open("modules/full.txt", "r") as f:
|
try:
|
||||||
modules_dict = {
|
f = requests.get(
|
||||||
line.split("/")[-1].split()[0]: line.strip() for line in f
|
"https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt"
|
||||||
}
|
).text
|
||||||
|
except Exception:
|
||||||
|
return await message.edit("Failed to fetch custom modules list")
|
||||||
|
modules_dict = {line.split("/")[-1].split()[0]: line.strip() for line in f.splitlines()}
|
||||||
if module_name in modules_dict:
|
if module_name in modules_dict:
|
||||||
url = f"https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{modules_dict[module_name]}.py"
|
url = f"https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{modules_dict[module_name]}.py"
|
||||||
else:
|
else:
|
||||||
@@ -225,8 +229,13 @@ async def load_all_mods(_, message: Message):
|
|||||||
if not os.path.exists(f"{BASE_PATH}/modules/custom_modules"):
|
if not os.path.exists(f"{BASE_PATH}/modules/custom_modules"):
|
||||||
os.mkdir(f"{BASE_PATH}/modules/custom_modules")
|
os.mkdir(f"{BASE_PATH}/modules/custom_modules")
|
||||||
|
|
||||||
with open("modules/full.txt", "r") as f:
|
try:
|
||||||
modules_list = f.read().splitlines()
|
f = requests.get(
|
||||||
|
"https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt"
|
||||||
|
).text
|
||||||
|
except Exception:
|
||||||
|
return await message.edit("Failed to fetch custom modules list")
|
||||||
|
modules_list = f.splitlines()
|
||||||
|
|
||||||
await message.edit("<b>Loading modules...</b>")
|
await message.edit("<b>Loading modules...</b>")
|
||||||
for module_name in modules_list:
|
for module_name in modules_list:
|
||||||
@@ -291,9 +300,13 @@ async def updateallmods(_, message: Message):
|
|||||||
for module_name in modules_installed:
|
for module_name in modules_installed:
|
||||||
if not module_name.endswith(".py"):
|
if not module_name.endswith(".py"):
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
with open("modules/full.txt", "r") as f:
|
f = requests.get(
|
||||||
modules_dict = {line.split("/")[-1].split()[0]: line.strip() for line in f}
|
"https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt"
|
||||||
|
).text
|
||||||
|
except Exception:
|
||||||
|
return await message.edit("Failed to fetch custom modules list")
|
||||||
|
modules_dict = {line.split("/")[-1].split()[0]: line.strip() for line in f.splitlines()}
|
||||||
if module_name in modules_dict:
|
if module_name in modules_dict:
|
||||||
resp = requests.get(
|
resp = requests.get(
|
||||||
f"https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{modules_dict[module_name]}.py"
|
f"https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{modules_dict[module_name]}.py"
|
||||||
|
|||||||
Reference in New Issue
Block a user