From 80db71602b92efaecb62e9793ecbe1c69bd10687 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Thu, 24 Jun 2021 11:39:06 -0600 Subject: [PATCH] A little refactoring --- src/config.py | 25 +++++++++++++++++++++++++ src/jarvis.py | 26 +------------------------- 2 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 src/config.py diff --git a/src/config.py b/src/config.py new file mode 100644 index 0000000..85f93f0 --- /dev/null +++ b/src/config.py @@ -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) diff --git a/src/jarvis.py b/src/jarvis.py index 90291a5..841eff8 100644 --- a/src/jarvis.py +++ b/src/jarvis.py @@ -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"]