MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / QRPlugin

Class QRPlugin

qr/qr.ts:186–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184
185━━━ 核心功能 ━━━
186• <code>qr &lt;文本&gt;</code> - 直接生成二维码
187• 回复文本消息使用 <code>qr</code> - 将消息内容转为二维码
188• 回复图片使用 <code>qr</code> - 解码图中的二维码内容
189
190━━━ 功能特性 ━━━
191• 📱 <b>生成二维码</b> - 将文本转换为二维码图片
192• 🔍 <b>解码二维码</b> - 从图片中识别和解码二维码内容
193• 💬 <b>多种使用方式</b> - 支持命令参数、回复消息等多种交互方式
194
195━━━ 系统依赖 ━━━
196<b>macOS:</b>
197<code>brew install qrencode zbar</code>
198
199<b>Ubuntu/Debian:</b>
200<code>sudo apt-get install qrencode zbar-tools</code>
201
202<b>CentOS/RHEL:</b>
203<code>sudo yum install qrencode zbar</code>
204
205━━━ 使用示例 ━━━
206• 生成二维码: <code>qr Hello World</code>
207• 解码二维码: 回复包含二维码的图片并发送 <code>qr</code>
208• 文本转码: 回复文本消息并发送 <code>qr</code>`;
209
210
211 cmdHandlers: Record<string, (msg: Api.Message) => Promise<void>> = {
212 qr: async (msg) => {
213 try {
214 const args = msg.message.split(' ').slice(1);
215 const textToEncode = args.join(' ');
216 const replied = msg.replyTo ? await safeGetReplyMessage(msg) : null;
217
218 // 1. 优先处理命令后的文本 (编码)
219 if (textToEncode) {
220 await msg.edit({
221 text: '⏳ 正在生成二维码...'
222 });
223 try {
224 const imageBuffer = await generateQRCode(textToEncode);
225 await msg.reply({
226 file: new CustomFile('qrcode.png', imageBuffer.length, '', imageBuffer),
227 message: '✅ 二维码生成完成'
228 });
229 await msg.delete();
230 } catch (error: any) {
231 const errorMsg = error.message || '未知错误';
232 await msg.edit({
233 text: `❌ <b>生成二维码失败</b>\n\n${errorMsg.includes('❌') ? errorMsg : `<code>${htmlEscape(errorMsg)}</code>`}`,
234 parseMode: 'html'
235 });
236 }
237 return;
238 }
239
240 // 2. 检查消息本身或回复中是否附带媒体文件 (解码)
241 let mediaToProcess = null;
242 if (msg.photo || msg.sticker || msg.document) {
243 mediaToProcess = msg;

Callers

nothing calls this directly

Calls 7

generateQRCodeFunction · 0.85
decodeQRCodeFunction · 0.85
errorMethod · 0.80
htmlEscapeFunction · 0.70
editMethod · 0.45
deleteMethod · 0.45
downloadMediaMethod · 0.45

Tested by

no test coverage detected