Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/core/elements/others/__init__.py

79 lines
2.1 KiB
Python
Raw Normal View History

2021-10-14 15:29:45 +00:00
import os
2022-01-20 12:13:03 +00:00
import traceback
2021-12-31 14:44:34 +00:00
from configparser import ConfigParser
from os.path import abspath
import requests
2021-10-14 15:29:45 +00:00
2022-01-14 09:51:17 +00:00
from core.exceptions import ConfigFileNotFound
2021-07-30 18:06:04 +00:00
confirm_command = ["", "", '确定', '是吧', '大概是',
2021-08-07 07:56:48 +00:00
'也许', '可能', '对的', '是呢', '对呢', '', '嗯呢',
'吼啊', '资瓷', '是呗', '也许吧', '对呗', '应该',
'yes', 'y', 'yeah', 'yep', 'ok', 'okay', '', '']
2021-08-19 12:17:48 +00:00
2021-08-23 12:44:31 +00:00
command_prefix = ['~', ''] # 消息前缀
2021-10-11 14:45:28 +00:00
class EnableDirtyWordCheck:
status = False
2021-10-14 15:29:45 +00:00
class PrivateAssets:
path = os.path.abspath('.')
@staticmethod
def set(path):
path = os.path.abspath(path)
if not os.path.exists(path):
os.mkdir(path)
PrivateAssets.path = path
2021-12-31 14:44:34 +00:00
class Secret:
list = []
@staticmethod
def add(secret):
Secret.list.append(secret)
class ErrorMessage:
def __init__(self, error_message):
self.error_message = '发生错误:' + error_message \
+ '\n错误汇报地址https://github.com/Teahouse-Studios/bot/issues/new?assignees=OasisAkari&labels=bug&template=report_bug.yaml&title=%5BBUG%5D%3A+'
def __str__(self):
return self.error_message
def __repr__(self):
return self.error_message
def load_secret():
config_filename = 'config.cfg'
config_path = abspath('./config/' + config_filename)
cp = ConfigParser()
cp.read(config_path)
2022-01-14 09:32:45 +00:00
section = cp.sections()
if len(section) == 0:
2022-01-14 09:51:17 +00:00
raise ConfigFileNotFound(config_path) from None
2022-01-14 09:32:45 +00:00
section = section[0]
2021-12-31 14:44:34 +00:00
options = cp.options(section)
for option in options:
value = cp.get(section, option)
if value != '':
Secret.add(value.upper())
try:
ip = requests.get('https://api.ip.sb/ip', timeout=10)
if ip:
Secret.add(ip.text.replace('\n', ''))
except:
traceback.print_exc()
pass
load_secret()
__all__ = ["confirm_command", "command_prefix", "EnableDirtyWordCheck", "PrivateAssets", "Secret", "ErrorMessage"]