一:go-cqhttp 下载
go-cqhttp 帮助中心https://docs.go-cqhttp.org/
?
?
我的是ubuntu18 64bit?
sudo dpkg -i xxx.deb
dpkg -i --instdir=/dest/dir/path xxx.deb //在指定位置安装
运行
./go-cqhttp
我选择了0
Http 通信
?
?device.json 改成了安卓
二:Flask
pip 安装 两个库
flask? ? ?gevent
pip install flask -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install gevent -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
?bot.py
# coding:UTF-8
from flask import Flask, request
from gevent import pywsgi
import api
app = Flask(__name__)
'''监听'''
@app.route('/', methods=["POST"])
def post_data():
if request.get_json().get('message_type')=='private':
uid = request.get_json().get('sender').get('user_id')
message = request.get_json().get('raw_message')
api.keyword(message, uid)
if request.get_json().get('message_type')=='group':
gid = request.get_json().get('group_id')
uid = request.get_json().get('sender').get('user_id')
message = request.get_json().get('raw_message')
api.keyword(message, uid, gid)
'''
message_type 是消息类型群聊或私聊 uid 是qq号 gid 是群号默认为空
'''
if __name__ == '__main__':
#app.run(debug=True, host='127.0.0.1', port=8000)
server = pywsgi.WSGIServer(('127.0.0.1',5701),app)
server.serve_forever()
api.py
# coding:UTF-8
import json
import time
import requests
import re
import random
'''message 是客户端传来的信息'''
''' go-http上看一看基本上就没啥问题'''
def keyword(message, uid, gid = None):
if message[0:4] == 'help':
if(gid==None):
requests.get(url='http://127.0.0.1:5700/send_private_msg?user_id='+str(uid)+'&message='+'help\n点歌\n setu\nssetu)')
else:
requests.get(url='http://127.0.0.1:5700/send_group_msg?group_id='+str(gid)+'&message='+'help\n点歌\n setu\nssetu )')
elif message[0:2] == '点歌':
if(gid==None):
requests.get(url='http://127.0.0.1:5700/send_private_msg?user_id='+str(uid)+'&message='+dg(message))
else:
requests.get(url='http://127.0.0.1:5700/send_group_msg?group_id='+str(gid)+'&message='+dg(message))
elif message[0:2] == 'at':
at()
#setu 的 url = 'https://api.ghser.com/random/pc.php'
#requests
#别人的API自己的不太好就不放出来了
def at():
requests.get(url='http://127.0.0.1:5700/send_group_msg?group_id='+'*********//群号'+'&message='+'[CQ:at,qq=all]')
def dg(s):
a,b = s.split()
urll = 'https://api.iyk0.com/wymusic/?msg='+b+'&n=1'
music_api = requests.get(urll).json()
name = music_api['song']
autor = music_api['singer']
img = music_api['img']
url_url = music_api['url']
cq = f'[CQ:music,type=custom,audio={url_url},title={name},content={autor},image={img}]'
return cq;
大体就是这个格式,可以根据自己的爱好写功能?...我连接挂机宝的工具是
?以前下载的也忘了在哪里下的了,百度上应该可以找到
ssh连接后先下载go-cqhttp,安装好以后,把代码拷贝到同一目录下其实就两个.py
新建两个screen
screen -S xxx
查看已创建的
screen -ls
打开
screen -r xxx.xxx
删除
screen -S xxx.xxx -X quit
在screen中运行./bot ./go-cqhttp
扫描登陆
ctrl + a + d 退出不会结束进程
CQ码https://docs.go-cqhttp.org/cqcode/#qq-%E8%A1%A8%E6%83%85CQ码很方便好用
APIhttps://api.iyk0.com/
APIhttp://api.api.kingapi.cloud/?
在Linux上比在Window上要麻烦一点 ,自己写的比较很粗糙简陋
|