Skip to content

Commit

Permalink
feat: 完成gateway的部分数据类的替换为字典类型
Browse files Browse the repository at this point in the history
  • Loading branch information
veehou committed May 18, 2022
1 parent dafc1bd commit d1d1fd4
Show file tree
Hide file tree
Showing 38 changed files with 123 additions and 595 deletions.
3 changes: 1 addition & 2 deletions botpy/__init__.py
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from .api import *
from .client import *
from .core.network.ws.ws_intents_handler import HandlerType, Handler
from .core.util import logging
from . import logging
from .flags import *
from .model import *

Expand Down
28 changes: 2 additions & 26 deletions botpy/api.py
@@ -1,14 +1,12 @@
# -*- coding: utf-8 -*-

# 异步api
import asyncio
import json
from json import JSONDecodeError
from typing import List

from .core.network.url import get_url, APIConstant
from .core.network.ws.ws_intents_handler import Handler, register_handlers
from .core.util.json_util import JsonUtil
from botpy.url import get_url, APIConstant
from botpy.utils import JsonUtil
from .http import AsyncHttp
from .model.announce import (
CreateAnnounceRequest,
Expand Down Expand Up @@ -68,28 +66,6 @@
from .model.user import ReqOption


def async_listen_events(t_token: Token, is_sandbox: bool, *handlers: Handler, ret_coro=False):
"""异步注册并监听频道相关事件
:param t_token: Token对象
:param handlers: 包含事件类型和事件回调的Handler对象,支持多个对象
:param is_sandbox:是否沙盒环境,默认为False
:param ret_coro: 是否返回协程对象
保留 `qq-bot` 版本 < 1.0.0 的使用方法
"""
# 通过api获取websocket链接
ws_api = AsyncWebsocketAPI(t_token, is_sandbox)
ws_ap = asyncio.run(ws_api.ws())
# 新建和注册监听事件
t_intent = register_handlers(handlers)
# 实例一个session_manager
from botpy import SessionManager

manager = SessionManager(ret_coro=ret_coro)
return manager.start(ws_ap, t_token.bot_token(), t_intent)


class AsyncAPIBase:
def __init__(self, token: Token, is_sandbox: bool = False, timeout: int = 3):
"""
Expand Down
19 changes: 9 additions & 10 deletions botpy/client.py
Expand Up @@ -4,9 +4,8 @@
from types import TracebackType
from typing import Any, Callable, Coroutine, Dict, List, Tuple, Optional, Type

from . import logging
from .api import AsyncWebsocketAPI
from .core.network.ws.ws_session import Session, ShardConfig
from .core.util import logging
from .flags import Intents
from .gateway import BotWebSocket
from .model import Token
Expand Down Expand Up @@ -162,14 +161,14 @@ async def _pool_init(self, token, session_interval):
loop=asyncio.get_event_loop(),
)
for i in range(self._ws_ap["shards"]):
session = Session(
session_id="",
url=self._ws_ap["url"],
intent=self.intents,
last_seq=0,
token=token,
shards=ShardConfig(i, self._ws_ap["shards"]),
)
session = {
"session_id": "",
"last_seq": 0,
"intent": self.intents,
"token": token,
"url": self._ws_ap["url"],
"shards": {"shard_id": i, "shard_count": self._ws_ap["shards"]},
}
self._connection.add(session)

loop = self._connection._loop
Expand Down
1 change: 0 additions & 1 deletion botpy/core/__init__.py

This file was deleted.

Empty file removed botpy/core/exception/__init__.py
Empty file.
Empty file removed botpy/core/network/__init__.py
Empty file.
1 change: 0 additions & 1 deletion botpy/core/network/ws/__init__.py

This file was deleted.

Empty file.
43 changes: 0 additions & 43 deletions botpy/core/network/ws/dto/enum_intents.py

This file was deleted.

34 changes: 0 additions & 34 deletions botpy/core/network/ws/dto/ws_payload.py

This file was deleted.

72 changes: 0 additions & 72 deletions botpy/core/network/ws/ws_event.py

This file was deleted.

57 changes: 0 additions & 57 deletions botpy/core/network/ws/ws_handler.py

This file was deleted.

0 comments on commit d1d1fd4

Please sign in to comment.