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
Official repository for gevent-socketio

Presentation gevent-socketio is a Python implementation of the Socket.IO protocol, developed originally for Node.js by LearnBoost and then ported to o

Alexandre Bourget 1.2k Dec 12, 2022
Websockify is a WebSocket to TCP proxy/bridge. This allows a browser to connect to any application/server/service. Implementations in Python, C, Node.js and Ruby.

websockify: WebSockets support for any application/server websockify was formerly named wsproxy and was part of the noVNC project. At the most basic l

noVNC 3.3k Jan 03, 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
JINS MEME(2021年モデル)のJINS MEME LoggerをPythonのWebSocketサーバーで受信するサンプル

JINS-MEME-Python-WebSocketServer-Sample JINS MEME(2021年モデル)のJINS MEME LoggerをPythonのWebSocketサーバーで受信するサンプルです。 Logging Data 以下のデータに対応しています。 各データの定義はJIN

KazuhitoTakahashi 19 Apr 29, 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
Get realtime updates in your mobile/web app from frappe and erpnext

Fsocket Extend frappe's websocket server using socket.io and redis Installation Use frappe bench to add fsocket in your project $ bench get-app https:

21 Sep 25, 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
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
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
Whatsapp Clone using django, django-channels and websocket

whatsapp-clone Whatsapp Clone using django, django-channels and websocket Features : Signup/Login One on One personal chat with other user Some screen

Anshu Pal 14 Dec 25, 2022
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
Elegant WebSockets for your Flask apps.

Flask-Sockets Elegant WebSockets for your Flask apps. Simple usage of route decorator: from flask import Flask from flask_sockets import Sockets app

Heroku Python Team 1.7k Dec 26, 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
Developer-friendly asynchrony for Django

Django Channels Channels augments Django to bring WebSocket, long-poll HTTP, task offloading and other async support to your code, using familiar Djan

Django 5.5k Jan 03, 2023
Discord.py Connect to Discord voice call with websocket

Discord.py Connect to Discord voice call with websocket

WoahThatsHot 3 Apr 22, 2022
Python socket.io server implementation on top of Tornado framework

TornadIO2 Disclaimer Unfortunately, Socket.IO 0.8 branch is abandoned, there are huge amount of bugs and nothing getting fixed. I would suggest to loo

Serge S. Koval 526 Oct 03, 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
This websocket program is for data transmission between server and client. Data transmission is for Federated Learning in Edge computing environment.

websocket-for-data-transmission This websocket program is for data transmission between server and client. Data transmission is for Federated Learning

9 Jul 19, 2022
A Security Tool for Enumerating WebSockets

STEWS: Security Testing and Enumeration of WebSockets STEWS is a tool suite for security testing of WebSockets This research was first presented at OW

175 Jan 01, 2023
Websocket RPC and Pub/Sub for Python applications and microservices

wampy [whomp-ee] For a background as to what WAMP is, please see here. This is a Python implementation of WAMP using Gevent, but you can also configur

simon 121 Nov 22, 2022