qqbot is a QQ robot implemented in python and based on Tencent's SmartQQ protocol. It can run on Linux, Windows and Mac OSX platforms.
The github address of this project: https://github.com/pandolia/qqbot
You can do this by extending qqbot:
For use under Python 2.7/3.4+, install with pip:
pip install qqbot
Or download the source code, unzip it, cd to the directory and run: pip install
.
Enter: qqbot on the command line to start a QQBot.
During the startup process, a QR code image will automatically pop up. You need to use the mobile QQ client to scan the code and authorize login. After successful startup, the login information will be saved to a local file. When starting next time, you can enter: qqbot -q qq number . First try to restore the login information from the local file (no need to manually scan the code). Only the recovery fails. You will need to manually scan the QR code to log in if the login is successful or the login information has expired. Generally speaking, saved login information will expire after 2 days.
Note: Under Linux, the gvfs-open or shotwell command is required in the system to automatically pop up the QR code image (generally, systems with the GNOME virtual file system gvfs installed will contain one of these two commands). Under Windows 10, the default opening program for png image files needs to be set in the system to automatically pop up the QR code image.
If the system cannot automatically pop up the QR code image, you can manually open the image file and scan the code, or you can set the QR code display mode to mailbox mode, server mode or text mode to scan the code. For details, see Section 7 of this document.
After QQBot is started, use the qq command in another console window to operate QQBot. The following commands are currently provided:
1) 帮助、停机和重启命令
qq help|stop|restart|fresh-restart
2) 联系人查询、搜索命令
qq list buddy|group|discuss [$cinfo|$clike]
( $cinfo --> $qq|$name|$key=$val )
( $clike --> :like:$qq|:like:$name|$key:like:$name )
qq list group-member|discuss-member $oinfo|$olike [$cinfo|$clike]
( $oinfo --> $oqq|$oname|$okey=$oval )
( $cinfo --> $qq|$name|$key=$val )
( $olike --> :like:$oqq|:like:$oname|$okey:like:$oname )
( $clike --> :like:$qq|:like:$name|$key:like:$name )
3) 联系人更新命令
qq update buddy|group|discuss
qq update group-member|discuss-member $ginfo
4) 消息发送命令
qq send buddy|group|discuss $rinfo $message
5) 加载/卸载/显示插件
qq plug/unplug myplugin
qq plugins
The list command provides powerful contact query and search functions. Usage examples are as follows:
# 列出所有好友
qq list buddy
# 列出 名称 为 xxx 的群
qq list group xxx
# 列出备注名为 jack 的好友
qq list buddy mark=jack
# 列出 群“456班” 的所有成员
qq list group-member 456班
# 列出 群“456班” 中名片为 “mike” 的成员
qq list group-member 456班 card=mike
# 列出 讨论组“XX小组” 中名为 jack 的好友
qq list discuss-member XX小组 jack
If the third and fourth parameters are in the format of key=val, they should be in the format of name=xx|nick=xx|mark=xx|card=xx|qq=xx. If they are not in the format of key=val, press The processing principle is as follows: if it is a string of numbers, query by QQ number, otherwise, query by name.
If there is a duplicate name, all contacts with the duplicate name will be listed. like:
qq list group 机器人测试
All groups named "Bot Test" will be listed.
If ":like:" is added to the third and fourth parameters of the list command, the search will be based on partial matching patterns. Usage examples are as follows:
# 列出名称中含有 “李” 的好友
qq list buddy :like:李
# 列出 QQ 中含有 “234” 的群
qq list group :like:234
# 列出备注名中含有 jack 的好友
qq list buddy mark:like:jack
# 列出 群“456班” 的中名称中含有 “李” 的成员
qq list group-member 456班 :like:李
# 列出 群“456班” 中名片中含有 “mike” 的成员
qq list group-member 456班 card:like:mike
# 列出的 讨论组“xx小组” 中名为 jack 的好友
qq list discuss-member :like:小组 jack
Starting from version v2.2.5, the list command uses a table to output the contact list. An example of its output style is as follows:
In order to ensure the display effect of the table in the terminal, it is recommended to set the output font of the terminal to consolas and the maximum number of characters that can be printed in each line is greater than 120. Also note: In order to ensure the display effect of the table, when the contact's name, business card and other attributes are too long or contain special characters, these attributes will be truncated or filtered before being output to the terminal.
The update command updates the specified contact list, and its parameter meanings are the same as those of the list command, such as:
# 更新好友列表
qq update buddy
# 更新群列表
qq update group
# 更新 群“456班” 的成员列表
qq update group-member 456班
The third parameter in the send command has the same format as the third parameter in the list command. Please note that if there is a duplicate name, a message will be sent to all contacts with the same name. Also note that the second parameter can only be buddy/group/discuss, not group-member/discuss-member. Example:
# 给 好友“jack” 发消息 “你好”
qq send buddy jack 你好
# 给 群“198班” 发消息 “大家好”
qq send group 198班 大家好
# 给 QQ 为 12345 的好友发消息
qq send buddy 12345 xxx
# 给讨论组发消息
qq send discuss MyDiscuss hello
You can embed emoticon keywords such as "/cute" in the message content to send emoticons to the other party. See facemap.py for details. You can also use the two escape characters n and t in the message content (for example: send buddy jack first linen second line).
All the above commands provide corresponding HTTP API interfaces for web front-end developers to call. The URL address of the interface is http://127.0.0.1:8188/{command}. You only need to use "/" for each parameter of the command after qq. Just separate and replace the command in the url, such as: http://127.0.0.1:8188/send/buddy/jack/hello , see urltestbot.md for other examples. Note: If the command contains Chinese or special characters, URL encoding (utf8) needs to be performed first. For example, call http://127.0.0.1:8188/send/buddy/jack/nihao%20%E4%BD%A0%E5 %A5%BD%20wohao will send the message "nihao hello wohao". (Tip: In JavaScript, you can use the encodeURIComponent function for encoding).
In addition, after QQBot is started, if you use this QQ account to send a message "--version" to a group/discussion group on other clients (such as mobile QQ), QQBot will automatically reply to the group/discussion group: "QQBot -v2.xx".
It is very simple to implement your own QQ robot. You only need to define your own message response function and load it as a plug-in. Sample code:
# -*- coding: utf-8 -*-
def onQQMessage ( bot , contact , member , content ):
if content == '-hello' :
bot . SendTo ( contact , '你好,我是QQ机器人' )
elif content == '-stop' :
bot . SendTo ( contact , 'QQ机器人已关闭' )
bot . Stop ()
Note that the function name of the response function registered above must be "onQQMessage", and the function parameters must also be consistent with the above.
Save the above code as sample.py (note that it is saved as a utf8-encoded file). Place it in the ~/.qqbot-tmp/plugins/ directory ( ~ represents the user's home directory, C:Usersxxx under win7), or a directory that can be imported in the system (such as Lib/ in the python installation directory) site-packages directory).
After that, keep the previous qqbot process running and enter qq plug sample in another console. Then the onQQMessage function in this file can be registered to the corresponding event of QQBot. At this time, if you use another QQ to send the message "-hello" to this QQ, it will automatically reply "Hello, I am a QQ robot" . If you send the message "-stop" , the QQ robot will be closed.
Enter qq unplug sample on the console to uninstall this plug-in and the corresponding callback function. Multiple plug-ins can be loaded at the same time, and the corresponding functions in each plug-in will be called in sequence (but the calling order has nothing to do with the loading order).
After QQBot starts running, each time it receives a QQ message, it will pass the message source, message content and a QQBot object to the registered message response function. in:
bot : QQBot 对象,提供 List/SendTo/Stop/Restart 等接口,详见本文档第五节
contact : QContact 对象,消息的发送者,具有 ctype/qq/uin/nick/mark/card/name 等属性
member : QContact 对象,仅当本消息为 群消息或讨论组消息 时有效,代表实际发消息的成员
content : str 对象,消息内容
contact represents the message sender, and its ctype attribute can be buddy
/ group
/ discuss
, which represents the friend/group/discussion group object, indicating that this message is a friend message/group message/discussion group message.
member is only valid when this message is a group message or discussion group message, and represents the member who actually sent the message. Its ctype attribute can be group-member
/ discuss-member
, which represents the group member/discussion group member object. When this message is a friend message, member is equal to None.
Both contact and member are QContact objects. For the meaning of attributes of different types of QContact objects, see: qcontact-attr. Note that all QContact objects are read-only objects . Only its properties can be read, its properties cannot be set, and additional properties cannot be added to it.
You can call the SendTo interface of the QQBot object to send messages to the QContact object, but please note: you can only send messages to friends/groups/discussion groups, but not to group members/discussion group members . In other words, only bot.SendTo(contact, 'xxx') can be called, but bot.SendTo(member, 'xxx') cannot be called.
The QQBot object provides a total of 9 public interfaces List/Update/SendTo/Plug/Unplug/Login/Stop/Restart/FreshRestart. The first letters of these interfaces are all capitalized. In addition, a public attribute conf is provided to save global configuration information.
In general, do not call/access other methods/properties of this object. In particular, do not call these interfaces in child threads . The following describes the first seven interfaces and conf attributes.
If you need to run or test the above interface in IDE or python-shell, you need to close the qqbot process first, and run the following code in IDE or python-shell to log in:
>>> from qqbot import _bot as bot
>>> bot.Login(['-q', '1234'])
Corresponds to the list command in Section 3 of this document. Returns a list of contact objects (QContact objects) or None. The first parameter tinfo is the code name of the contact list, and the second parameter is optional (the format is the same as the third parameter of the list command).
The parameter tinfo is used to represent a contact list. This parameter is very important in contact query. Please be sure to understand the following two situations :
The meaning of tinfo (case 1): tinfo can be buddy
/ group
/ discuss
, which respectively represent friend list/group list/discussion group list. Example:
# 返回 好友列表:
>>> bot.List('buddy')
# 返回名为 'jack' 的好友的列表:
>>> bot.List('buddy', 'jack')
# 返回 群列表:
>>> bot.List('group')
# 返回名为 “机器人测试” 的群的列表:
>>> bot.List('group', '机器人测试')
The meaning of tinfo (Case 2): tinfo can also be a QContact object with ctype equal to group
/ discuss
, representing the member list of the group/discussion group. For example, the second and third sentences below return the list of members of the group "Class 456" and the list of members whose business card is "jack" in the group respectively:
>>> g = bot.List('group', "456班")[0] # g 是一个 Group 对象(群“456班”)
>>> bot.List(g) # 返回 群“456班” 的成员列表
>>> bot.List(g, 'card=jack') # 返回 群“456班” 中名片为 “jack” 的成员列表
Note that the third sentence above does not allow the format of bot.List(g, card='jack').
The internal execution sequence of the List interface: first search for the contact list represented by tinfo in QQBot's contact database; if the list already exists in the database, search within this list and return a list containing "all and "cinfo matching contacts" list; if there is no such list in the database, request data from the QQ server to obtain the contact list. After successful acquisition, the contact list will be saved to the database, and then search and return a list containing "this list" all in cinfo "matching contacts" list; if an error occurs during requesting data from the QQ server, the relevant failure information will be printed and None will be returned.
The meaning of the return value of the List interface: Returns a non-empty list to represent all contacts matching cinfo in the contact list specified by tinfo; Returns an empty list to represent that there are no contacts matching cinfo in the contact list; Returns None to represent Requesting the contact list and information from the QQ server failed. I don't know if there are matching contacts.
After calling the List interface, be sure to judge the return value based on the above three situations before executing subsequent code.
Note: When the List interface returns a non-empty list, the elements in the list are QContact objects, not str objects:
>>> g = bot.List('group')[0] # g 是一个 Group 对象
>>> print([g, type(g), g.qq, g.name, g.uin, g.mark]) # 打印 g 的各项属性
For the meaning of attributes of different types of QContact objects, see: qcontact-attr.
The parameter tinfo of the Update interface has the same meaning as the parameters in the List interface. Calling this interface will immediately request the corresponding contact list from the QQ server and update the contact database, and will block until the update is successful. The slowest update is the friend list. If there are many friends, it may be blocked for 5 ~ 10 seconds. The member list is updated very quickly. Even for a large group of 2,000 people, the update time is only 1 to 2 seconds.
If the update is successful, True is returned; otherwise, False is returned.
Example:
# 更新 好友列表 :
>>> bot.Update('buddy')
# 更新 群列表 :
>>> bot.Update('group')
# 更新 某个群的成员列表 :
>>> gl = bot.List('group', "456班")
>>> if gl:
>>> g = gl[0]
>>> bot.Update(g)
Send a message to a contact. The first parameter is the QContact object, and the second parameter is the message content. Reminder again: You can only send messages to friends/groups/discussion groups. You are not allowed to send messages to group members/discussion group members .
You can embed emoticon keywords such as "/smile" in the message content to send emoticons to the other party. For details, see facemap.py.
If the sending is successful, a string is returned (向xx 发消息成功
). Otherwise, a string containing the cause of the error (错误:...
) is returned.
When sending a message, the message may be sent repeatedly. This is because the QQ server returns code 1202. Version v2.1.17 has added a parameter to the bot.SendTo interface for this problem: resendOn1202. If this parameter is True (default value), if the QQ server returns code 1202 (indicating that the message may fail) when sending a message, it will also It will continue to be sent 3 times until the return code is 0. If this parameter is False, no resending will be attempted.
Setting it to True can ensure that the message will be sent in most cases, but the disadvantage is that sometimes a message will be sent repeatedly. If set to False, on the contrary, the message will not be sent repeatedly, but sometimes the message cannot be sent.
In short, because of the uncertainty of this 1202 code, there is no perfect solution. Please select the value of resendOn1202 according to your actual situation.
The first parameter contact must be the QContact object returned by bot.List or the first parameter passed in by the callback function onQQMessage. Example:
# 向 昵称 为 jack 的好友发消息
>>> bl = bot.List('buddy', 'jack')
>>> if bl:
>>> b = bl[0]
>>> bot.SendTo(b, 'hello')
Global configuration information is saved in bot.conf. For details on each configuration, see Section 7 of this document. For example, bot.conf.termServerPort saves the port number of the QQBot command line server, and bot.conf.qq saves the QQ number of this login.
Note: The configuration information saved in bot.conf is read-only. Please do not modify this configuration information.
In addition to the onQQMessage response function mentioned above, you can also register callback functions for a total of nine events onInit/onQrcode/onStartupComplete/onInterval/onUpdate/onPlug/onUnplug/onExit. Please see sampleslots for the callback function parameter format, meaning and examples of all events. py.
The running process of the program and the calling timing of each callback function are as follows:
Reminder again: the function name of the registered callback function and the function parameters (number and name) must not be changed .
When QQBot receives a group message, it will first determine whether someone @ itself based on the message content. If so, add a [@ME]
mark at the beginning of the message content and pass it to the onQQMessage function; otherwise, replace all @ME
in the message content with @Me
and pass it to onQQMessage. Therefore, in the onQQMessage function, you only need to determine whether the content contains @ME
to know whether you have been @ by the message sender. For example:
def onQQMessage ( bot , contact , member , content ):
if '@ME' in content :
bot . SendTo ( contact , member . name + ',艾特我干嘛呢?' )
Please note that if there is another member in the group whose name is the same as the beginning of your own name (for example: your name is ab and another member's name is abc), then when someone @abc, it will be falsely reported as @ME, in this case, you need to modify your group business card to avoid false positives.
When this QQ sends a message, QQBot will also receive the same message. The bot object provides an isMe method to determine whether the message is sent by itself:
def onQQMessage ( bot , contact , member , content ):
if bot . isMe ( contact , member ):
print ( 'This is me' )
Starting from 2.1.13, qqbot provides a powerful function decorator - qqbotsched
to customize scheduled tasks, sample code:
from qqbot import qqbotsched
@ qqbotsched ( hour = '11,17' , minute = '55' )
def mytask ( bot ):
gl = bot . List ( 'group' , '456班' )
if gl is not None :
for group in gl :
bot . SendTo ( group , '同志们:开饭啦啦啦啦啦啦!!!' )
After the above code is loaded in the form of a plug-in, a message will be automatically sent to the group "Class 456" every 11:55 and 17:55: "Comrades: Dinner is served!!!"
The qqbotsched decorator accepts a total of 11 keyword parameters: year, month, day, week, day_of_week, hour, minute, second, start_date, end_date, timezone. Each parameter represents the value that the customized time component of the task should match. For example: hour='11,17' means the task should be executed at 11:xx or 17:xx, minute='55' means the task should be executed at xx:55, minute='0-55/5' means the task should be executed at xx: 00, xx:05, xx:10, ..., xx:55 executes the task, day_of_week='mon-fri' (or '0-4') indicates that the task should be executed from Monday to Friday.
qqbotsched is a simple encapsulation of Python's scheduled task framework apscheduler, and its parameters should be input in the crontab format in Unix systems. For information about crontab and Python’s scheduled task framework apscheduler, please see the following reference materials:
For details on the format of each crontab parameter, see:
Registering callback functions and customizing scheduled tasks is the only way to extend QQBot. When writing these functions, please pay attention to the following:
When logging in to WebQQ, you need to use your mobile phone QQ to scan the QR code image. In QQBot, the QR code image can be displayed in the following four modes:
GUI mode is the default mode and is only available on PCs. Mailbox mode can be used on personal computers and remote servers. Server mode is generally only used in systems with public IP addresses. If you use QQ mailbox to receive the QR code, after sending the QR code picture, the mobile QQ client will immediately receive a notification. Open the email on the mobile QQ client, and then long press the QR code to scan. Text mode is convenient for use during the development process or server deployment, and provides developers with a shortcut to log in to QQ.
Note: When the mailbox mode/server mode/text mode is turned on, the GUI mode is turned off, and the QR code image will not automatically pop up when logging in.
A QR code manager (QrcodeManager object) will be created each time you log in. The QR code manager will select the display method of the QR code image based on the configuration file and command line parameters.
The configuration file is ~/.qqbot-tmp/v2.x.conf ( ~ represents the user’s home directory, which is C:Usersxxx under win7 and /home/xxx under linux). It will be automatically configured after running QQBot for the first time. Create this configuration file with the following contents:
{
# QQBot 的配置文件
# 使用 qqbot -u somebody 启动程序时,依次加载:
# 根配置 -> 默认配置 -> 用户 somebody 的配置 -> 命令行参数配置
# 使用 qqbot 启动程序时,依次加载:
# 根配置 -> 默认配置 -> 命令行参数配置
# 用户 somebody 的配置
"somebody" : {
# QQBot-term (HTTP-API) 服务器端口号(该服务器监听 IP 为 127.0.0.1 )
# 设置为 0 则不会开启本服务器(此时 qq 命令和 HTTP-API 接口都无法使用)。
"termServerPort" : 8188,
# 二维码 http 服务器 ip,请设置为公网 ip 或空字符串
"httpServerIP" : "",
# 二维码 http 服务器端口号
"httpServerPort" : 8189,
# 自动登录的 QQ 号
"qq" : "3497303033",
# 接收二维码图片的邮箱账号
"mailAccount" : "[email protected]",
# 该邮箱的 IMAP/SMTP 服务授权码
"mailAuthCode" : "feregfgftrasdsew",
# 是否以文本模式显示二维码
"cmdQrcode" : False,
# 显示/关闭调试信息
"debug" : False,
# QQBot 掉线后自动重启
"restartOnOffline" : False,
# 在后台运行 qqbot ( daemon 模式)
"daemon": False,
# 完成全部联系人列表获取之后才启动 QQBot
"startAfterFetch" : False,
# 插件目录
"pluginPath" : ".",
# 启动时需加载的插件
"plugins" : [],
# 插件的配置(由用户自定义)
"pluginsConf" : {},
},
# 可以在 默认配置 中配置所有用户都通用的设置
"默认配置" : {
"qq" : "",
"pluginPath" : "",
"plugins" : [
'qqbot.plugins.sampleslots',
'qqbot.plugins.schedrestart',
],
"pluginsConf" : {
'qqbot.plugins.schedrestart': '8:00',
}
},
# # 注意:根配置是固定的,用户无法修改(在本文件中修改根配置不会生效)
# "根配置" : {
# "termServerPort" : 8188,
# "httpServerIP" : "",
# "httpServerPort" : 8189,
# "qq" : "",
# "mailAccount" : "",
# "mailAuthCode" : "",
# "cmdQrcode" : False,
# "debug" : False,
# "restartOnOffline" : False,
# "daemon" : False,
# "startAfterFetch" : False,
# "pluginPath" : "",
# "plugins" : [],
# "pluginsConf" : {}
# },
}
You can add your own user configuration in the configuration file (that is, add a new item in the dictionary of the file, and the key of this item represents a user). For example, the someone item already in the file represents the user named someone. , when running QQBot, enter qqbot -u somebody , and the configurations under the someone project will be loaded.
The following describes the functions of each configuration in the configuration file. The following content assumes that the configuration under someone has been modified and run in the qqbot -u somebody mode.
If you need to use the mailbox mode to display the QR code, you can set the mailAccount and mailAuthCode items as the mailbox account and authorization code respectively. After running, the QR code manager will send the QR code image to the mailbox.
Note: The authorization code is not the login password of the mailbox, but the authorization code provided by the mailbox service provider to activate the IMAP/SMTP service (reminder: not the POP3/SMTP service). QQ/NetEase mailbox can activate this in the mailbox settings of the web version. service and get the authorization code. If only mailAccount is defined but not mailAuthCode, the authorization code will be required to be manually entered when the program starts.
The mailbox mode has been tested in QQ, NetEase and Google mailboxes.
If you need to use server mode, you can configure the httpServerIP and httpServerPort items. Generally speaking, they should be set to public network ip. After the server mode is turned on, you can access the QR code image through http://{httpServerIP}:{httpServerPort}/{any}. where {any} can be any non-empty string of numbers or letters.
When the mailbox mode and server mode are turned on at the same time, the real picture will not be sent when sending an email. Only the picture address will be sent to the mailbox, and it will only be sent once. When the QR code expires, just refresh the email. If you only turn on the mailbox mode, the real picture will be sent when sending an email. When the QR code expires, you need to set the email as read (the email will be read after you click on the email with QQ on your mobile phone) before it will be sent. The latest QR code pictures.
If the cmdQrcode item is set to True, the QR code will be displayed in text mode in the term. Note: To use text mode, you need to install the pillow and wcwidth libraries yourself. You can use pip to install them.
Each user in the configuration file has the qq item. If this item has been set to a certain QQ number, QQBot will automatically log in using the login information saved in the last login of this QQ number when it is started.
If the restartOnOffline item is set to True in the configuration file, QQBot will be automatically restarted when it goes offline or terminates with an error.
This option is only valid in UNIX-like systems. Setting the daemon option in the configuration to True will run the program in daemon mode. At this point, standard output and standard error are redirected to the daemon-$qq.log file (where $qq is the value of the qq option in the configuration).
Under normal circumstances, QQBot will be started immediately after scanning the QR code to log in. It will only obtain the contact list and update the contact database when necessary. If startAfterFetch in the configuration file is set to True, QQBot will wait for all contact lists to be obtained before starting . Note that if there are more contacts, it will take a longer time.
After QQBot is started, a QQBot-term server will be opened to monitor the operation commands sent by users through the qq command line tool and the operation commands sent through the HTTP API interface. The listening IP of this server is always 127.0.0.1, and the default listening port number is 8188, this port number can be modified by modifying the value of termServerPort.
If the configured QQBot-term server port number is not the default 8188, then when running the qq command, you need to specify the port number in the first parameter, such as:
$ qq 8100 send buddy jack hello
$ qq 8100 list group-member chatbot
Similarly, the port number of the HTTP API interface also needs to be changed, such as: http://127.0.0.1:8100/send/buddy/jack/hello.
If you do not need to use the qq command and HTTP-API interface, you can set this port number to 0, and the QQBot-term server will not be opened at this time.
If you need to log in to multiple QQ numbers on the same machine, you can directly open multiple qqbot processes in different terminals to log in. However, each qqbot process must set its own termServerPort and httpServerPort (or all set to 0 or empty value), otherwise a port number conflict will occur.
If the debug item is set to True, debugging information will be printed during running.
Generally, plug-ins need to be stored in the system's import directory or ~/.qqbot-tmp/plugins directory. You can configure other storage directories in the pluginPath option. In addition, in the plugins option, you can specify the plugins that need to be loaded when QQBot starts.
All options in the configuration file have corresponding command line parameters, and the options entered in the command line parameters have a higher priority than those in the configuration file. Enter qqbot -h to view all command line parameter formats.
There are four levels of configuration in the program, and their priorities are as follows:
使用 qqbot -u somebody 启动程序时,依次加载:
根配置 -> 默认配置 -> 用户 somebody 的配置 -> 命令行参数配置
使用 qqbot 启动程序时,依次加载:
根配置 -> 默认配置 -> 命令行参数配置
Among them: the root configuration is fixed and cannot be modified by users; the default configuration and user configuration can be modified by users in the v2.x.conf file; finally, configurations can also be entered in command line parameters.
When qqbot is running, it will search/create the following files/directories in the working directory:
The default working directory is ~/.qqbot-tmp/. You can specify other working directories through the command line parameter -b|--bench when starting qqbot, for example: qqbot -b bench.
A plug-in is actually a python module, so it can be a python file or a python package. qqbot will search for plug-ins in the following directories based on the plug-in name:
hot-plug method
You can dynamically load/unload plug-ins during the running of qqbot. There are three methods:
The first two methods are called by external processes of the qqbot process, and the third method is used within the qqbot process. Do not use the first two methods inside the qqbot process.
Note: Plug-ins loaded using the hot-plug method will be lost after qqbot restarts.
auto-plug-at-start mode
You can also automatically load plug-ins when qqbot starts. Just specify the name of the plug-in that needs to be loaded in the plugins option in the configuration (command line parameter -pl|--plugins). These plugins will be loaded at startup, before logging in.
In addition, if there is a package named qqbotdefault in the system (or in the plug-in directory), then all submodules under the package will be automatically loaded as plug-ins at startup (note: qqbotdefault itself will not be loaded as a plug-in).
Writing plug-ins mainly involves writing callback functions or scheduled task functions. See Sections 4 to 6 for details.
name | github author | Function description | Whether to load by default |
---|---|---|---|
qqbot.plugins.sampleslots | pandolia | Callback function example | yes |
qqbot.plugins.schedrestart | pandolia | Scheduled restart | yes |
qqbot.plugins.miniirc | pandolia | IRC server | no |
passwordlogin | pandolia | Log in using username-password | no |
adblock | feisuweb | Group ad blocking | no |
chatlog | feisuweb | Chat content record | no |
If you have any useful plug-ins to share, please send me an email.
Under the Linux system, since the QQ client cannot be used, the plug-in qqbot.plugins.miniirc can be used to implement the IRC chat function. Loading method: qq plug qqbot.plugins.miniirc, or load at startup: qqbot -pl qqbot.plugins.miniirc, or add qqbot.plugins.miniirc
to the plugins option in the configuration file.
After the plug-in is loaded, a micro IRC server will be opened on port 6667. Users can use IRC clients (such as weechat, irssi, etc.) to connect to this server to achieve chat in command line mode. The following uses weechat as an example to introduce how to use it:
启动 weechat : weechat
连接本服务器: /connect localhost
进入 群聊天 会话: /join group-name
进入 讨论组聊天 会话: /join !discuss-name
进入 好友聊天 会话: /query buddy-name
进入 聊天会话 后,直接敲入文本并回车就可以向对方发送消息了。所有接收到的 QQ 消息也会被转发给相应的 聊天会话 。
在聊天会话之间切换: ctrl+P 或 ctrl+N
显示所有 群和讨论组 的名称: /list
The above are almost all the functions provided by this micro IRC server, but it is enough to chat with QQ friends/groups/discussion groups.
QQBot refers to the following open source projects:
I would like to thank the above three authors for their selfless sharing, especially ScienJus for its in-depth and detailed analysis of the SmartQQ protocol.