OneBotConnecter 0.3.12__tar.gz → 0.3.13__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: OneBotConnecter
3
- Version: 0.3.12
3
+ Version: 0.3.13
4
4
  Summary: 基于websocket(服务器正向)连接的onebot11通用python接口
5
5
  Author-email: Sugar51243 <1733682365@qq.com>
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "OneBotConnecter"
7
- version = "0.3.12"
7
+ version = "0.3.13"
8
8
  authors = [
9
9
  { name="Sugar51243", email="1733682365@qq.com" },
10
10
  ]
@@ -100,6 +100,50 @@ class OneBot:
100
100
  except Exception: pass
101
101
  await asyncio.sleep(sleep_time)
102
102
 
103
+ #建立连接 (WS正向) == #初次连接
104
+ async def non_async_run(self, on_message: __module__ = _on_message, sleep_time: int = 1):
105
+ print("正在建立初次连接...", needPrint=False)
106
+ #直到连接成功为止,持续尝试连接
107
+ while self.bot == None:
108
+ try: self.bot = await websockets.connect(self._uri)
109
+ except: await asyncio.sleep(1)
110
+ #更新连接状态
111
+ if self.bot != None:
112
+ self.bot = await websockets.connect(self._uri)
113
+ message = await self.bot.recv() #测试接口可用性
114
+ print(f"地址{self._uri}连接已完成")
115
+ callback = await self.get_login_info() #更新机器人本体信息
116
+ if callback == None:
117
+ print(f"地址{self._uri}连接中断")
118
+ print("正在尝试重连")
119
+ await self.run(on_message = on_message, sleep_time = sleep_time)
120
+ return
121
+ print(f"机器人账号: {self.botAcc}")
122
+ print(f"机器人名称: {self.botName}")
123
+ if self.owner != None: print(f"机器人管理员: {self.owner}")
124
+ if self.localtion != None: print(f"机器人根目录地址: {self.localtion}")
125
+ print(f"开始监听机器人信息推送\n")
126
+ while True:
127
+ #连接失败 => 直到连接成功为止,持续尝试重连
128
+ if self.bot == None:
129
+ try:
130
+ self.bot = await websockets.connect(self._uri)
131
+ print("重连成功\n")
132
+ except:
133
+ print("连接失败,5秒后重试\n")
134
+ await asyncio.sleep(5)
135
+ #连接正常
136
+ if self.bot != None:
137
+ #从接口收取信息,并进行信息处理
138
+ try:
139
+ await self._receive_messages(on_message)
140
+ #报错处理
141
+ except Exception as e:
142
+ tb = e.__traceback__
143
+ formatted_tb = ''.join(traceback.format_tb(tb))
144
+ print(f"接口处理报错:\n{formatted_tb}", needPrint=self.testMode)
145
+ await asyncio.sleep(sleep_time)
146
+
103
147
  #收到信息时
104
148
  async def _receive_messages(self, callback: __module__):
105
149
  #连接正常
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: OneBotConnecter
3
- Version: 0.3.12
3
+ Version: 0.3.13
4
4
  Summary: 基于websocket(服务器正向)连接的onebot11通用python接口
5
5
  Author-email: Sugar51243 <1733682365@qq.com>
6
6
  License: MIT License