This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Sourcery refactored main branch #3
Open
sourcery-ai
wants to merge
2
commits into
main
Choose a base branch
from
sourcery/main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,31 +31,36 @@ | |
\033[37m┌─────────────────────────────────────────────┐\033[0m\n\033[37m│\033[44m\033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[91;101m#########################\033[0m\033[37m│\n\033[37m│\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[97;107m:::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[44m\033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[91;101m#########################\033[0m\033[37m│\n\033[37m│\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[97;107m:::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[44m\033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[91;101m#########################\033[0m\033[37m│\n\033[37m│\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[97;107m:::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[44m\033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[91;101m#########################\033[0m\033[37m│ \033[1mUnited we stand, Divided we fall\033[0m\n\033[37m│\033[97;107m:::::::::::::::::::::::::::::::::::::::::::::\033[0m\033[37m│ \033[1mKigyo Project, a tribute to USS Enterprise.\033[0m\n\033[37m│\033[91;101m#############################################\033[0m\033[37m│\n\033[37m│\033[97;107m:::::::::::::::::::::::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[91;101m#############################################\033[0m\033[37m│\n\033[37m│\033[97;107m:::::::::::::::::::::::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[91;101m#############################################\033[0m\033[37m│\n\033[37m└─────────────────────────────────────────────┘\033[0m\n | ||
""" | ||
|
||
|
||
def get_user_list(key): | ||
# Import here to evade a circular import | ||
from kyosuke.modules.sql import nation_sql | ||
|
||
royals = nation_sql.get_royals(key) | ||
return [a.user_id for a in royals] | ||
|
||
|
||
FORMAT = "[kyosuke] %(message)s" | ||
logging.basicConfig( | ||
handlers=[logging.FileHandler("log.txt"), logging.StreamHandler()], | ||
level=logging.INFO, | ||
format=FORMAT, | ||
datefmt="[%X]", | ||
) | ||
LOGGER = logging.getLogger('[kyosuke]') | ||
LOGGER = logging.getLogger("[kyosuke]") | ||
LOGGER.info("kyosuke is starting. | Rendy Projects. | Licensed under GPLv3.") | ||
LOGGER.info("Not affiliated to other anime.") | ||
LOGGER.info("Project maintained by: github.com/Randi356 (t.me/rencprx)") | ||
|
||
# enable logging | ||
|
||
fileConfig('logging.ini') | ||
fileConfig("logging.ini") | ||
|
||
#print(flag) | ||
log = logging.getLogger('[kyosuke]') | ||
logging.getLogger('ptbcontrib.postgres_persistence.postgrespersistence').setLevel(logging.WARNING) | ||
# print(flag) | ||
log = logging.getLogger("[kyosuke]") | ||
logging.getLogger("ptbcontrib.postgres_persistence.postgrespersistence").setLevel( | ||
logging.WARNING | ||
) | ||
logging.getLogger("pyrogram").setLevel(logging.INFO) | ||
log.info("[KYOSUKE] Takehito is starting. | Rendy Project. | Licensed under GPLv3.") | ||
log.info("[KYOSUKE] Not affiliated to other anime.") | ||
|
@@ -72,70 +77,75 @@ def get_user_list(key): | |
parser.read("config.ini") | ||
renconfig = parser["renconfig"] | ||
|
||
|
||
class KyosukeINIT: | ||
def __init__(self, parser: ConfigParser): | ||
self.parser = parser | ||
self.SYS_ADMIN: int = self.parser.getint('SYS_ADMIN', 0) | ||
self.OWNER_ID: int = self.parser.getint('OWNER_ID') | ||
self.OWNER_USERNAME: str = self.parser.get('OWNER_USERNAME', None) | ||
self.SYS_ADMIN: int = self.parser.getint("SYS_ADMIN", 0) | ||
self.OWNER_ID: int = self.parser.getint("OWNER_ID") | ||
self.OWNER_USERNAME: str = self.parser.get("OWNER_USERNAME", None) | ||
self.APP_ID: str = self.parser.getint("APP_ID") | ||
self.API_HASH: str = self.parser.get("API_HASH") | ||
self.WEBHOOK: bool = self.parser.getboolean('WEBHOOK', False) | ||
self.URL: str = self.parser.get('URL', None) | ||
self.CERT_PATH: str = self.parser.get('CERT_PATH', None) | ||
self.PORT: int = self.parser.getint('PORT', None) | ||
self.INFOPIC: bool = self.parser.getboolean('INFOPIC', False) | ||
self.WEBHOOK: bool = self.parser.getboolean("WEBHOOK", False) | ||
self.URL: str = self.parser.get("URL", None) | ||
self.CERT_PATH: str = self.parser.get("CERT_PATH", None) | ||
self.PORT: int = self.parser.getint("PORT", None) | ||
self.INFOPIC: bool = self.parser.getboolean("INFOPIC", False) | ||
self.DEL_CMDS: bool = self.parser.getboolean("DEL_CMDS", False) | ||
self.STRICT_GBAN: bool = self.parser.getboolean("STRICT_GBAN", False) | ||
self.ALLOW_EXCL: bool = self.parser.getboolean("ALLOW_EXCL", False) | ||
self.CUSTOM_CMD: List[str] = ['/', '!', '^'] | ||
self.CUSTOM_CMD: List[str] = ["/", "!", "^"] | ||
self.BAN_STICKER: str = self.parser.get("BAN_STICKER", None) | ||
self.TOKEN: str = self.parser.get("TOKEN") | ||
self.DB_URI: str = self.parser.get("SQLALCHEMY_DATABASE_URI") | ||
self.REDIS_URL: str = self.parser.get("REDIS_URL") | ||
self.LOAD = self.parser.get("LOAD").split() | ||
self.LOAD: List[str] = list(map(str, self.LOAD)) | ||
self.MESSAGE_DUMP: int = self.parser.getint('MESSAGE_DUMP', None) | ||
self.GBAN_LOGS: int = self.parser.getint('GBAN_LOGS', None) | ||
self.MESSAGE_DUMP: int = self.parser.getint("MESSAGE_DUMP", None) | ||
self.GBAN_LOGS: int = self.parser.getint("GBAN_LOGS", None) | ||
self.NO_LOAD = self.parser.get("NO_LOAD").split() | ||
self.NO_LOAD: List[str] = list(map(str, self.NO_LOAD)) | ||
self.spamwatch_api: str = self.parser.get('spamwatch_api', None) | ||
self.CASH_API_KEY: str = self.parser.get('CASH_API_KEY', None) | ||
self.TIME_API_KEY: str = self.parser.get('TIME_API_KEY', None) | ||
self.WALL_API: str = self.parser.get('WALL_API', None) | ||
self.LASTFM_API_KEY: str = self.parser.get('LASTFM_API_KEY', None) | ||
self.CF_API_KEY: str = self.parser.get("CF_API_KEY", None) | ||
self.spamwatch_api: str = self.parser.get("spamwatch_api", None) | ||
self.CASH_API_KEY: str = self.parser.get("CASH_API_KEY", None) | ||
self.TIME_API_KEY: str = self.parser.get("TIME_API_KEY", None) | ||
self.WALL_API: str = self.parser.get("WALL_API", None) | ||
self.LASTFM_API_KEY: str = self.parser.get("LASTFM_API_KEY", None) | ||
self.CF_API_KEY: str = self.parser.get("CF_API_KEY", None) | ||
self.STRING_SESSION: str = self.parser.get("STRING_SESSION", None) | ||
self.BOT_ID: str = self.parser.get("BOT_ID", None) | ||
self.BOT_NAME: str = self.parser.get('BOT_NAME', "RendyTapiBot") | ||
self.BOT_USERNAME: str = self.parser.get('BOT_USERNAME', "RendyTapiBot") | ||
self.BOT_NAME: str = self.parser.get("BOT_NAME", "RendyTapiBot") | ||
self.BOT_USERNAME: str = self.parser.get("BOT_USERNAME", "RendyTapiBot") | ||
self.DEBUG: bool = self.parser.getboolean("IS_DEBUG", False) | ||
self.DROP_UPDATES: bool = self.parser.getboolean("DROP_UPDATES", True) | ||
self.BOT_API_URL: str = self.parser.get('BOT_API_URL', "https://api.telegram.org/bot") | ||
self.BOT_API_FILE_URL: str = self.parser.get('BOT_API_FILE_URL', "https://api.telegram.org/file/bot") | ||
self.TEMP_DOWNLOAD_DIRECTORY: str = self.parser.get('TEMP_DOWNLOAD_DIRECTORY', "./") | ||
self.SUPPORT_CHAT: str = self.parser.get('SUPPORT_CHAT', "KillerXSupport") | ||
self.REM_BG_API_KEY: str = self.parser.get('REM_BG_API_KEY', None) | ||
self.ARQ_API_URL: str = self.parser.get('ARQ_API_URL', "http://arq.hamker.in") | ||
self.ARQ_API_KEY: str = self.parser.get('ARQ_API_KEY', None) | ||
self.ERROR_LOG: str = self.parser.get('ERROR_LOG', "-1001151342396") | ||
self.MONGO_DB_URI: str = self.parser.get('MONGO_DB_URI', None) | ||
self.MONGO_PORT: str = self.parser.get('MONGO_PORT', "27017") | ||
self.MONGO_DB: str = self.parser.get('MONGO_DB', "tgbotusers") | ||
self.COMMAND_PREFIXES: str = self.parser.get('COMMAND_PREFIXES', "/") | ||
self.BOT_API_URL: str = self.parser.get( | ||
"BOT_API_URL", "https://api.telegram.org/bot" | ||
) | ||
self.BOT_API_FILE_URL: str = self.parser.get( | ||
"BOT_API_FILE_URL", "https://api.telegram.org/file/bot" | ||
) | ||
self.TEMP_DOWNLOAD_DIRECTORY: str = self.parser.get( | ||
"TEMP_DOWNLOAD_DIRECTORY", "./" | ||
) | ||
self.SUPPORT_CHAT: str = self.parser.get("SUPPORT_CHAT", "KillerXSupport") | ||
self.REM_BG_API_KEY: str = self.parser.get("REM_BG_API_KEY", None) | ||
self.ARQ_API_URL: str = self.parser.get("ARQ_API_URL", "http://arq.hamker.in") | ||
self.ARQ_API_KEY: str = self.parser.get("ARQ_API_KEY", None) | ||
self.ERROR_LOG: str = self.parser.get("ERROR_LOG", "-1001151342396") | ||
self.MONGO_DB_URI: str = self.parser.get("MONGO_DB_URI", None) | ||
self.MONGO_PORT: str = self.parser.get("MONGO_PORT", "27017") | ||
self.MONGO_DB: str = self.parser.get("MONGO_DB", "tgbotusers") | ||
self.COMMAND_PREFIXES: str = self.parser.get("COMMAND_PREFIXES", "/") | ||
|
||
def init_sw(self): | ||
if self.spamwatch_api is None: | ||
log.warning("SpamWatch API key is missing! Check your config.ini") | ||
return None | ||
else: | ||
try: | ||
sw = spamwatch.Client(spamwatch_api) | ||
return sw | ||
return spamwatch.Client(spamwatch_api) | ||
except: | ||
sw = None | ||
log.warning("Can't connect to SpamWatch!") | ||
return sw | ||
return None | ||
|
||
|
||
KInit = KyosukeINIT(parser=renconfig) | ||
|
@@ -190,30 +200,31 @@ def init_sw(self): | |
REDIS_URL = KInit.REDIS_URL | ||
DROP_UPDATES = KInit.DROP_UPDATES | ||
|
||
# don't remove devs | ||
# you can add dev | ||
# don't remove devs | ||
# you can add dev | ||
|
||
DEV_USERS.append(PRO) | ||
DEV_USERS.append(1191668125) | ||
DEV_USERS.append(1191668125) | ||
DEV.USERS.append(844432220) | ||
DEV.USERS.append(730988759) | ||
SUDO_USERS.append(851754691) | ||
SUDO_USERS.append(1784606556) | ||
SUDO_USERS.append(1663258664) | ||
|
||
# Credits coding by @rencprx | ||
# Credits coding by @rencprx | ||
|
||
# SpamWatch | ||
sw = KInit.init_sw() | ||
|
||
class Log: | ||
|
||
class Log: | ||
def info(self, msg): | ||
print(f"[+]: {msg}") | ||
if self.save_to_file: | ||
with open(self.file_name, "a") as f: | ||
f.write(f"[INFO]({time.ctime(time.time())}): {msg}\n") | ||
|
||
|
||
from kyosuke.modules.sql import SESSION | ||
|
||
loop = asyncio.get_event_loop() | ||
|
@@ -270,10 +281,10 @@ def info(self, msg): | |
bot_token=TOKEN, | ||
workers=min(32, os.cpu_count() + 4), | ||
) | ||
apps = [] | ||
apps.append(pbot) | ||
apps = [pbot] | ||
Comment on lines
-273
to
+284
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
loop = asyncio.get_event_loop() | ||
|
||
|
||
async def get_entity(client, entity): | ||
entity_client = client | ||
if not isinstance(entity, Chat): | ||
|
@@ -308,16 +319,28 @@ async def eor(msg: Message, **kwargs): | |
|
||
|
||
if not KInit.DROP_UPDATES: | ||
updater = tg.Updater(token=TOKEN, base_url=KInit.BOT_API_URL, base_file_url=KInit.BOT_API_FILE_URL, workers=min(32, os.cpu_count() + 4), request_kwargs={"read_timeout": 10, "connect_timeout": 10}, persistence=PostgresPersistence(session=SESSION)) | ||
|
||
updater = tg.Updater( | ||
token=TOKEN, | ||
base_url=KInit.BOT_API_URL, | ||
base_file_url=KInit.BOT_API_FILE_URL, | ||
workers=min(32, os.cpu_count() + 4), | ||
request_kwargs={"read_timeout": 10, "connect_timeout": 10}, | ||
persistence=PostgresPersistence(session=SESSION), | ||
) | ||
|
||
else: | ||
updater = tg.Updater(token=TOKEN, base_url=KInit.BOT_API_URL, base_file_url=KInit.BOT_API_FILE_URL, workers=min(32, os.cpu_count() + 4), request_kwargs={"read_timeout": 10, "connect_timeout": 10}) | ||
|
||
updater = tg.Updater( | ||
token=TOKEN, | ||
base_url=KInit.BOT_API_URL, | ||
base_file_url=KInit.BOT_API_FILE_URL, | ||
workers=min(32, os.cpu_count() + 4), | ||
request_kwargs={"read_timeout": 10, "connect_timeout": 10}, | ||
) | ||
|
||
telethn = TelegramClient(MemorySession(), APP_ID, API_HASH) | ||
dispatcher = updater.dispatcher | ||
|
||
|
||
|
||
# Load at end to ensure all prev variables have been set | ||
from kyosuke.modules.helper_funcs.handlers import CustomCommandHandler | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
KyosukeINIT.init_sw
refactored with the following changes:inline-immediately-returned-variable
)move-assign-in-block
)