The author's original intention is very simple: because one day the flame of group chat that has lasted for a long time suddenly disappeared... So he made up his mind to complete the script program that can automatically send messages
At present, there are three ways to realize it:
- Mobile terminal (qnotified & other modules supporting java script)
- Linux side (cq robot)
- windows side (python script)
Qnotified & implementation ideas of other frameworks
Send messages by directly calling the api interface provided by Qn
The ugly talk comes first
Disadvantages of this method:
- You cannot enter QQ after opening the script (solution: you must clear the application data of QQ and Qn. At least this happens when I test, and the method I use is effective for me. Different frameworks, versions, modules and environments may affect it)
Therefore, be careful to use chat records and other data, and Qn will return to the default setting after clearing the data
code
//InfoStart //@author: Xiang //@name: automatically send group chat messages to maintain the flame of group chat //@version: 0.2 //@label: beta //@decs: as title //InfoEnd import cc.ioctl.script.QNClient; import java.util.concurrent.TimeUnit; import java.text.SimpleDateFormat; import java.util.Date; public void onLoad(){ while(true){ SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd HH:mm:ss a"); Date date = new Date();// Get current time QNClient.send("752099815","Qnotified Send messages regularly to maintain the flame of group chat"+sdf.format(date),1); //752099815 is the group number, which is modified to the group number you want to send messages TimeUnit.SECONDS.sleep( 60 ); //Wait 60 seconds, or 1 minute } }
Copy, save and import Qn
Linux cq robot
As the name suggests, installing cq robot on Linux can automatically send messages
The scandal comes to the front again
You need a computer and need to turn it on for a long time. If not, you can use vps, hang up treasure (about 5 yuan) or free student servers such as Alibaba cloud and Tencent cloud
Recommend one I'm using myself Hang up treasure platform
3.5 yuan a month
I use go cqhttp
Download according to system requirements
I deployed on raspberry pie
wget https://github.com/Mrs4s/go-cqhttp/releases/download/v1.0.0-beta2/go-cqhttp_1.0.0-beta2_linux_arm64.deb
After downloading, sudo dpkg - I go cqhttp_ 1.0.0-beta2_ linux_ arm64. deb
Go cqhttp directly after installation
The first time you use it, you will report an error. There is no configuration file. After it is automatically generated, press ctrl+c
Then edit config yml
vim config.yml
Fill in your QQ account and password
Press i to enter editing mode
After editing, press esc, then enter the English colon, and then enter wq to save and exit
Then use go cqhttp
If login verification is required, just follow the prompts
I wrote a python script
import requests,time,os,datetime while True: now=str(datetime.datetime.now()) print(now) os.system("curl '127.0.0.1:5700/send_group_msg?access_token=zjs07070277qqfc&group_id=428686902&message=go-cqhttp\u5b9a\u65f6\u53d1\u9001\u6d88\u606f\uff08\u7ef4\u6301\u7fa4\u804a\u70bd\u7130)'") time.sleep(3600)
Send messages every 1 hour
PS: if you use ssh to start go cqhttp, please remember to use the screen or nohup command to avoid killing the program after closing ssh
windows python script
This is a little complicated
It also requires the computer to be turned on for a long time, Hang up treasure website (it is not recommended to buy windows hang up treasure, because the performance is too weak and the experience is very bad)
#Depending on the pywin32 library, please remember pip install pywin32 import time import win32clipboard as w import win32gui,win32con def setText(aString): '''Copy the text to be sent''' w.OpenClipboard() w.EmptyClipboard() w.SetClipboardData(win32con.CF_UNICODETEXT, aString) w.CloseClipboard() def send_Mess(hwnd): '''Paste and press enter to send''' win32gui.PostMessage(hwnd,win32con.WM_PASTE, 0, 0) time.sleep(0.3) win32gui.PostMessage(hwnd,win32con.WM_KEYDOWN,win32con.VK_RETURN,0) win32gui.PostMessage(hwnd,win32con.WM_KEYUP,win32con.VK_RETURN,0) windowtitle = 'Mysterious test group in the alley' #Window title, change to your QQ group chat name (note!!! When opening multiple chat windows, the title will become xx and other x sessions) hwnd = win32gui.FindWindow(None, windowtitle) #Find window handle by window title while True: if hwnd>0: print('find%s'%windowtitle) now= time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) #Time this message was sent setText('Python Send messages regularly to maintain the flame of group chat:'+now) send_Mess(hwnd) time.sleep(10) #Wait 600 seconds, or 10 minutes else: print('Can't find%s'%windowtitle) ''' hwnd_title = dict() def get_all_hwnd(hwnd,mouse): if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd): hwnd_title.update({hwnd:win32gui.GetWindowText(hwnd)}) win32gui.EnumWindows(get_all_hwnd, 0) for h,t in hwnd_title.items(): if t is not "": print(h, t) ''' #If you still don't get the window handle successfully, you can use this code to print out all the current window title names and handles
See my for specific tutorials GitHub blog