Introduce a,

QQBot is a simple QQ robot implemented in Python and based on Tencent SmartQQ protocol. It can run on Linux, Windows and Mac OSX platforms.

The project is making address: https://github.com/pandolia/qqbot

You can do this by extending QQBot:

  • Monitor and collect QQ messages
  • Automatic message push
  • Chatbot
  • Remote control of your device via QQ

Two, installation method

For use with Python 2.7/3.4/3.5, installed with PIP:


						

							

								pip install qqbot
							

						

					Copy the code

Users of version 2.0 should go to Issue74 first to see the updates and changes for version 2.1.

Note: Most systems with Python already have PIP shipped with them. On Windows, ensure that PIP and Add python.exe to Path are selected when installing Python. If PIP is not present in your system, download get-pip.py from the PIP home page and run it to install PIP to your system.

Three, use method

1. Start the QQBot

Enter qqbot on the command line. During the startup process, the qr code picture will automatically pop up. You need to scan the qr code with the MOBILE QQ client and authorize login. After successful startup, the system saves the login information to a local file. At the next startup, you can enter: QQbot -q QQ number to recover the login information from the local file (manual code scanning is not required). Manual code scanning is required only when the recovery fails or the login information has expired. Generally, saved login information will expire after 2 days.

Note: In Linux, you need to run the gvFs-open or shotwell command to automatically display the QR code image. Generally, the system installed with the GNOME virtual file system GVFS contains either of the two commands. Under Windows10, the system needs to have set the default PNG image file opening program to automatically pop up two-dimensional code pictures.

If the system cannot automatically display a qr code picture, you can manually open the image file or set the display mode of the QR code to email/server/text mode. For details, see Section 7 of this document.

2. QQBot operations

After QQBot is started, use QQ command in another console window to operate QQBot. Currently, the following commands are provided:

1) help, stop and restart command qq help | stop | 2) restart contacts list query command qq buddy | group | discuss | group - member | discuss - member [oqq | oname | okey = oval] [qq | name | key = val] 3) messages send command qq buddy | group | | discuss qq name | key = val message 4) group management command: Qq group-set-admin ginfo minfo1,minfo2,... qq group-unset-admin ginfo minfo1,minfo2,... qq group-set-card ginfo minfo1,minfo2,... card qq group-unset-card ginfo minfo1,minfo2,... qq group-shut ginfo minfo1,minfo2,... [t] qq group-kick ginfo minfo1,minfo2,... 5) Load/uninstall/display the qq plug/unplug plugin-name QQ pluginsCopy the code

The list command provides powerful contact query functions. The following is an example of the command usage:

Qq list buddy mark=jack # list group "456" Qq list group-member456 # list discussion group "XX group" named Jack # list discussion group "XX group" named Jack # list discussion group "XX group" named Jack # list discussion group "XX group" named Jack # Friends qq list discussion-member XX group JackCopy the code

The third, four parameters if it is a key = val format, is should be xx | Nick name = = xx xx | | mark = card = = | qq xx xx format, if not the key = val format, processing according to the following principles: If a string of numbers, then by QQ number query, otherwise, by name query.

If the same name exists, all contacts with the same name are listed. Such as:

Qq List Group robot testCopy the code

All groups named robot Tests will be listed.

The format of the third parameter in the send command is the same as that of the third and fourth parameters in the list command. Note that all contacts with the same name will be sent messages if they have the same name. Note also that the second parameter can only be buddy/group/discuss, not group-member/discuss-member.

You can send emojis to the other person by embedding emojis such as “/ smile” in the message content, as shown in Facemap.py. You can also use the escape characters \n,\t in the message content (for example, send Buddy Jack, line 1 \n, line 2).

The format of ginfo and minfo in the group management command is the same as that of the third and fourth parameters in the list command. Such as:

# set jack, Mike, Jim as the administrator of group "class 456" qq group-set-admin jack, Mike, Jim of class 456 "jm # forbid Jack, Mike, Jim from group" class 456 "to speak (2 minutes) QQ Group-shut class 456 Jack, Mike, JM 120Copy the code

All of the above commands provide the corresponding HTTP API interfaces for web front-end developers to invoke. The URL of the interfaces is http://127.0.0.1:8188/{command}. Just need to qq at the back of the command parameters are replaced with “/” separated in the url command, such as: http://127.0.0.1:8188/send/buddy/jack/hello, and other examples can be found in the urltestbot. TXT. Note: If the command contains Chinese characters or special characters, you need to perform URL encoding (UTF8) first. For example, Call http://127.0.0.1:8188/send/buddy/jack/nihao%20%E4%BD%A0%E5%A5%BD%20wohao will send a message “hi wohao nihao”. (Tip: In JavaScript, you can code using the encodeURIComponent function).

In addition, after the launch of QQBot, use another QQ to send “–version” to this QQ, the QQBot will automatically reply: “QQbot-v2.x.x”.

4. Make your own QQ robot

It is very easy to implement your own QQ robot, just register a message response function of your own. Sample code:

from qqbot import QQBotSlot as qqbotslot, RunBot @qqbotslot def onQQMessage(bot, contact, member, content): If content == '-hello': bot.SendTo(contact, 'hello, I am QQ robot ') elif content == '-stop': Bot. SendTo (contact, 'QQ robot closed) bot. Stop () if __name__ = = "__main__' : RunBot ()Copy the code

Note that the function name of the response function registered above must be “onQQMessage” and the function parameters must be the same as above.

Save the above code as sample.py, shut down the previous QQbot process, and then type “python sample.py -q QQ number” in the command line to start your own QQ robot. At this point, using another QQ to send a message to the QQ “-hello”, will automatically reply “hello, I am QQ robot”, send a message “-stop” will shut down QQ robot.

After QQBot starts to run, every time it receives a QQ message, it will transfer the message source, message content and one QQBot object to the message response function registered above. Among them:

Bot: QQBot object, which provides four interfaces: List/SendTo/Stop/Restart. See Section 5 contact: QContact object, the message sender, ctype/qq/uin/Nick/mark/card/name attribute, these properties are the STR object member: QContact object, valid only if the message is a group or discussion group message and represents the member that actually sent the message. Content: STR object, the content of the messageCopy the code

A QContact object represents a contact, and its ctype attribute can be ‘buddy’/’group’/’discuss’/’group-member’/’ discussion-member ‘, representing a friend/group/discussion group/group member/discussion group member. Note that all QContact objects are read-only and can only read its properties, not set them, or add additional properties to them. The Nick /mark/card/name attributes of QContact objects have different meanings. For details, see contact-Attr-meannings.png.

You can call the SendTo interface of the QQBot object to send a message to the QContact object, but note that you can only send a message to a friend/group/discussion group, not to a group/discussion group member.

In addition to running the sample.py file directly, you can also use the file as a plug-in to load and unload dynamically during the running of QQbot. Save the file in a directory that can be imported from the system (such as Lib/site-packages in the Python installation directory), then run the QQbot. After the QQbot is fully started, enter the QQ Plug sample in another console. You can register the onQQMessage function in this file with the corresponding event of the QQBot. Enter QQ unplugin sample to uninstall this plug-in. Multiple plug-ins can be loaded at the same time, in which case the corresponding functions in each plug-in are called in sequence (but the order in which they are called is independent of the loading order).

If sample.py is loaded as a plug-in, the contents of this file can be simplified to:

def onQQMessage(bot, contact, member, content): if content == '-hello': Bot.SendTo(contact, 'QQ bot is disabled ') elif Content == '-stop': bot.SendTo(contact, 'QQ bot is disabled ') bot.stop ()Copy the code

A plug-in is essentially a module, so it can be either a PY file or a package, as long as it is in a directory that can be imported into the system (section 7 of this document describes how to specify the plug-in directory). It is suggested to use the form of plug-in to expand QQBot.

The extension method of inheriting QQBot class from the original 2.1.10 version can continue to be used, but if this method is used, the plug-in function cannot be used.

Five, QQBot object interface

QQBot object provides a List/SendTo/GroupSetAdmin/GroupSetCard/GroupShut/GroupKick/Stop/Restart eight public interface, in general, please do not call/access the object/attributes of other methods. The following describes the first six interfaces.

(1) the bot. The List (tinfo, [cinfo]) – > [contact0 contact1,…] / [] / None

Corresponds to the list command above. Return a list of QContact objects or None.

The first argument to the List interface, tinfo, can be ‘buddy’/’group’/’discuss’, and the second argument is optional (in the same format as the third argument to the List command). Example:

>>> Bot.List('group', 'bot test ')Copy the code

The first argument to the List interface, tinfo, can also be a QContact object with ctype equal to ‘group’/’discuss’. In this case, a List of members of the group/discussion group is returned. As shown in the second and third sentences below, the list of members of group “class 456” and the list of members of the group whose name card is “Jack” are returned respectively:

> > > g = bot. The List (' group ', "456") [0] > > > bot. The List (g) > > > bot. The List (g, 'card = jack)Copy the code

Bot. List(g, card=’jack’);

The internal execution order of List interface: Firstly, the contact List represented by TINFO is searched in the contact database of QQBot; If the list already exists in the database, search the list and return a list containing “all contacts in this list that match cinfo”; If there is no such list in the database, it requests data from the QQ server to obtain the contact list, and saves the contact list to the database after obtaining the successful contact list, and then searches and returns a list containing “all contacts in this list that match cINFO”; If an error occurs while requesting data from the QQ server, it prints the relevant failure message and returns None.

This interface returns a non-empty List of contacts that match cINFO in the contact List specified by tINFO. Returns an empty list indicating that there are no contacts matching cINFO in the contact list. Returning None indicates that the QQ server failed to request the contact list and data, and does not know if there is a match.

After calling the List interface, it is important to evaluate the return value against the above three cases before executing the subsequent code.

(2) bot.SendTo(contact, content) –> ‘send message to xx ‘/’ error:… ‘

Send messages to contacts. The first argument is the QContact object and the second argument is the message content. Note: You can only send messages to friends/groups/discussion groups, not group members/discussion group members.

You can send emojis to the other person by embedding emojis such as “/ smile” in the message content, as shown in Facemap.py.

If the message is sent successfully, a string (‘ message to xx succeeded ‘) is returned. Otherwise, return a string containing the cause of the error (‘ Error:… ‘).

(3) the bot. GroupXXX (group, membs [arg]) – > [‘ success:… ‘, ‘success:…’, ‘error:…]

Corresponding to the group management command in Section 3, there are four interfaces:

  • GroupSetAdmin(group, membs, admin=True)
  • GroupSetCard(group, memBS, card)
  • GroupShut(group, membs, t=60) bot.GroupShut(group, membs, t=60)
  • GroupKick(group, memBS)

The first parameter group is the group object (the QContact object whose ctype is equal to ‘group’), and the second parameter membs is the list of members being operated on. The return value is the operation information of each member in MEMBS.

Note: 1) the second parameter membs is a list object (e.g. [memb0,memb1… ) instead of a QContact object; 2) If a member of memBS is an administrator, other interfaces other than SetCard may not be valid for it, even though a success message is returned. 3) When using these four interfaces, ensure that the user who logs in is the administrator of the group and all members in MEMBS belong to the group.

Register callback functions, be notified by others @, customize scheduled tasks

Register the callback function

In addition to the above mentioned onQQMessage response function, also can register onNewContact/onLostContact/onInterval/onStartupComplete/onFetchComplete five event callback function, The format and meanings of all events and function parameters are as follows:

@qqbotslot def onQQMessage(bot, contact, member, content): The QQBot object provides four interfaces: List/SendTo/Stop/Restart. For details, see Section 5 # contact: QContact object, the message sender, ctype/qq/uin/name/Nick/mark/card properties, these properties are the STR object # member: QContact, valid only if the message is a group or discussion group message, representing the member that actually sent the message # content: STR object, if content == '--version': bot.SendTo(contact, 'QQbot-' + bot.conf.version) @qqbotslot def onNewContact(bot, contact, owner): Call when adding a new friend/group/discussion group/member/discussion group You can add lists of contacts you care about to monitorTables in the configuration file. If the number of lists in monitorTables is small, the contact change event lag in monitored lists is significantly shorter. QContact object, which represents the new contact # owner: Pass @qqbotSlot def onLostContact(bot, contact, owner): Call when you lose a friend/group/discussion group/group member/discussion group member You can add lists of contacts you care about to monitorTables in the configuration file. If the number of lists in monitorTables is small, the contact change event lag in monitored lists is significantly shorter. Pass @qqbotSlot def onInterval(bot): # owner: QContact (bot): QContact (bot): Pass @qqbotSlot def onStartupComplete(bot): # bot: QQBot object pass@qqbotSlot def onFetchComplete(bot): Called when completing a contact list refresh round # bot: QQBot object passCopy the code

Note: The function name and function parameters (number and name) of the registered response function must be the same as above.

By other members of the group @ notification

When QQBot receives a group message, it will first judge whether someone @ itself according to the message content. If so, a ‘[@me] ‘mark is added to the beginning of the message content, which is passed 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 the sender of the message @. Such as:

@qqbotslot def onQQMessage(bot, contact, member, content): if '@ME' in content: Bot.SendTo(contact, member.name+', thinking of me again ')Copy the code

Customizing scheduled Tasks

From 2.1.13, qqbot provides a powerful function decorator — QQBotSched to customize scheduled tasks. Example code:

From qqbot import QQBotSched as QQBotSched, runbo@qqbotsched (hour='11,17', minute='55') def mytask(bot): Gl = bot.List('group', '456 class ') if gl is not None: for group in gl: bot.SendTo(group, 'comrades: ') if __name__ == '__main__': RunBot()Copy the code

After the above code is run (or loaded as a plug-in), it automatically sends a message to group class 456 every 11:55 and 17:55: “Guys: Dinner la la la la!!” .

Year, month, day, week, day_of_week, hour, minute, second, start_date, end_date, A total of 11 keywords are used as parameters, and each parameter represents the value that the component of the task’s custom time should match. For example, if hour=’11,17′, minute=’55’, and minute=’0-55/5′, the task is executed on xx:x0 or XX :x5.

QQBotSched is a simple encapsulation of Python’s scheduled task framework Apscheduler, and its parameters should be input in the Format of Crontab in Unix. See resources for crontab and Python’s scheduled task framework apScheduler:

  • https://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs–net-8800/
  • http://apscheduler.readthedocs.io/en/latest/userguide.html
  • https://lz5z.com/Python%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%AE%9E%E7%8E%B0%E6%96%B9%E5%BC%8F/
  • http://debugo.com/apscheduler/

Registers callback functions and customizes scheduled task considerations

  • The function name, parameter name, parameter number, and parameter order of the callback function must be the same as those of the preceding six functions.
  • The function name of the scheduled task can be defined by itself, but there is only one parameter. The parameter name must be bot, which is a QQBot object.
  • If written as a plug-in, the @qqbotSlot before the callback function can be omitted, and the @qqbotsched before the scheduled task cannot be omitted.
  • All callback functions and scheduled tasks will be called in the main thread, so there is no need to worry about thread-safety of the data.
  • The running time of all callback functions and scheduled tasks should be as short as possible. Do not perform blocking IO operations in these functions, otherwise the whole program will be blocked.

Vii. Qr code manager, QQBot configuration and command line parameters

Display mode of two-dimensional code

SmartQQ login requires mobile QQ to scan qr code pictures. In QQBot, qr code pictures can be displayed in the following three modes:

  • GUI mode: The QR code picture is automatically displayed on the GUI
  • Mailbox mode: Send the qr code picture to the specified mailbox
  • Server mode: Displays the QR code image in an HTTP server
  • Text mode: Present the QR code in text form in Term (need to install your own pillow library)

GUI mode is the default mode and only works on PCS. Mailbox mode can be applied to personal computers and remote servers. The server mode is used only in the system that has a public IP address. If you use QQ mailbox to receive two-dimensional code, when sending two-dimensional code pictures, the mobile QQ client will immediately receive a notice, open the mail on the mobile QQ client, and then long press the TWO-DIMENSIONAL code can be scanned. The text mode is convenient to use in the development process or server deployment, and provides a shortcut for developers to log in to QQ. Note: The display effect of the text mode in some terminals (such as gnome-Terminal and mate-terminal) is not good.

Note: When the email/server/text mode is enabled, the GUI mode is disabled, and the QR code picture will not automatically pop up when you log in.

Each login will create a QrcodeManager (QrcodeManager object), the QrcodeManager will select the display mode of the qr code image according to the configuration file and command line parameters.

How to use the configuration file

The configuration file is ~/.qqbot-tmp/v2.1.conf. This configuration file will be automatically created after the first run of QQbot, which contains the following contents:

{# QQBot -u [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] [-u] "Somebody" : {# qqbot-term server port number (http-API will also use this port) "termServerPort" : 8188, # qr code HTTP server IP address, please set to public IP address or empty string "httpServerIP" : "127.0.0.1", # QR code HTTP server port number "httpServerPort" : 8189, # automatic login QQ number "QQ" : "3497303033", # receive two-dimensional code picture mailbox account "mailAccount" : "[email protected]", # IMAP/SMTP service authorization code" mailAuthCode" : "FeregFGFTrASdSEW ", # whether to display the TWO-DIMENSIONAL code" cmdQrcode" in text mode: "Debug" : False, # QQBot automatically restarts after offline "restartOnOffline" : False, # fetchInterval: 120, # Start QQBot "startAfterFetch" after completing all contact list fetching: False, # list of contacts to be specially monitored # 'buddy'/'group'/'discuss' indicates that special monitoring is required: # 'group-member-456 class '/' discussion-member-xx group 'indicates that special monitoring is required: # Group "Class 456" Member List/Discussion Group "XX group" Contact change events in member list # If the number of lists in this column is small, the lag time for contact change events in specially monitored lists can be greatly reduced. "monitorTables" : ['buddy', 'group-member-456 '], # pluginPath: ".", # plugins: ['sample1'],}, # pluginPath: {"qq" : "" ", "" ":"}, # pluginPath: { [],}, # # Note: The root configuration is fixed and cannot be modified by users (modifying the root configuration in this file will not take effect) # "Root configuration" : {# "termServerPort" : 8188, # "httpServerIP" : "", # "httpServerPort" : 8189, # "qq" : "", # "mailAccount" : "", # "mailAuthCode" : "", # "cmdQrcode" : False, # "debug" : False, # "restartOnOffline" : False, # "fetchInterval" : 120, # "startAfterFetch" : False, # "monitorTables" : [], # "pluginPath" : "", # "plugins" : [], # }, }Copy the code

You can add your own user configuration to the configuration file (that is, add an item to the dictionary of the file whose key represents a user). For example, the existing Somebody project in the file represents the user named Somebody. When running QQBot, Enter qqbot -u somebody or python sample.py -u somebody to load the configuration of the somebody project.

The following describes the functions of each configuration file in the configuration file. Assume that the configuration of somebody has been modified, and the qqbot -u somebody or Python samp. py -u somebody is used.

Configuring the mailbox mode (mailAccount and mailAuthCode)

To display the TWO-DIMENSIONAL code in email mode, you can set mailAccount and mailAuthCode to the email account and authorization code respectively. After running the mailbox, the TWO-DIMENSIONAL code manager will send the two-dimensional 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 open the IMAP/SMTP service. QQ mailbox can open this service in the webpage version of the mailbox Settings, and get the authorization code. If only mailAccount is defined but mailAuthCode is not defined, this authorization code will be manually entered at the start of the program.

As netease’s mailbox has very limited support for IMAP protocol, it cannot be used in QQBot. QQ’s mailbox has passed the test, but other service providers’ mailboxes have not been tested, so it is suggested to use QQ mailbox.

Server mode configuration (httpServerIP and httpServerPort)

To use the server mode, you can configure httpServerIP and httpServerPort. Generally, set this parameter to a public IP address. Server mode after open, can access the qr code image through http://httpServerIP:httpServerPort/qqbot/qrcode.

When the mailbox mode and server mode are 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 only sent once, when the TWO-DIMENSIONAL code expires, just refresh the email. If only the mailbox mode is enabled, the real picture will be sent when the email. When the TWO-DIMENSIONAL code expires, the email needs to be set as read (after opening the email with mobile QQ, the email is read), and then the latest two-dimensional code picture will be sent.

Automatic login QQ number (QQ)

Each user has the QQ entry in the configuration file. If the entry is set to a CERTAIN QQ number, the system automatically logs in using the saved login information of the last login of the QQ number.

Automatic restart after offline (restartOnOffline)

If restartOnOffline is set to True in the configuration file, the QQBot will be restarted automatically when it is offline or terminated in an error.

fetchInterval

After QQBot starts, it will obtain and update the contact list in the background. When all the contact list is obtained, it will sleep for two minutes and then start the next round of acquisition and update. You can control this timeout by setting the fetchInterval item to another value in seconds in the configuration file. If this value is set to negative, the contact list is retrieved only once (and never again).

Start after the contact list is fetched

Generally speaking, the QQBot will be started immediately after the code-scanning login is completed, and the contact list will be obtained and updated in the background. If startAfterFetch is set to True in the configuration file, the QQBot will wait for all contacts to be fetched before starting. Note that it will take a long time if there are many contacts.

Qqbot-term Server port number (termServerPort)

After QQBot is started, a QQbot-term server will start to monitor the operation commands sent by users through QQ command line tool and HTTP API interface. The default port number of this server is 8188. You can change this port number by changing the value of termServerPort.

If the configured qqbot-term server port number is not the default 8188, you need to specify the port number in the first parameter when running the QQ command, for example:


						

							

								$ qq 8100 send buddy jack hello
							

							

								$ qq 8100 list group-member chatbot
							

						

					Copy the code

Similarly, also need to change the port, the HTTP API interface, such as: http://127.0.0.1:8100/send/buddy/jack/hello.

If you need to log in to multiple QQ numbers on the same machine, you need to set different termServerPort and httpServerPort for different QQ numbers to avoid port conflicts.

Display qr code (cmdQrcode) in text mode

If the cmdQrcode item is set to True, the QR code will be displayed in text mode in term. Note: To use text mode, you need to install the Pillow library yourself, which can be installed using PIP.

Debug mode

If the debug option is set to True, debugging information is displayed during the running.

List of contacts that need to be monitored

Usually contacts change event (onNewContact/onLostContact) lag 5 ~ 10 minutes, can be concerned about the contact list to join in the configuration file monitorTables, if monitorTables the list number is less, The delay time of contact change events in the monitored list is greatly shortened. For example, if the contact of group Class 456 changes, you can set monitorTables = [‘ group-member-class 456 ‘]. The member changes of the group take 1 to 3 seconds.

Plug-in configuration (pluginPath and plugins)

Under normal circumstances, plug-ins need to be stored in the import directory of the system. You can configure the directory of plug-ins in the pluginPath option, and the directory specified by the option can also be dynamically loaded by QQBot. In addition, in the plugins option, you can specify the plugins that need to be loaded when the QQBot starts (note: these plugins need to be saved in the import directory of the system or in the directory specified in the pluginPath).

Command line parameters and configured priorities

All options in the configuration file have corresponding command line parameters. The options entered in the command line parameters have a higher priority than those in the configuration file. Run qqbot -h or python sample.py -h to view all command line parameter formats.

There are four levels of configuration in the program, with the following priorities:

When using qqbot -u somebody to start the program, load it in sequence: root configuration -> Default configuration -> Configuration of user SOMEBODY -> Command line Parameter Configuration When using QQbot to start the program, load it in sequence: root configuration -> Default configuration -> Command line parameter configurationCopy the code

The root configuration is fixed and cannot be modified by users. The default and user configurations can be modified by users in the v2.1.conf file. Finally, you can enter the configuration in command line parameters.

Viii. Smartqq protocol support and restrictions

The project has achieved most of the functions supported by smartQQ protocol, as follows:

  • Message receiving/sending
  • Contact person (including friends/group/discussion group/group member/discussion group member) information acquisition and query (including QQ number/nickname/name/remark name/group member name card)
  • Contact information updates dynamically, notifications of new and lost friends/groups/discussion groups/group members/discussion group members
  • By other members of the group @ notification
  • Group management functions: set the administrator, set the group name card, group members forbidden speech and kick group members
  • Send and receive emojis (see facemap.py)

Other features

  • Call the default picture browser to display the login QR code, send the login QR code to the mailbox, start an HTTP server to display the login QR code, and display the QR code in text mode in the command line window
  • Use THE QQ command line tool to send messages and query contacts
  • Automatic restart after offline (manual code scanning is sometimes required)
  • Scheduled execution of tasks (via QQBotSched)

Due to the limitation of smartQQ protocol, there is no solution to the following problems

  • If the user cannot stay online for a long time, the cookie after each successful login will become invalid every 1 to 2 days and the User will be forcibly logged out by the Tencent server. In this case, the user must manually scan the code to log in again. You can set the two-dimensional code display mode to mailbox mode and enable the automatic restart mode. When you are offline, the system automatically restarts and sends the two-dimensional code to the mailbox to realize remote code scanning
  • Unable to send pictures, files, audio, XML card messages
  • Unable to get messages sent by other clients (mobile QQ, PC-QQ)
  • It is impossible to @ other members in the group. Even if this program is used to send a message like “@Jack XXX” in the group, Jack can only receive the plain text without receiving the reminder of “someone @me”.
  • You cannot send messages to or receive temporary session messages from non-friend members in a group or discussion group
  • In very rare cases, a message will be sent multiple times, or the other party may have received the message but return the result that the message failed to be sent

Ix. Reference materials

QQBot refers to the following open source projects:

  • ScienJus/qqbot (ruby)
  • floatinghotpot/qqbot (node.js)
  • sjdy521/Mojo-Webqq (perl)

I would like to thank the above three authors for their selfless sharing, especially ScienJus for his in-depth analysis of the SmartQQ protocol.