A little refactoring

This commit is contained in:
Zeva Rose 2021-06-24 11:39:06 -06:00
parent 355d3963bb
commit 80db71602b
2 changed files with 26 additions and 25 deletions

25
src/config.py Normal file
View 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)

View file

@ -1,15 +1,9 @@
from discord import Embed, Color, Intents
from discord.ext import commands
from discord.utils import find
from dataclasses import dataclass
from yaml import load
from psutil import Process
from asyncio import sleep
try:
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
from config import get_config
intents = Intents.default()
intents.members = True
@ -18,24 +12,6 @@ jarvis = commands.Bot(command_prefix=">", intents=intents)
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:
bytes = float(bytes)
sizes = ["B", "KB", "MB", "GB"]