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
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
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
Python framework for AsyncAPI-documented Websocket, PubSub, and other async constructs

asyncapi-eventrouter Work in Progress Write Python code for Event-Driven Architectures! The asyncapi-eventrouter prototype library creates Websocket,

noteable 4 Jan 27, 2022
Discord.py Connect to Discord voice call with websocket

Discord.py Connect to Discord voice call with websocket

WoahThatsHot 3 Apr 22, 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
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
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
Connects microservices through a mesh of websockets

WebMesh WebMesh is a WebSocket based communication library for microservices. It uses a WebSocket server based on wsproto that distributes clients on

Charles Smith 9 Apr 29, 2022
Chat app for Django, powered by Django Channels, Websockets & Asyncio

Django Private Chat2 New and improved https://github.com/Bearle/django-private-chat Chat app for Django, powered by Django Channels, Websockets & Asyn

Bearle 205 Dec 30, 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
一款为 go-cqhttp 的正向 WebSocket 设计的 Python SDK

Nakuru Project 一款为 go-cqhttp 的正向 WebSocket 设计的 Python SDK 在 kuriyama 的基础上改动 项目名来源于藍月なくる,图标由せら绘制 食用方法 将 nakuru 文件夹移至 Python 的 Lib/site-packages 目录下。

35 Dec 21, 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
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
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
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
WebSocket client for Python

websocket-client The websocket-client module is a WebSocket client for Python. It provides access to low level APIs for WebSockets. All APIs are for s

3.1k Jan 02, 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
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
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