SocketIO 转发台,保持 botoy 能力和插件功能的同时,透传其接口,以此使用更灵活、生态更好的技术进行开发

Overview

bot_sio_transfer

SocketIO 转发台,保持 botoy 能力和插件功能的同时,透传其接口,以此使用更灵活、生态更好的技术进行开发

Usage

请参考 botoy 文档接入本插件

Example

考虑一种图文混排场景,如何从复杂结构内快速获取第一张图片的 url ? ( 假设图片是第一位出现 )

代码量减少

这里以 TypeScript 为例,解析一个复杂的字符串结构 ctx?.Content ,方法包装后仅有两行。

(ctx: IGroupMsg) => {
  const url = getPicMsgFirstUrl(ctx?.Content)
  sendMsgV2(url)
}

安全性提高

可正如所说,用户提供的消息并不一定含有图片,可能是任意消息,图文混排的顺序也不确定,甚至有没有值都不确定。

籍以生态工具库的强大我们可以进行任意深度的安全取值:

    const msgObj = JSON.parse(ctx?.Content)
    // 100% safe get value
    // or msgObj?.GroupPic?.[0]?.Url
    return _get(msgObj, 'GroupPic.[0].Url')

增强类型提示

受够了 Python 不够强大的类型提示,又不想涉猎强类型语言的复杂,折中方案或许是最快选择。

// 强类型语言一样的方便枚举值
export enum EMsgType {
  Image = 'PicMsg',
  Text = 'TextMsg',
  Voice = 'VoiceMsg',
  Xml = 'XmlMsg',
}

export interface IGroupMsg {
  message: string
  CurrentQQ: number

  // 当不确定时即为 any 或 unknown ,而在强类型语言内必定要明确指明,复杂度大大提升
  data: Record<string, unknown>
  FromGroupId: number
  FromGroupName: string
  FromUserId: number
  FromNickName: string
  Content: string
  MsgType: EMsgType
  MsgTime: number
  MsgSeq: number
  MsgRandom: number

  // 编辑器会告诉你哪个值可能不存在,哪个值必定存在
  RedBaginfo?: Record<string, any>
}

当然,此处仅仅举一例 case 说明,当你跳出 py 弱区,采用其他方便的工具得到的便利。

完整 case 可查看 example/src/index.ts

项目实践

可参见 sio-yyy 项目级实践示例。

Other

所以,为什么不再造一个框架/工具?

喜欢无偿浪费时间重复造轮子是吧 😅

Owner
OPQ Open Source Community
OPQBot 开源开发社区
OPQ Open Source Community
WebSocket implementation in Python built on top of websockets python library. Similar to Node.js's ws.

ws WebSocket implementation in Python built on top of websockets python library. Similar to Node.js's ws. Basic usage. server.py import ws server = w

AceExpert 7 Jun 27, 2022
Burgeramt-appointments-websockets - Fetch Bürgeramt appointments and broadcast them via websockets

Bürgeramt appointment finder This server looks for Bürgeramt appointment every f

74 Dec 19, 2022
A simple texts communication platform using pygame and sockets.

Python Tchat A simple texts communication platform using pygame and sockets. How to install ? You need a python 3.8.6 server with at least one opened

Yohann Boniface 7 Jan 23, 2022
A websocket client for Source Filmmaker intended to trasmit scene and frame data to other applications.

SFM SOCK A websocket client for Source Filmmaker intended to trasmit scene and frame data to other applications. This software can be used to transmit

KiwifruitDev 2 Jan 08, 2022
Websocket 'broadcast' demo using FastAPI/Starlette

fastapi-websocket-broadcast An example of the familiar 'chat' websocket demo app, implemented in FastAPI / Starlette. Run with uvicorn app:app And th

Kit Thwaite 109 Nov 30, 2022
tiny multi-threaded socks4 server implemented in python2

tiny, multi-threaded socks4a server implemented in python2.

4 Sep 21, 2022
WebSocket emulation - Python server

SockJS-tornado server SockJS-tornado is a Python server side counterpart of SockJS-client browser library running on top of Tornado framework. Simplif

Serge S. Koval 854 Nov 19, 2022
Tetri5 - Multiplayer Websocket Backend

Tetri5 - Multiplayer Websocket Backend This repository is the backend of the multiplayer portion of the Tetri5 game client. It uses the python websock

Giovani Rodriguez 1 Dec 10, 2022
Library for building WebSocket servers and clients in Python

What is websockets? websockets is a library for building WebSocket servers and clients in Python with a focus on correctness and simplicity. Built on

Aymeric Augustin 4.3k Jan 04, 2023
Using python-binance to provide websocket data to freqtrade

The goal of this project is to provide an alternative way to get realtime data from Binance and use it in freqtrade despite the exchange used. It also uses talipp for computing

58 Jan 01, 2023
WebSocket and WAMP in Python for Twisted and asyncio

Autobahn|Python WebSocket & WAMP for Python on Twisted and asyncio. Quick Links: Source Code - Documentation - WebSocket Examples - WAMP Examples Comm

Crossbar.io 2.4k Jan 04, 2023
Benchmark a WebSocket server's message throughput ⌛

📻 WebSocket Benchmarker ⌚ Message throughput is how fast a WebSocket server can parse and respond to a message. Some people consider this to be a goo

Andrew Healey 24 Nov 17, 2022
Synci - Learning project to create a websocket based client server messaging application

Synci Learning project to create a websocket based client server messaging appli

2 Jan 13, 2022
image stream publish server over websocket

Image Stream Push Server 简介 通过浏览器网页实时查看图像处理结果。 环境 运行程序需要安装一下python依赖: tornado: 用于创建http及websocket服务; opencv-contrib-python: 用于图像数据源获取及图像处理。 使用 进入到src目

MrError404 1 Nov 04, 2021
AWS API Gateway Websocket Asynchronous Notifications Pusher

AWS API Gateway Websocket Asynchronous Pusher Fast AWS API Gateway websockets notifications' pusher using Python AsyncIO for managing asynchronous and

OBytes 5 May 15, 2022
Terminals served by tornado websockets

This is a Tornado websocket backend for the Xterm.js Javascript terminal emulator library. It evolved out of pyxterm, which was part of GraphTerm (as

Project Jupyter 332 Dec 27, 2022
Python Socket.IO server and client

python-socketio Python implementation of the Socket.IO realtime client and server. Version compatibility The Socket.IO protocol has been through a num

Miguel Grinberg 3.2k Dec 31, 2022
An IPC based on Websockets, fast, stable, and reliable

winerp An IPC based on Websockets. Fast, Stable, and easy-to-use, for inter-communication between your processes or discord.py bots. Key Features Fast

Black Thunder 5 Aug 09, 2022
wssh ("wish") is a command-line utility/shell for WebSocket inpsired by netcat.

wssh ("wish") is a command-line utility/shell for WebSocket inspired by netcat

Jeff Lindsay 256 Nov 16, 2022
Socket.IO integration for Flask applications.

Flask-SocketIO Socket.IO integration for Flask applications. Installation You can install this package as usual with pip: pip install flask-socketio

Miguel Grinberg 4.9k Jan 03, 2023