Added self.config
This commit is contained in:
parent
f8b21093a4
commit
0cfe55d3c9
@ -1,11 +1,11 @@
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
from os import getpid
|
||||
from pathlib import Path
|
||||
from time import time
|
||||
from typing import List, Union
|
||||
|
||||
import pyrogram
|
||||
from libbot import config_get
|
||||
from libbot.i18n import BotLocale
|
||||
from libbot.i18n.sync import _
|
||||
from pyrogram.client import Client
|
||||
@ -34,26 +34,26 @@ logger = logging.getLogger(__name__)
|
||||
class PyroClient(Client):
|
||||
def __init__(self):
|
||||
with open("config.json", "r", encoding="utf-8") as f:
|
||||
config = loads(f.read())
|
||||
self.config: dict = loads(f.read())
|
||||
super().__init__(
|
||||
name="bot_client",
|
||||
api_id=config["bot"]["api_id"],
|
||||
api_hash=config["bot"]["api_hash"],
|
||||
bot_token=config["bot"]["bot_token"],
|
||||
api_id=self.config["bot"]["api_id"],
|
||||
api_hash=self.config["bot"]["api_hash"],
|
||||
bot_token=self.config["bot"]["bot_token"],
|
||||
# Workers should be commented when using convopyro, otherwise
|
||||
# handlers land in another event loop and you won't see them
|
||||
workers=config["bot"]["workers"],
|
||||
plugins=dict(root="plugins", exclude=config["disabled_plugins"]),
|
||||
workers=self.config["bot"]["workers"],
|
||||
plugins=dict(root="plugins", exclude=self.config["disabled_plugins"]),
|
||||
sleep_threshold=120,
|
||||
)
|
||||
self.owner = config["bot"]["owner"]
|
||||
self.owner: int = self.config["bot"]["owner"]
|
||||
self.commands: List[PyroCommand] = []
|
||||
self.scoped_commands = config["bot"]["scoped_commands"]
|
||||
self.start_time = 0
|
||||
self.scoped_commands: bool = self.config["bot"]["scoped_commands"]
|
||||
self.start_time: float = 0
|
||||
|
||||
self.bot_locale = BotLocale(config["locations"]["locale"])
|
||||
self.default_locale = self.bot_locale.default
|
||||
self.locales = self.bot_locale.locales
|
||||
self.bot_locale: BotLocale = BotLocale(Path(self.config["locations"]["locale"]))
|
||||
self.default_locale: str = self.bot_locale.default
|
||||
self.locales: dict = self.bot_locale.locales
|
||||
|
||||
self._ = self.bot_locale._
|
||||
self.in_all_locales = self.bot_locale.in_all_locales
|
||||
@ -74,7 +74,7 @@ class PyroClient(Client):
|
||||
|
||||
try:
|
||||
await self.send_message(
|
||||
chat_id=await config_get("chat_id", "reports"),
|
||||
chat_id=self.config["reports"]["chat_id"],
|
||||
text=f"Bot started PID `{getpid()}`",
|
||||
)
|
||||
|
||||
@ -92,7 +92,7 @@ class PyroClient(Client):
|
||||
async def stop(self):
|
||||
try:
|
||||
await self.send_message(
|
||||
chat_id=await config_get("chat_id", "reports"),
|
||||
chat_id=self.config["reports"]["chat_id"],
|
||||
text=f"Bot stopped with PID `{getpid()}`",
|
||||
)
|
||||
except BadRequest:
|
||||
@ -108,14 +108,14 @@ class PyroClient(Client):
|
||||
"""
|
||||
command_sets = None
|
||||
|
||||
# If config get bot.scoped_commands is true - more complicated
|
||||
# If config's bot.scoped_commands is true - more complicated
|
||||
# scopes system will be used instead of simple global commands
|
||||
if self.scoped_commands:
|
||||
scopes = {}
|
||||
command_sets = []
|
||||
|
||||
# Iterate through all commands in config
|
||||
for command, contents in (await config_get("commands")).items():
|
||||
for command, contents in self.config["commands"].items():
|
||||
# Iterate through all scopes of a command
|
||||
for scope in contents["scopes"]:
|
||||
if dumps(scope) not in scopes:
|
||||
|
Reference in New Issue
Block a user