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
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
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
Django Channels HTTP/WebSocket server

daphne Daphne is a HTTP, HTTP2 and WebSocket protocol server for ASGI and ASGI-HTTP, developed to power Django Channels. It supports automatic negotia

Django 1.9k Dec 31, 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
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
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
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
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
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
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
Library for easily creating and managing websockets.

Documentation coming in version 0.1.4 GitHub PyPI Discord Features Easy to use with object oriented syntax. Intellisense support with typehints and do

ZeroIntensity 0 Aug 27, 2022
Minecraft WebSocket

Minecraft-WebSocket Pythonでマインクラフトと通信します。 紹介動画 推奨設定 Minecraft Windows Edition (Education Edition) 1.17 以上 Python 3系(3.8.2で動作確認済み) 必要なモジュール ・asyncio ・w

Roii.py 2 Jul 07, 2022
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
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
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
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
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
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
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
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