Пример #1
0
 async def _friend_msg_handler(self, msg):
     context = FriendMsg(msg)
     if self.qq and context.CurrentQQ not in self.qq:
         return
     logger.info(f'{context.__class__.__name__} ->  {context.data}')
     # 黑名单
     if context.FromUin in self.config.friend_blacklist:
         return
     # 屏蔽用户
     if context.FromUin in self.config.blocked_users:
         return
     # 中间件
     if self._friend_context_middlewares:
         for middleware in self._friend_context_middlewares:
             if asyncio.iscoroutinefunction(middleware):
                 new_context = await middleware(context)
             else:
                 new_context = middleware(context)
             if isinstance(new_context, type(context)):
                 context = new_context
             else:
                 return
     context._host = self.config.host
     context._port = self.config.port
     await self._friend_context_distributor(context)
Пример #2
0
 def run(self):
     logger.info('Connecting to the server...')
     try:
         self.socketio.connect(self.config.address, transports=['websocket'])
     except Exception:
         logger.error(traceback.format_exc())
         self.close(1)
     else:
         try:
             self.socketio.wait()
         except KeyboardInterrupt:
             pass
         finally:
             print('bye~')
             self.close(0)
Пример #3
0
 def _event_handler(self, msg):
     context = EventMsg(msg)
     if self.qq and context.CurrentQQ not in self.qq:
         return
     logger.info(f'{context.__class__.__name__} ->  {context.data}')
     # 中间件
     if self._event_context_middlewares:
         for middleware in self._event_context_middlewares:
             new_context = middleware(context)
             if isinstance(new_context, type(context)):
                 context = new_context
             else:
                 return
     context._host = self.config.host
     context._port = self.config.port
     self.pool.submit(self._event_context_distributor, context)
Пример #4
0
 async def _event_handler(self, msg):
     context = EventMsg(msg)
     if self.qq and context.CurrentQQ not in self.qq:
         return
     logger.info(f'{context.__class__.__name__} ->  {context.data}')
     # 中间件
     if self._event_context_middlewares:
         for middleware in self._event_context_middlewares:
             if asyncio.iscoroutinefunction(middleware):
                 new_context = await middleware(context)
             else:
                 new_context = middleware(context)
             if isinstance(new_context, type(context)):
                 context = new_context
             else:
                 return
     context._host = self.config.host
     context._port = self.config.port
     await self._event_context_distributor(context)
Пример #5
0
 def _group_msg_handler(self, msg):
     context = GroupMsg(msg)
     if self.qq and context.CurrentQQ not in self.qq:
         return
     logger.info(f'{context.__class__.__name__} ->  {context.data}')
     # 黑名单
     if context.FromGroupId in self.config.group_blacklist:
         return
     # 屏蔽用户
     if context.FromUserId in self.config.blocked_users:
         return
     # 中间件
     if self._group_context_middlewares:
         for middleware in self._group_context_middlewares:
             new_context = middleware(context)
             if isinstance(new_context, type(context)):
                 context = new_context
             else:
                 return
     context._host = self.config.host
     context._port = self.config.port
     self.pool.submit(self._group_context_distributor, context)
Пример #6
0
 def _friend_msg_handler(self, msg):
     context = FriendMsg(msg)
     if self.qq and context.CurrentQQ not in self.qq:
         return
     logger.info(f'{context.__class__.__name__} ->  {context.data}')
     # 黑名单
     if context.FromUin in self.config.friend_blacklist:
         return
     # 屏蔽用户
     if context.FromUin in self.config.blocked_users:
         return
     # 中间件
     if self._friend_context_middlewares:
         for middleware in self._friend_context_middlewares:
             new_context = middleware(context)
             if isinstance(new_context, type(context)):
                 context = new_context
             else:
                 return
     # 传递几个数据供(插件中的)接收函数调用, 其他不再注释
     context._host = self.config.host
     context._port = self.config.port
     self.pool.submit(self._friend_context_distributor, context)