QQ 自动聊天机器人
Projects
Overview
In the github document
Installation:
pip install qqbot
Run:
qqbot
#or in these way
qqbot -q qqnumber
See help or others:
qq help|stop|restart|fresh-restart
Plugin
qq plug/unplug myplugin
Create a bot
urllib, url request
Use the ‘图灵机器人’ API:
# -*- coding: utf-8 -*-
import json
import urllib
import random
def onQQMessage(bot, contact, member, content):
api_url = "http://openapi.tuling123.com/openapi/api/v2"
req = {
"perception":
{
"inputText":
{
"text": content
},
"selfInfo":
{
"location":
{
"city": "西安",
"province": "陕西",
"street": "高新二路"
}
}
},
"userInfo":
{
"apiKey": "2da9ae73b65f4cce8cff91fc027fa---",
"userId": "OnlyUseAlphabet"
}
}
req = json.dumps(req).encode('utf8')
http_post = urllib.request.Request(api_url, data=req, headers={
'content-type': 'application/json'})
response = urllib.request.urlopen(http_post)
response_str = response.read().decode('utf8')
response_dic = json.loads(response_str)
intent_code = response_dic['intent']['code']
results_text = response_dic['results'][0]['values']['text']
if content is not None and contact.ctype == 'buddy':
# bot.SendTo(contact, results_text, resendOn1202=True)
bot.SendTo(contact, results_text)
Timed transmission
@qqbotsched(hour='10, 11, 12, 13, 14', minute='01')
def sendMyMessage(bot):
gl = bot.List('buddy', 'Jack')
if gl is not None:
for member in gl:
bot.SendTo(member, 'Hi, this is a TimingMessage!') 修改历史8 次提交
- refactor: reorganize documentation structure and update Navbar componentxiaocheng··
2fb8f42 - chore(project): clean up obsolete configuration and build artifactsxiaocheng··
3574bd3 - new struct for lblogsxiaocheng··
8c9b28e - move blogs to docsxiaocheng··
c8535a0 - update fix: timeline errorchenweigao··
fb4b591 - update Datechenweigao··
3c14689 - init v3chenweigao··
b770fc2 - init v2chenweigao··
505f81b