EuDs

EuDs

EuDs's Blog
twitter
github

qqBot Setup

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 I started building it, and I encountered many problems. But one great thing is that the issues for these three projects are very active. I can 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. I hope I can make my own contributions in the future.

  • I didn't expect the most difficult part to be not the programming of the bot, but the login process. I used a new account (created about a week ago), and the risk control level is quite high.

And my requirement is to deploy the bot on a server in a location other than where I am, which further increases the probability of being risk-controlled.

After trying many methods, my final solution is:

  1. Use the watch protocol to scan the QR code locally first. ("sort_version_name":8.9.73, protocol:2)
  2. After successfully logging in, move the obtained files to the server and configure signsever, then log in 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 the plugin I wrote, 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:

    1. The username requirement for Create an account · PyPI is the most demanding 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.

    2. About NoneFlow is very powerful. I want to try to write something similar myself or learn how it's done.

Thoughts#

  1. I remember 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 outdo the other. It's a mixed feeling.
  2. I think the plugin system like nonebot is great. It saves a lot of effort.
  3. I feel that qqBot has a high playability. I often see interesting bots in other groups. But unfortunately, Tencent's attitude is disappointing.

Gains#

  1. nohup
  • Usage: Example: nphup nb run
  • Shutdown: Example:
    ps aux | grep `nb` # Find the corresponding process number
    kill $process_number
    
  1. Daemon (Systemd)
    Note: The following is copied from Using NoneBot2 and go-cqhttp to Build Your Own FF14 QQ Bot
    • 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
    
  2. 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
    
    

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.