diff --git a/setup.py b/setup.py index 8b2a88d..cc4bdab 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ import os import sys from shutil import rmtree -from utils.version import __version__ +from src.utils.version import __version__ from setuptools import setup, Command @@ -96,7 +96,7 @@ def run(self): author_email=EMAIL, python_requires=REQUIRES_PYTHON, url=URL, - packages=['api', 'core', 'utils', 'main'], + packages=['src', 'src/api', 'src/core', 'src/utils'], # If your package is a single module, use this instead of 'packages': # py_modules=['mypackage'], @@ -122,7 +122,7 @@ def run(self): }, entry_points={ 'console_scripts': [ - 'pwl-chat-python = main.main:cli', + 'pwl-chat-python = src.main:cli', ], } diff --git a/api/__api__.py b/src/api/__api__.py similarity index 100% rename from api/__api__.py rename to src/api/__api__.py diff --git a/api/__init__.py b/src/api/__init__.py similarity index 96% rename from api/__init__.py rename to src/api/__init__.py index 341d5c5..4247643 100644 --- a/api/__init__.py +++ b/src/api/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -from api.chatroom import ChatRoom -from utils.utils import UA, HOST +from .chatroom import ChatRoom +from src.utils.utils import UA, HOST from .__api__ import Base from .user import User import sys diff --git a/api/chatroom.py b/src/api/chatroom.py similarity index 95% rename from api/chatroom.py rename to src/api/chatroom.py index 7bb0096..a7825b4 100644 --- a/api/chatroom.py +++ b/src/api/chatroom.py @@ -1,8 +1,8 @@ import requests import json import random -from utils.utils import UA, HOST -from utils.version import __version__ +from src.utils.utils import UA, HOST +from src.utils.version import __version__ from .__api__ import Base diff --git a/api/user.py b/src/api/user.py similarity index 96% rename from api/user.py rename to src/api/user.py index 5346196..4037c21 100644 --- a/api/user.py +++ b/src/api/user.py @@ -2,7 +2,7 @@ import requests import json -from utils.utils import UA, HOST +from src.utils.utils import UA, HOST from .__api__ import Base diff --git a/core/__init__.py b/src/core/__init__.py similarity index 64% rename from core/__init__.py rename to src/core/__init__.py index 3803719..7a51379 100644 --- a/core/__init__.py +++ b/src/core/__init__.py @@ -1,29 +1,40 @@ import json -from api import FishPi -from core.chatroom import init_soliloquize -from core.cli import init_sys_in -from core.config import GLOBAL_CONFIG, RedPacketConfig, AuthConfig, RepeatConfig +from src.api import FishPi +from .chatroom import init_soliloquize +from .cli import init_sys_in +from .config import GLOBAL_CONFIG, RedPacketConfig, AuthConfig, RepeatConfig import configparser import os -import sys def __init__(api: FishPi): + file_path = f'{os.getcwd()}/config.ini' config = configparser.ConfigParser() try: print("配置读取中") - config.read(f'{os.getcwd()}/config.ini', encoding='utf-8') - GLOBAL_CONFIG.auth_config = __init_login_auth_config(config) - GLOBAL_CONFIG.redpacket_config = __int_redpacket_var(config) - GLOBAL_CONFIG.repeat_config = __init_repeat_config(config) + if not os.path.exists(file_path): + print("config.ini配置文件不存在") + __init_default_config() + else: + config.read(file_path, encoding='utf-8') + GLOBAL_CONFIG.auth_config = __init_login_auth_config(config) + GLOBAL_CONFIG.redpacket_config = __int_redpacket_var(config) + GLOBAL_CONFIG.repeat_config = __init_repeat_config(config) except: - print("请检查config.ini配置文件是否合法") - sys.exit(1) + print("config.ini配置文件不合法") + __init_default_config() init_soliloquize(api) init_sys_in(api) +def __init_default_config(): + print("加载默认配置文件") + GLOBAL_CONFIG.auth_config = AuthConfig() + GLOBAL_CONFIG.redpacket_config = RedPacketConfig() + GLOBAL_CONFIG.repeat_config = RepeatConfig() + + def __int_redpacket_var(config) -> RedPacketConfig: ret = RedPacketConfig() if config.getint('redPacket', 'rate') > 0: diff --git a/core/blacklist.py b/src/core/blacklist.py similarity index 96% rename from core/blacklist.py rename to src/core/blacklist.py index db4af14..68b5270 100644 --- a/core/blacklist.py +++ b/src/core/blacklist.py @@ -1,8 +1,8 @@ import os import re -from api import FishPi -from core.config import GLOBAL_CONFIG +from src.api import FishPi +from .config import GLOBAL_CONFIG def unban_someone(api: FishPi, username): diff --git a/core/chatroom.py b/src/core/chatroom.py similarity index 94% rename from core/chatroom.py rename to src/core/chatroom.py index 110fb3d..19f6d71 100644 --- a/core/chatroom.py +++ b/src/core/chatroom.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- import random import schedule -from api import FishPi -from core.config import GLOBAL_CONFIG -from core.redpacket import rush_redpacket +from src.api import FishPi +from .config import GLOBAL_CONFIG +from .redpacket import rush_redpacket REPEAT_POOL = {} # 复读池 diff --git a/core/cli.py b/src/core/cli.py similarity index 94% rename from core/cli.py rename to src/core/cli.py index 6f0adf6..3cfd74b 100644 --- a/core/cli.py +++ b/src/core/cli.py @@ -1,8 +1,8 @@ import _thread -from core.blacklist import * -from core.config import GLOBAL_CONFIG -from core.user import * -from utils.utils import * +from .blacklist import * +from .config import GLOBAL_CONFIG +from .user import * +from src.utils.utils import * diff --git a/core/config.py b/src/core/config.py similarity index 90% rename from core/config.py rename to src/core/config.py index 6048752..69643d9 100644 --- a/core/config.py +++ b/src/core/config.py @@ -1,6 +1,6 @@ class RedPacketConfig(object): - def __init__(self, red_packet_switch=True, heartbeat=False, smart_mode=False, threshold=0.5, adventure_mode=False, - timeout=5, rate=3): + def __init__(self, red_packet_switch=True, heartbeat=True, smart_mode=True, threshold=0.5, adventure_mode=True, + timeout=7, rate=3): self.red_packet_switch = red_packet_switch self.heartbeat = heartbeat self.smart_mode = smart_mode diff --git a/core/redpacket.py b/src/core/redpacket.py similarity index 98% rename from core/redpacket.py rename to src/core/redpacket.py index 163cd87..297940f 100644 --- a/core/redpacket.py +++ b/src/core/redpacket.py @@ -1,8 +1,8 @@ -from api import FishPi +from src.api import FishPi import json import time -from core.config import GLOBAL_CONFIG +from .config import GLOBAL_CONFIG def __open_redpacket_render(username, redpacket: dict) -> None: diff --git a/core/user.py b/src/core/user.py similarity index 93% rename from core/user.py rename to src/core/user.py index eb64cf5..a31e764 100644 --- a/core/user.py +++ b/src/core/user.py @@ -1,9 +1,9 @@ import time -from api import FishPi -from utils.utils import * -from core.config import GLOBAL_CONFIG +from src.api import FishPi +from src.utils.utils import * +from .config import GLOBAL_CONFIG def render_user_info(userInfo): diff --git a/core/websocket.py b/src/core/websocket.py similarity index 92% rename from core/websocket.py rename to src/core/websocket.py index ef49578..db75db9 100644 --- a/core/websocket.py +++ b/src/core/websocket.py @@ -6,9 +6,9 @@ import websocket import _thread -from api import FishPi -from core.chatroom import listener -from core.config import GLOBAL_CONFIG +from src.api import FishPi +from .chatroom import listener +from .config import GLOBAL_CONFIG __api = FishPi() def on_message(ws, message): diff --git a/main/main.py b/src/main.py similarity index 77% rename from main/main.py rename to src/main.py index 1ff9a3f..c97bcaa 100644 --- a/main/main.py +++ b/src/main.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- import click -from api import FishPi -from core import __init__ -from core.config import GLOBAL_CONFIG, AuthConfig -from core.user import login -from core.websocket import start -from utils.version import __version__ +from src.core import __init__ +from src.core.config import GLOBAL_CONFIG, AuthConfig +from src.core.user import login +from src.core.websocket import start +from src.utils.version import __version__ +from src.api import FishPi def run(params: dict): diff --git a/utils/utils.py b/src/utils/utils.py similarity index 100% rename from utils/utils.py rename to src/utils/utils.py diff --git a/src/utils/version.py b/src/utils/version.py new file mode 100644 index 0000000..facc209 --- /dev/null +++ b/src/utils/version.py @@ -0,0 +1 @@ +__version__ = "1.3.9" \ No newline at end of file diff --git a/utils/version.py b/utils/version.py deleted file mode 100644 index a5f268b..0000000 --- a/utils/version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "1.3.5" \ No newline at end of file