From 954cbc837a517162609034a8c20ec3bc1c3f36dc Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Thu, 20 May 2021 17:40:17 +0800 Subject: [PATCH] Add files via upload --- services/db_context.py | 27 +++++++ services/init_config.py | 159 ++++++++++++++++++++++++++++++++++++++++ services/log.py | 30 ++++++++ 3 files changed, 216 insertions(+) create mode 100644 services/db_context.py create mode 100644 services/init_config.py create mode 100644 services/log.py diff --git a/services/db_context.py b/services/db_context.py new file mode 100644 index 00000000..29287a9b --- /dev/null +++ b/services/db_context.py @@ -0,0 +1,27 @@ + + +from gino import Gino +from .log import logger +from configs.config import bind, sql_name, user, password, address, port, database + + +# 全局数据库连接对象 +db = Gino() + + +async def init(): + i_bind = bind + if not bind: + i_bind = f"{sql_name}://{user}:{password}@{address}:{port}/{database}" + # print(i_bind) + try: + await db.set_bind(i_bind) + await db.gino.create_all() + logger.info(f'Database loaded successfully!') + except Exception as e: + raise Exception(f'数据库连接错误.... e: {e}') + + +async def disconnect(): + await db.pop_bind().close() + diff --git a/services/init_config.py b/services/init_config.py new file mode 100644 index 00000000..20974f75 --- /dev/null +++ b/services/init_config.py @@ -0,0 +1,159 @@ +# import nonebot +from pathlib import Path +try: + import ujson as json +except ModuleNotFoundError: + import json + +# driver: nonebot.Driver = nonebot.get_driver() + +base_config = Path() / 'config.json' +plugins_cmd_config = Path() / 'configs' / 'plugins2cmd_config.json' +other_config = Path() / 'configs' / 'other_config.json' + + +def init_config(): + if not base_config.exists(): + base_config.parent.mkdir(parents=True, exist_ok=True) + config_dict = { + 'path': { + 'IMAGE_PATH': '', + 'VOICE_PATH': '', + 'TXT_PATH': '', + 'LOG_PATH': '', + 'DATA_PATH': '', + 'DRAW_PATH': '', + 'TEMP_PATH': '', + }, + 'proxy': { + 'system_proxy': '', + 'buff_proxy': '' + }, + 'apikey': { + 'LOLICON_KEY': '', + 'TL_KEY': [], + }, + 'rsshub': { + 'RSSHUBAPP': 'https://docs.rsshub.app/', + }, + 'sql': { + 'bind': '', + 'sql_name': '', + 'user': '', + 'password': '', + 'address': '', + 'port': '', + 'database': '', + }, + 'level': { + 'DELETE_IMG_LEVEL': 7, + 'MOVE_IMG_LEVEL': 7, + 'UPLOAD_LEVEL': 6, + 'BAN_LEVEL': 5, + 'OC_LEVEL': 2, + 'MUTE_LEVEL': 5, + }, + } + with open(base_config, 'w', encoding='utf8') as f: + json.dump(config_dict, f, indent=4, ensure_ascii=False) + if not plugins_cmd_config.exists(): + plugins_cmd_config.parent.mkdir(parents=True, exist_ok=True) + config_dict = { + 'base_config': { + 'sign_in': ['签到'], + 'send_img': ['发送图片', '萝莉', '美图', '壁纸'], + 'send_setu': ['色图', '涩图', '瑟图', '查色图'], + 'white2black': ['黑白图', '黑白草图'], + 'coser': ['coser', 'cos'], + 'quotations': ['语录'], + 'jitang': ['鸡汤'], + 'send_dinggong_voice': ['骂我', '骂老子', '骂劳资'], + 'open_cases': ['开箱', '我的开箱', '群开箱统计', '我的金色'], + 'luxun': ['鲁迅说过', '鲁迅说'], + 'fake_msg': ['假消息'], + 'buy': ['购买', '购买道具'], + 'my_gold': ['我的金币'], + 'my_props': ['我的道具'], + 'shop_help': ['商店'], + 'nonebot_plugin_cocdicer': ['骰子娘'], + 'update_pic': ['图片', '操作图片', '修改图片'], + 'search_buff_skin_price': ['查询皮肤'], + 'weather': ['天气', '查询天气', '天气查询'], + 'yiqing': ['疫情', '疫情查询', '查询疫情'], + 'what_anime': ['识番'], + 'search_anime': ['搜番'], + 'songpicker2': ['点歌'], + 'epic': ['epic'], + 'pixiv': ['pixiv', 'p站排行', '搜图'], + 'poke': ['戳一戳'], + 'draw_card': ['游戏抽卡', '原神一井', '原神来一井', '方舟一井', '方舟来一井'], + 'ai': ['ai', 'Ai', 'AI', 'aI'], + 'one_friend': ['我有一个朋友', '我有一个朋友想问问'], + 'translate': ['翻译', '英翻', '翻英', '日翻', '翻日', '韩翻', '翻韩'], + 'nonebot_plugin_picsearcher': ['识图'], + 'almanac': ['原神黄历', '黄历'], + 'material_remind': ['今日素材', '天赋材料'], + 'qiu_qiu_translation': ['丘丘翻译', '丘丘一下', '丘丘语翻译'], + 'query_resource_points': ['原神资源查询', '原神资源列表'], + } + } + with open(plugins_cmd_config, 'w', encoding='utf8') as f: + json.dump(config_dict, f, indent=4, ensure_ascii=False) + if not other_config.exists(): + other_config.parent.mkdir(parents=True, exist_ok=True) + config_dict = { + 'base': { + 'IMAGE_DIR_LIST': ["色图", "美图", "萝莉", "壁纸"], + 'BAN_RESULT': "才不会给你发消息.", + }, + 'bool': { + 'AUTO_ADD_FRIEND': True, + 'DOWNLOAD_SETU': True, + }, + 'probability': { + 'INITIAL_SETU_PROBABILITY': 0.7, + 'FUDU_PROBABILITY': 0.7, + }, + 'max_count': { + 'MAXINFO_REIMU': 7, + 'COUNT_PER_DAY_REIMU': 5, + 'MAXINFO_BT': 10, + 'MAXINFO_PRIVATE_ANIME': 20, + 'MAXINFO_GROUP_ANIME': 5, + 'MAX_FIND_IMG_COUNT': 3, + 'MAX_SIGN_GOLD': 200, + }, + 'malicious_ban': { + 'MALICIOUS_BAN_TIME': 30, + 'MALICIOUS_BAN_COUNT': 4, + 'MALICIOUS_CHECK_TIME': 5, + }, + 'open_case': { + 'INITIAL_OPEN_CASE_COUNT': 20, + }, + 'mute': { + 'MUTE_DEFAULT_COUNT': 10, + 'MUTE_DEFAULT_TIME': 7, + 'MUTE_DEFAULT_DURATION': 10, + }, + 'other': { + 'UPDATE_GOCQ_GROUP': [], + 'ADMIN_DEFAULT_AUTH': 5, + }, + 'auth': { + 'admin_plugins_auth': { + "admin_bot_manage": 2, + "ban": 5, + "delete_img": 7, + "move_img": 7, + "upload_img": 6, + "admin_help": 1, + "mute": 5 + } + }, + } + with open(other_config, 'w', encoding='utf8') as f: + json.dump(config_dict, f, indent=4, ensure_ascii=False) + + + diff --git a/services/log.py b/services/log.py new file mode 100644 index 00000000..b45763e9 --- /dev/null +++ b/services/log.py @@ -0,0 +1,30 @@ +import logging +from datetime import datetime +from configs.path_config import LOG_PATH + +# CRITICAL 50 +# ERROR 40 +# WARNING 30 +# INFO 20 +# DEBUG 10 +# NOTSET 0 + +# _handler = logging.StreamHandler(sys.stdout) +# _handler.setFormatter( +# logging.Formatter('[%(asctime)s %(name)s] %(levelname)s: %(message)s') +# ) +logger = logging.getLogger('hibiki') +logger.setLevel(level=logging.DEBUG) + +formatter = logging.Formatter('[%(asctime)s] - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s') +# print(LOG_PATH) +file_handler = logging.FileHandler(LOG_PATH + str((datetime.now()).date()) + '.log', mode='a', encoding='utf-8') +file_handler.setLevel(level=logging.INFO) +file_handler.setFormatter(formatter) + +stream_handler = logging.StreamHandler() +stream_handler.setLevel(logging.INFO) +stream_handler.setFormatter(formatter) + +logger.addHandler(file_handler) +logger.addHandler(stream_handler)