Spaces:
Sleeping
Sleeping
File size: 5,937 Bytes
c26bbaf 87abec5 11ae35a aef1161 11ae35a 1b4a9e6 8fb35a7 aef1161 89a7a7a 51e1c40 8fb35a7 aef1161 1b4a9e6 89ad488 c26bbaf 89ad488 1b4a9e6 bd54dc6 1b4a9e6 f192ee1 6cef7ec f192ee1 1b4a9e6 51e1c40 aef1161 c26bbaf 89ad488 47a10d1 aef1161 1b4a9e6 bd54dc6 1b4a9e6 aef1161 1b4a9e6 aef1161 bd54dc6 8fb35a7 89a7a7a 8fb35a7 9015bc5 8fb35a7 1b4a9e6 8fb35a7 89ad488 fe86459 8fb35a7 8074cb2 89a7a7a 818420a 89a7a7a 1b4a9e6 be19ad1 1b4a9e6 89ad488 1b4a9e6 6dcea66 1b4a9e6 83fe5dc c26bbaf 1b4a9e6 89a7a7a 1b4a9e6 ea508b7 424a281 1b4a9e6 6cef7ec c26bbaf 89ad488 c26bbaf 89ad488 b48df3a 89ad488 b48df3a 89ad488 ea508b7 1b4a9e6 51e1c40 1b4a9e6 51e1c40 1b4a9e6 769060e 1b4a9e6 769060e 9da6fea 1b4a9e6 9da6fea 1b4a9e6 6cef7ec 1b4a9e6 |
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
import shutil
from datetime import datetime
from importlib import import_module as imp_mod
from logging import (INFO, WARNING, FileHandler, StreamHandler, basicConfig,
getLogger)
from os import environ, listdir, mkdir, path
from platform import python_version
from sys import exit as sysexit
from sys import stdout, version_info
from time import time
from traceback import format_exc
import lyricsgenius
import pyrogram
import pytz
from apscheduler.schedulers.asyncio import AsyncIOScheduler
LOG_DATETIME = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
LOGDIR = f"{__name__}/logs"
if path.isdir(LOGDIR):
shutil.rmtree(LOGDIR)
mkdir(LOGDIR)
LOGFILE = f"{LOGDIR}/{__name__}_{LOG_DATETIME}_log.txt"
file_handler = FileHandler(filename=LOGFILE)
stdout_handler = StreamHandler(stdout)
basicConfig(
format="%(asctime)s - [Gojo_Satoru] - %(levelname)s - %(message)s",
level=INFO,
handlers=[file_handler, stdout_handler],
)
getLogger("pyrogram").setLevel(WARNING)
LOGGER = getLogger(__name__)
# if version < 3.9, stop bot.
if version_info[0] < 3 or version_info[1] < 7:
LOGGER.error(
(
"You MUST have a Python Version of at least 3.7!\n"
"Multiple features depend on this. Bot quitting."
),
)
sysexit(1) # Quit the Script
# the secret configuration specific things
try:
from Powers.vars import is_env
if is_env or environ.get("ENV"):
from Powers.vars import Config
else:
from Powers.vars import Development as Config
except Exception as ef:
LOGGER.error(ef) # Print Error
LOGGER.error(format_exc())
sysexit(1)
# time zone
TIME_ZONE = pytz.timezone(Config.TIME_ZONE)
Vpath = "./Version"
version = [
i for i in listdir(Vpath) if i.startswith("version") and i.endswith("md")
]
VERSION = sorted(version)[-1][8:-3]
PYTHON_VERSION = python_version()
PYROGRAM_VERSION = pyrogram.__version__
LOGGER.info("------------------------")
LOGGER.info("| Gojo_Satoru |")
LOGGER.info("------------------------")
LOGGER.info(f"Version: {VERSION}")
LOGGER.info(f"Owner: {str(Config.OWNER_ID)}")
LOGGER.info(f"Time zone set to {Config.TIME_ZONE}")
LOGGER.info("Source Code: https://github.com/Gojo-Bots/Gojo_Satoru\n")
LOGGER.info("Checking lyrics genius api...")
# API based clients
if Config.GENIUS_API_TOKEN:
LOGGER.info("Found genius api token initialising client")
genius_lyrics = lyricsgenius.Genius(
Config.GENIUS_API_TOKEN,
skip_non_songs=True,
excluded_terms=["(Remix)", "(Live)"],
remove_section_headers=True,
)
is_genius_lyrics = True
genius_lyrics.verbose = False
LOGGER.info("Client setup complete")
else:
LOGGER.info("Genius api not found lyrics command will not work")
is_genius_lyrics = False
genius_lyrics = False
# is_audd = False
# Audd = None
# if Config.AuDD_API:
# is_audd = True
# Audd = Config.AuDD_API
# LOGGER.info("Found Audd api")
is_rmbg = False
RMBG = None
if Config.RMBG_API:
is_rmbg = True
RMBG = Config.RMBG_API
# Account Related
BOT_TOKEN = Config.BOT_TOKEN
API_ID = Config.API_ID
API_HASH = Config.API_HASH
# General Config
MESSAGE_DUMP = Config.MESSAGE_DUMP or Config.OWNER_ID
SUPPORT_GROUP = Config.SUPPORT_GROUP
SUPPORT_CHANNEL = Config.SUPPORT_CHANNEL
# Users Config
OWNER_ID = Config.OWNER_ID
SUPPORT_USERS = {"Owner": [Config.OWNER_ID], "Dev": set(Config.DEV_USERS), "Sudo": set(Config.SUDO_USERS), "White": set(Config.WHITELIST_USERS)}
# Plugins, DB and Workers
DB_URI = Config.DB_URI
DB_NAME = Config.DB_NAME
NO_LOAD = Config.NO_LOAD
WORKERS = Config.WORKERS
BDB_URI = Config.BDB_URI
# Prefixes
PREFIX_HANDLER = Config.PREFIX_HANDLER
HELP_COMMANDS = {} # For help menu
UPTIME = time() # Check bot uptime
# Make dir
youtube_dir = "./Youtube/"
if path.isdir(youtube_dir):
shutil.rmtree(youtube_dir)
mkdir(youtube_dir)
scrap_dir = "./scrapped/"
if path.isdir(scrap_dir):
shutil.rmtree(scrap_dir)
mkdir(scrap_dir)
scheduler = AsyncIOScheduler(timezone=TIME_ZONE)
async def load_cmds(all_plugins):
"""Loads all the plugins in bot."""
for single in all_plugins:
# If plugin in NO_LOAD, skip the plugin
if single.lower() in [i.lower() for i in Config.NO_LOAD]:
LOGGER.warning(
f"Not loading '{single}' s it's added in NO_LOAD list")
continue
imported_module = imp_mod(f"Powers.plugins.{single}")
if not hasattr(imported_module, "__PLUGIN__"):
continue
plugin_name = imported_module.__PLUGIN__.lower()
plugin_dict_name = f"plugins.{plugin_name}"
plugin_help = imported_module.__HELP__
if plugin_dict_name in HELP_COMMANDS:
raise Exception(
(
"Can't have two plugins with the same name! Please change one\n"
f"Error while importing '{imported_module.__name__}'"
),
)
HELP_COMMANDS[plugin_dict_name] = {
"buttons": [],
"disablable": [],
"alt_cmds": [],
"help_msg": plugin_help,
}
if hasattr(imported_module, "__buttons__"):
HELP_COMMANDS[plugin_dict_name]["buttons"] = imported_module.__buttons__
if hasattr(imported_module, "_DISABLE_CMDS_"):
HELP_COMMANDS[plugin_dict_name][
"disablable"
] = imported_module._DISABLE_CMDS_
if hasattr(imported_module, "__alt_name__"):
HELP_COMMANDS[plugin_dict_name]["alt_cmds"] = imported_module.__alt_name__
# Add the plugin name to cmd list
(HELP_COMMANDS[plugin_dict_name]["alt_cmds"]).append(plugin_name)
if NO_LOAD:
LOGGER.warning(f"Not loading Plugins - {NO_LOAD}")
return (
", ".join((i.split(".")[1]).capitalize()
for i in list(HELP_COMMANDS.keys()))
+ "\n"
)
|