Building qqBot#
These days, I'm building a qqBot, so I'll record it.
Overall Technology#
I'm using go-cqhttp and nonebot2.
When encountering risk control issues, I used unidbg-fetch-qsign.
Process#
-
The whole process was much more difficult than I expected before starting to build it, and I encountered many problems. But a great thing is that the issues for these three projects are very active. I could find almost all the problems I encountered in the issues. I haven't used many open-source projects, but these three have given me a good impression, and I hope to make my own contributions in the future.
-
I didn't expect the most difficult part to be the login, not the programming of the bot. I used a new account (created about a week ago), and the risk control level is high.
My requirement is to deploy the bot on a server located in a place other than where I am, which increases the probability of being risk-controlled.
After trying many methods, my final solution is:
- Use the watch protocol to scan the QR code for login locally. (
"sort_version_name":8.9.73
,protocol: 2
) - After successfully logging in, move the obtained files to the server and configure
signsever
for login again.
-
But in the end, the bot was still risk-controlled and unable to send group messages.
I don't want to tinker further in a short time.
-
Today, I published my own plugin EuDs63/nonebot-plugin-yesman: nonebot2 plugin to the Plugin Store | NoneBot. I went through the process of publishing a plugin, which was quite interesting. There are a few points worth mentioning:
- The username requirement for Create an account · PyPI is the most strict I have ever seen. But I can understand it.
Choose a strong password that contains letters (uppercase and lowercase), numbers and special characters. Avoid common words or repetition.
- About NoneFlow is very powerful. I want to try to write a similar one myself or understand how it is done.
- The username requirement for Create an account · PyPI is the most strict I have ever seen. But I can understand it.
Thoughts#
- I remembered when building a Telegram bot, I only needed to apply for a token, and even the official tutorial was available. But here, it's like a cat-and-mouse game with each side trying to outsmart the other. It's a mixed feeling.
- I think the plugin system like nonebot is great. It saves a lot of effort.
- I feel that qqBot has a high playability. I often see interesting bots in other groups. But unfortunately, Tencent's attitude is disappointing.
Gains#
nohup
- Usage: Example:
nohup nb run
- Shutdown: Example:
ps aux | grep `nb` # Find the corresponding process number kill $process_number
Daemon (Systemd)
Note: The following is copied from 使用 NoneBot2 和 go-cqhttp 打造自己的 FF14 QQ 机器人- Creation
# vim /lib/systemd/system/go-cqhttp.service [Unit] Description=GO-CQHTTP Wants=network-online.target After=network-online.target [Service] Type=simple User=root WorkingDirectory= The running directory of GO-CQHTTP ExecStart= nohup go-cqhttp KillMode=process [Install] WantedBy=multi-user.target
- Usage
systemctl status go-cqhttp # Check status systemctl enable go-cqhttp # Enable auto-start on boot systemctl restart go-cqhttp # Restart the process systemctl stop go-cqhttp # Stop the process systemctl start go-cqhttp # Start the process
- Python virtual environment
- Create
python -m venv myenv # Create a virtual environment named myenv
- Activate
source ./qqVenv/bin/activate # bash source ./qqVenv/bin/activate.fish # fish