A little refactoring
This commit is contained in:
parent
355d3963bb
commit
80db71602b
2 changed files with 26 additions and 25 deletions
25
src/config.py
Normal file
25
src/config.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from yaml import load
|
||||||
|
|
||||||
|
try:
|
||||||
|
from yaml import CLoader as Loader
|
||||||
|
except ImportError:
|
||||||
|
from yaml import Loader
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Config:
|
||||||
|
token: str
|
||||||
|
client_id: str
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_yaml(cls, y):
|
||||||
|
instance = cls(token=y["token"], client_id=y["client_id"])
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
def get_config(path: str = "config.yaml") -> Config:
|
||||||
|
with open(path) as f:
|
||||||
|
raw = f.read()
|
||||||
|
y = load(raw, Loader=Loader)
|
||||||
|
return Config.from_yaml(y)
|
|
@ -1,15 +1,9 @@
|
||||||
from discord import Embed, Color, Intents
|
from discord import Embed, Color, Intents
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.utils import find
|
from discord.utils import find
|
||||||
from dataclasses import dataclass
|
|
||||||
from yaml import load
|
|
||||||
from psutil import Process
|
from psutil import Process
|
||||||
from asyncio import sleep
|
from asyncio import sleep
|
||||||
|
from config import get_config
|
||||||
try:
|
|
||||||
from yaml import CLoader as Loader
|
|
||||||
except ImportError:
|
|
||||||
from yaml import Loader
|
|
||||||
|
|
||||||
intents = Intents.default()
|
intents = Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
|
@ -18,24 +12,6 @@ jarvis = commands.Bot(command_prefix=">", intents=intents)
|
||||||
jarvis_self = Process()
|
jarvis_self = Process()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Config:
|
|
||||||
token: str
|
|
||||||
client_id: str
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_yaml(cls, y):
|
|
||||||
instance = cls(token=y["token"], client_id=y["client_id"])
|
|
||||||
return instance
|
|
||||||
|
|
||||||
|
|
||||||
def get_config(path: str = "config.yaml") -> Config:
|
|
||||||
with open(path) as f:
|
|
||||||
raw = f.read()
|
|
||||||
y = load(raw, Loader=Loader)
|
|
||||||
return Config.from_yaml(y)
|
|
||||||
|
|
||||||
|
|
||||||
def convert_bytesize(bytes: int) -> str:
|
def convert_bytesize(bytes: int) -> str:
|
||||||
bytes = float(bytes)
|
bytes = float(bytes)
|
||||||
sizes = ["B", "KB", "MB", "GB"]
|
sizes = ["B", "KB", "MB", "GB"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue