QQ robot
11 Nov 2017 • Leave CommentsSome APIs has beeb shut down and commands related to QQ number would fail!
QQBot written with Python, is a conversation robot base on Tencent's SmartQQ. This post describes QQbot on Gentoo PC.
Installation
# within virtualenv
~ $ pip install qqbot
~ $ qqbot -h
At the very first run, it may throw exception complaining lack of sqlite3 module. Make sure python is built with relevant USE:
~ # echo 'dev-lang/python sqlite' >> /etc/portage/package.use/python
~ # emerge -av1 dev-lang/python:3.6
Startup
Help
Firstly, check basic parameters:
~ $ qqbot -h
Especially, pay attention to --daemon --bench --qq
.
First run
~ $ qqbot
# -or-
~ $ qqbot -q <qq number>
For the very first run, a QRcode pops up. Use QQ mobile app to scan for authorization. -q
attempts to load login cookies locally first and resorts to QRcode if that fails.
In order that QRcode image pops up automatically, gvfs-open or shotwell must be available under Linux system, which should not be a problem as long as gvfs package is installed. We can, however, manually open the QRcode located under ~/.qqbot-tmp/*.png.
Once login, a QQbot-term service is launched at port 8188 for interaction. Open a new terminal and:
~ $ qq help
~ $ qq list [ buddy | group | discuss ]
~ $ qq list buddy [ name | nick | mark | qq ] = xxx
~ $ qq list buddy name:like:xxx
~ $ qq list group-member <qq group>
For more operations, refer to official README.MD section 3.
Aternatively, all operations can be done through HTTP API. For example, open http://localhost:8188/list/buddy. We just separate each argument by /
. This is pretty useful when terminal output jumbers disorderly.
Configuration
Check ~/.qqbot-tmp/v2.x.conf, and add a section for specific QQ account:
"jim" : {
"termServerPort" : 8188,
"qq" : "123456789",
"daemon" : True,
"plugins" : [],
"pluginsConf" : {},
},
- If there are multiple QQ accounts, please assign different termServerPort.
- daemon mode releases terminal immediately after login. stout and stderr are redirected to daemon-$qq.log.
- plugins list overides the default value.
With that configuration block, launch QQbot by -u
:
~ $ qq stop
~ $ qqbot -u jim
User configuration section name instead of QQ number after -u
.
Plugins
Pre-built plugins (i.e. qqbot.plugins.sample ) are installed into site-packages/qqbot/plugins reference to whom should be prefixed with qqbot.plugins..
To be simple, put personal plugin myplugin.py under ~/.qqbot-tmp/plugins directory. You can load a plugin on-the-fly (hot-plug way) or by telling QQbot to load it on startup. Reference to personal plugin is the script filename.
-
hot-plug method.
~ $ qq plugins (list loaded) ~ $ qq plug qqbot.plugins.test ~ $ qq plugins ~ $ qq unplug myplugin
-
Automatic plug
Put your desired plugin name to
"plugins" : ['autohello',]
list.
qqbot.plugins.miniirc
To be able to talk with IRC client:
~ $ qq plug qqbot.plugins.miniirc
Then launch Weechat:
/server add qqbot localhost/6667
# set qqbot nick; change sasl_mechanism to plain; turn off ssl and ssl_verify;
/connect qqbot
/list
/join #group
/query buddy-name
The minirrc plugin is limited and recognizes only QQ name. For instance, you cannot query a QQ number.