Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
修正“群名中含某些特殊字符时无法获取到其真实qq,进而无法获取到其成员列表”的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pandolia committed Mar 23, 2017
1 parent 57d4546 commit b957dc3
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 31 deletions.
24 changes: 12 additions & 12 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ QQBot 启动后,在另一个控制台窗口使用 qq 命令来操作 QQBot ,
list 命令提供强大的联系人查询功能,用法示例如下:

# 列出所有好友
list buddy
qq list buddy

# 列出 QQ 为 123456 的群
list group 123456
qq list group 123456

# 列出备注名为 jack 的好友
list buddy mark=jack
qq list buddy mark=jack

# 列出 群“456班” 的所有成员
list group-member 456班
qq list group-member 456班

# 列出 群“456班” 中名片为 “mike” 的成员
list group-member 456班 card=mike
qq list group-member 456班 card=mike

# 列出 讨论组“XX小组” 中名为 jack 的好友
list discuss-member XX小组 jack
qq list discuss-member XX小组 jack

其中第三、四个参数如果是 key=val 的格式,则应为 name=xx|nick=xx|mark=xx|card=xx|qq=xx|uin=xx 的格式,如果不是 key=val 的格式,则按以下原则进行处理:若是一串数字,则按 QQ 号进行查询,否则,按名称进行查询。

如果存在重名现象,会列出所有重名的联系人。如:

list group 机器人测试
qq list group 机器人测试

将列出所有名为 “机器人测试” 的群。

Expand Down Expand Up @@ -309,6 +309,11 @@ GUI 模式是默认的模式,只适用于个人电脑。邮箱模式可以适
+ 掉线后自动重启功能(有时需要手工扫码)
+ 定时执行任务(通过注册 onInterval 函数实现)

#### smartqq 协议支持、但尚未实现的功能

+ 群成员禁言、踢除群成员等群管理功能
+ 发送表情

#### 因 smartqq 协议的限制,以下问题无解决办法

+ 无法长时间保持在线状态,每次登录成功后的 cookie 会每在 1 ~ 2 天后失效,将被腾讯服务器强制下线,此时 **必须** 手工扫码重新登录。可以将二维码显示模式设置为邮箱模式并打开自动重启模式,在被下线时自动重启并将二维码发送到邮箱,实现远程扫码
Expand All @@ -318,11 +323,6 @@ GUI 模式是默认的模式,只适用于个人电脑。邮箱模式可以适
+ 无法向 群/讨论组 内的其他非好友成员发消息,也无法收到非好友成员发过来的临时会话消息
+ 在非常少的情况下,发消息时会重复发送多次,也可能对方已收到消息但返回发送失败的结果

#### smartqq 协议支持、但尚未实现的功能

+ 群成员禁言、踢除群成员等群管理功能
+ 发送表情

九、其他
-------------

Expand Down
4 changes: 4 additions & 0 deletions changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2017-03-23 qqbot v2.1.3
1) 修正“群名中含某些特殊字符时无法获取到其真实qq,进而无法获取到其成员列表”的bug。感谢网友 SuperMarioSF 和 某10 的帮助和反馈。


2017-03-22 qqbot v2.1.2
1) 细化文档,增加 List 接口返回值的含义说明;增加 QContact 对象的 nick/mark/card/name 的属性的含义说明。
2) 增加针对 “获取好友列表有时返回的json中没有备注名列表” 的情况的处理。
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from qqbot import Main; Main()
10 changes: 10 additions & 0 deletions qqbot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,13 @@ def AutoTest():
else:
raw_input()
sys.stdout.write('\n')

if not PY3:
import HTMLParser; htmlUnescape = HTMLParser.HTMLParser().unescape
def HTMLUnescape(s):
s = s.replace(' ', ' ')
return htmlUnescape(s.decode('utf8')).encode('utf8')
else:
import html.parser; htmlUnescape = html.parser.HTMLParser().unescape
def HTMLUnescape(s):
return htmlUnescape(s.replace(' ', ' '))
2 changes: 1 addition & 1 deletion qqbot/mainloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self):
def Put(self, func, *args, **kwargs):
self.mainQueue.put((func, args, kwargs))

# Put a task into a child queue with label `queueLabel`. It will be
# Put a task into a child queue which with label `queueLabel`. It will be
# executed in a child thread. Normally, it is a good idea to put an IO
# task into a child queue, and when this task finishs his job, he put
# a committing task with his result into the main queue.
Expand Down
2 changes: 1 addition & 1 deletion qqbot/qconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if p not in sys.path:
sys.path.insert(0, p)

version = 'v2.1.2'
version = 'v2.1.3'

sampleConfStr = '''{
Expand Down
2 changes: 1 addition & 1 deletion qqbot/qcontactdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def autoUpdate(self, args):

PutTo('auto-fetch', self.fetchUpdate, tinfo, needFetch, args)

# in child thread 'fetch'
# in child thread 'auto-fetch'
def fetchUpdate(self, tinfo, needFetch, args):
if needFetch:
table = self.autoSession.FetchTable(tinfo)
Expand Down
6 changes: 4 additions & 2 deletions qqbot/qqbotcls.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ def Login(self, qq=None, user=None):
self.StrOfList = contactdb.StrOfList
self.find = contactdb.Find

# child thread 1/2/3
# child thread 1/2
self.poll = session.Copy().Poll
self.updateForever = contactdb.UpdateForever
self.termForver = QTermServer(self.conf.termServerPort).Run

# runs in main thread, but puts tasks into child thread 3
self.updateForever = contactdb.UpdateForever

def Run(self):
import qqbot.qslots as _x; _x
Expand Down
38 changes: 25 additions & 13 deletions qqbot/qsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from qqbot.qcontactdb import QContactDB,QContactTable,GetCTypeAndOwner,CTYPES
from qqbot.utf8logger import WARN, INFO, DEBUG, ERROR
from qqbot.basicqsession import BasicQSession, RequestError
from qqbot.common import JsonDumps
from qqbot.common import JsonDumps, HTMLUnescape

def QLogin(qq=None, user=None):
conf = QConf(qq, user)
conf = QConf(qq, user)
conf.Display()

if conf.qq:
Expand Down Expand Up @@ -87,7 +87,8 @@ def fetchBuddyTable(self):
qqDict = collections.defaultdict(list)
for blist in list(qqResult.values()):
for d in blist.get('mems', []):
name = d['name'].replace(' ', ' ').replace('&', '&')
# name = d['name'].replace(' ', ' ').replace('&', '&')
name = HTMLUnescape(d['name'])
qqDict[name].append(str(d['uin']))

for info in result['info']:
Expand Down Expand Up @@ -155,8 +156,8 @@ def fetchGroupTable(self):
qqDict = collections.defaultdict(list)
for k in ('create', 'manage', 'join'):
for d in qqResult.get(k, []):
name = d['gn'].replace(' ', ' ').replace('&', '&')
qqDict[name].append(str(d['gc']))
# name = d['gn'].replace(' ', ' ').replace('&', '&')
qqDict[HTMLUnescape(d['gn'])].append(str(d['gc']))

for info in result['gnamelist']:
uin = str(info['gid'])
Expand All @@ -165,17 +166,26 @@ def fetchGroupTable(self):

qqlist = qqDict.get(name, [])
if len(qqlist) == 1:
qq = qqlist.pop()
qq = qqlist[0]
qqDict.pop(name)
elif len(qqlist) == 0:
qq = self.fetchGroupQQ(uin)
for xname, qqlist in qqDict.items():
for trueQQ in qqlist:
if qq[-6:] == trueQQ[-6:]:
qq = trueQQ
if len(qqlist) == 1:
qqDict.pop(xname)
else:
qqlist.remove(qq)
break
else:
qq = self.fetchGroupQQ(uin)
for x in qqlist:
if qq[-6:] == x[-6:]:
qq = x
for trueQQ in qqlist:
if qq[-6:] == trueQQ[-6:]:
qq = trueQQ
qqlist.remove(qq)
break
try:
qqlist.remove(qq)
except ValueError:
pass

groupTable.Add(uin=uin, name=(mark or name), nick=name, qq=qq,
mark=mark, gcode=str(info['code']))
Expand Down Expand Up @@ -217,6 +227,8 @@ def fetchGroupMemberTable(self, group):
for m in r['mems']:
qq, nick, card = \
str(m['uin']), str(m['nick']), str(m.get('card', ''))
nick = HTMLUnescape(nick)
card = HTMLUnescape(card)
memb = [qq, nick, card]
qqDict[qq] = memb
nickDict[nick].append(memb)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

version = '2.1.2'
version = '2.1.3'

setup(
name = 'qqbot',
Expand Down

0 comments on commit b957dc3

Please sign in to comment.