Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
生成二维码插件
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed May 11, 2021
1 parent f9fd8de commit 8a4d049
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions plugins/bot_generateQrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""生成二维码,格式:生成二维码{内容}"""
import base64
import io

from botoy import GroupMsg
from botoy.decorators import ignore_botself, startswith, these_msgtypes
from botoy.sugar import Picture

try:
import qrcode
except ImportError as e:
raise ImportError("请先安装依赖库: pip install qrcode") from e


def gen_qrcode(text: str) -> str:
img = qrcode.make(text)
img_buffer = io.BytesIO()
img.save(img_buffer)
return base64.b64encode(img_buffer.getvalue()).decode()


@ignore_botself
@these_msgtypes("TextMsg")
@startswith("生成二维码")
def receive_group_msg(ctx: GroupMsg):
Picture(pic_base64=gen_qrcode(ctx.Content[5:]))
6 changes: 6 additions & 0 deletions plugins/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@
汉字转拼音

格式: 拼音{汉字}

# generate Qrcode

生成二维码

格式:生成二维码{内容}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
botoy
pillow
aiofiles
qrcode

0 comments on commit 8a4d049

Please sign in to comment.