Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #138 from szsam/master
Browse files Browse the repository at this point in the history
修复tucao插件的两个bug

1. 文件打开模式应为二进制模式
2. 重复学习同一 key-value 对会导致这个 key 下的其他 value 被删除,已修复此 BUG
  • Loading branch information
Yinzo authored Sep 1, 2017
2 parents 0ba8a2d + 18a19f4 commit f9e0d0c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/smart_qq_plugins/tucao.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def save(self, group_id):
global TUCAO_PATH
try:
tucao_file_path = TUCAO_PATH + str(group_id) + ".tucao"
with open(tucao_file_path, "w+") as tucao_file:
with open(tucao_file_path, "wb") as tucao_file:
cPickle.dump(self.tucao_dict[str(group_id)], tucao_file)
logger.info("RUNTIMELOG tucao saved. Now tucao list: {0}".format(str(self.tucao_dict)))
except Exception:
Expand All @@ -45,7 +45,7 @@ def load(self, group_id):
if not os.path.isdir(TUCAO_PATH):
os.makedirs(TUCAO_PATH)
if not os.path.exists(tucao_file_path):
with open(tucao_file_path, "w") as tmp:
with open(tucao_file_path, "wb") as tmp:
tmp.close()
with open(tucao_file_path, "rb") as tucao_file:
try:
Expand Down Expand Up @@ -78,10 +78,10 @@ def tucao(msg, bot):
if command == 'learn':
if group_id not in core.tucao_dict:
core.load(group_id)
if key in core.tucao_dict[group_id] and value not in core.tucao_dict[group_id][key]:
core.tucao_dict[group_id][key].append(value)
else:
if key not in core.tucao_dict[group_id]:
core.tucao_dict[group_id][key] = [value]
elif value not in core.tucao_dict[group_id][key]:
core.tucao_dict[group_id][key].append(value)
reply("学习成功!快对我说" + str(key) + "试试吧!")
core.save(group_id)
return True
Expand Down

0 comments on commit f9e0d0c

Please sign in to comment.