Update
This commit is contained in:
parent
faa672fa7c
commit
cfc84471fd
3 changed files with 13 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from os.path import abspath
|
from os.path import abspath
|
||||||
|
|
||||||
|
from core.exceptions import ConfigFileNotFound
|
||||||
|
|
||||||
config_filename = 'config.cfg'
|
config_filename = 'config.cfg'
|
||||||
config_path = abspath('./config/' + config_filename)
|
config_path = abspath('./config/' + config_filename)
|
||||||
|
|
||||||
|
@ -10,7 +12,10 @@ class CFG:
|
||||||
cp = ConfigParser()
|
cp = ConfigParser()
|
||||||
cp.read(config_path)
|
cp.read(config_path)
|
||||||
try:
|
try:
|
||||||
section = cp.sections()[0]
|
section = cp.sections()
|
||||||
|
if len(section) == 0:
|
||||||
|
raise ConfigFileNotFound(config_path) from None
|
||||||
|
section = section[0]
|
||||||
value = cp.get(section, q)
|
value = cp.get(section, q)
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -5,6 +5,8 @@ import traceback
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from core.exceptions import ConfigFileNotFound
|
||||||
|
|
||||||
confirm_command = ["是", "对", '确定', '是吧', '大概是',
|
confirm_command = ["是", "对", '确定', '是吧', '大概是',
|
||||||
'也许', '可能', '对的', '是呢', '对呢', '嗯', '嗯呢',
|
'也许', '可能', '对的', '是呢', '对呢', '嗯', '嗯呢',
|
||||||
'吼啊', '资瓷', '是呗', '也许吧', '对呗', '应该',
|
'吼啊', '资瓷', '是呗', '也许吧', '对呗', '应该',
|
||||||
|
@ -55,7 +57,7 @@ def load_secret():
|
||||||
cp.read(config_path)
|
cp.read(config_path)
|
||||||
section = cp.sections()
|
section = cp.sections()
|
||||||
if len(section) == 0:
|
if len(section) == 0:
|
||||||
raise Error('Config file not found') from None
|
raise ConfigFileNotFound(config_path) from None
|
||||||
section = section[0]
|
section = section[0]
|
||||||
options = cp.options(section)
|
options = cp.options(section)
|
||||||
for option in options:
|
for option in options:
|
||||||
|
|
|
@ -1,2 +1,6 @@
|
||||||
class AbuseWarning(Exception):
|
class AbuseWarning(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigFileNotFound(Exception):
|
||||||
|
pass
|
||||||
|
|
Reference in a new issue