dwgx@blog:~$dwgx
> cd ../posts

QQbot: A QQ Group Dice Bot Built on Tencent's Official SDK

// created

QQbot is a QQ group bot built on Tencent’s official qq-botpy SDK, running a token-based dice betting game inside a group chat. @ the bot and it starts receiving events; the whole core revolves around placing bets and drawing results.

The gameplay is token dice. @ it with 大100 单50 to bet 100 on big and 50 on odd, then sh or toss a 🎲 to draw; use sh3 for consecutive rolls. The odds are hardcoded: 1.97 for big/small, 2.9 for odd/even, up to 6.9 for exact points, just off-the-cuff numbers that are good enough to play with. On top of that there’s a banker and red packets: 我当老板 takes the banker seat and opens with 1,000,000 tokens, hb 100 5 sends a red packet, others 领取 to claim, and 撤回 to pull one back if you sent it wrong; who can hand out money is controlled by the admin list. Check your balance with ye.

Two things are worth calling out. The data doesn’t go into a database, just a local JSON holding accounts, but group chat is concurrent: several people betting and grabbing red packets at the same time means read/write races that miscalculate balances, so all persistence is serialized through an asyncio lock. The process stays up long-term, and it hooks SIGINT/SIGTERM for a graceful exit, flushing to disk before it leaves on a signal so a Ctrl+C doesn’t lose the books.

Config runs through a lookup chain: it checks config.yaml first, falls back to the root directory if not found, then to other/run/, or you point at it directly with DWGXBOT_CONFIG; it only holds three things, appid, secret, and admins. Start it with a single python Code/QQbot/main/DwgxBot.py, and logs plus data.json land in other/run/.

The repo also has some other stuff crammed in. Code/web/ is a demo experimenting with AES-encrypted communication, a WebSocket chat bound to 0.0.0.0:20008 with messages encrypted using a session key. other/pyside6tool/ is a pile of small PySide6 desktop tools, tossed in together because splitting out a separate repo was too much bother. The stack is nothing fancy: qq-botpy 1.2.1, aiohttp, websockets, APScheduler, cryptography, PySide6 6.8, and CI only runs compileall once on push and PR as a syntax check, with no tests written yet.

A practice project, WIP status, with odds and some URLs still hardcoded as placeholders, but the core bot runs stably.