From ce70b2da1969a4fa7dcb5dc411c5b747afe3807f Mon Sep 17 00:00:00 2001 From: szsam Date: Thu, 31 Aug 2017 11:28:02 +0800 Subject: [PATCH 1/2] Fix: Files should be opened in binary mode --- src/smart_qq_plugins/tucao.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/smart_qq_plugins/tucao.py b/src/smart_qq_plugins/tucao.py index 250cb41..79e2d5a 100644 --- a/src/smart_qq_plugins/tucao.py +++ b/src/smart_qq_plugins/tucao.py @@ -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: @@ -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: From 18a19f4edab05ec04cdf43cdc8648b27488eee15 Mon Sep 17 00:00:00 2001 From: szsam Date: Thu, 31 Aug 2017 11:32:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20=E5=BD=93=E9=87=8D=E5=A4=8D=E5=AD=A6?= =?UTF-8?q?=E4=B9=A0=E5=90=8C=E4=B8=80key-value=20pair=E6=97=B6=EF=BC=8Ctu?= =?UTF-8?q?cao=5Fdict=E5=BA=94=E4=BF=9D=E6=8C=81=E4=B8=8D=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/smart_qq_plugins/tucao.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/smart_qq_plugins/tucao.py b/src/smart_qq_plugins/tucao.py index 79e2d5a..b75301b 100644 --- a/src/smart_qq_plugins/tucao.py +++ b/src/smart_qq_plugins/tucao.py @@ -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