Skip to content

Commit

Permalink
Merge pull request #17 from gakkiyomi/develop
Browse files Browse the repository at this point in the history
package结构
  • Loading branch information
gakkiyomi authored May 9, 2023
2 parents ffe1cdf + b790d79 commit 5a8c39a
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 45 deletions.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'],

Expand All @@ -122,7 +122,7 @@ def run(self):
},
entry_points={
'console_scripts': [
'pwl-chat-python = main.main:cli',
'pwl-chat-python = src.main:cli',
],
}

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions api/__init__.py → src/api/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions api/chatroom.py → src/api/chatroom.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
2 changes: 1 addition & 1 deletion api/user.py → src/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
33 changes: 22 additions & 11 deletions core/__init__.py → src/core/__init__.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions core/blacklist.py → src/core/blacklist.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
6 changes: 3 additions & 3 deletions core/chatroom.py → src/core/chatroom.py
Original file line number Diff line number Diff line change
@@ -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 = {} # 复读池
Expand Down
8 changes: 4 additions & 4 deletions core/cli.py → src/core/cli.py
Original file line number Diff line number Diff line change
@@ -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 *



Expand Down
4 changes: 2 additions & 2 deletions core/config.py → src/core/config.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/redpacket.py → src/core/redpacket.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 3 additions & 3 deletions core/user.py → src/core/user.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
6 changes: 3 additions & 3 deletions core/websocket.py → src/core/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions main/main.py → src/main.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/utils/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.3.9"
1 change: 0 additions & 1 deletion utils/version.py

This file was deleted.

0 comments on commit 5a8c39a

Please sign in to comment.