提交 218848be 编写于 作者: L LittleCoder

Add python3 warnings and fix bug reported by tangzhenquan

上级 f9301535
#coding=utf8
import time, sys
if sys.version[:3] != '2.7': print('This project should be run with python2.7');sys.exit()
import itchat.storage, itchat.out, itchat.argparser, itchat.robot
from itchat.client import WeChatClient
from plugin.ChatLikeCMD import ChatLikeCMD
......@@ -8,7 +9,7 @@ from plugin.ChatLikeCMD import ChatLikeCMD
ROBOT = True # change to False if you need to use command line wechat
def demo_robot(s, msgList, client): # ONLY FOR DEMO
print 'Start auto-replying'
print('Start auto-replying')
while 1:
if msgList:
msg = msgList.pop()
......@@ -16,7 +17,7 @@ def demo_robot(s, msgList, client): # ONLY FOR DEMO
time.sleep(.1)
if __name__ == '__main__':
from PluginTest import plugin_load_succeed
if not plugin_load_succeed(): print 'Try to fix the plugins and test them with PluginTest.py';sys.exit()
if not plugin_load_succeed(): print('Try to fix the plugins and test them with PluginTest.py');sys.exit()
client_s = itchat.storage.Storage()
if ROBOT:
......
......@@ -63,7 +63,7 @@ if 'vote' in pluginList['msgdealers']:
sys_print('INFO', 'But whether it can be properly used need to be tested online')
except:
sys_print('WARN', 'Vote plugin loaded failed, this is strange, you need to contact me')
traceback.print_exc()
# traceback.print_exc()
def send_msg(msg):
if len(msg) > 5:
......@@ -97,7 +97,7 @@ if __name__ == '__main__':
send_msg(r)
except:
print 'Exit'
traceback.print_exc()
# traceback.print_exc()
else:
sys_print('INFO', 'Plugin loading finished')
......@@ -26,6 +26,8 @@ ItChat是一个个人微信号的机器人,他实现了一个机器人需要
`python ItChat.py`
本项目基于python 2.7.11开发,使用python 3可能发生异常。
##Plugins
本项目默认开启投票插件与自定义回复插件
......
import requests, time, re
import os, sys
import requests, time, re
import thread, subprocess
import json, xml.dom.minidom, mimetypes
from urllib import unquote
......@@ -138,7 +138,7 @@ class WeChatClient:
for m in memberList:
if m['Sex'] != 0: continue
if (m['VerifyFlag'] & 8 == 0 and '@' in m['UserName'] and not '@@' in m['UserName'] and
any([n in m['UserName'] for n in range(10)]) and any([chr(n) in m['UserName'] for n in (
any([str(n) in m['UserName'] for n in range(10)]) and any([chr(n) in m['UserName'] for n in (
range(ord('a'), ord('z') + 1) + range(ord('A'), ord('Z') + 1))])): continue
memberList.remove(m);i+=1
if i == 0: break
......
#coding=utf8
import itchat.out as out
import itchat.log as log
import PluginTest
from plugin.msgdealers.vote import vote
from plugin.msgdealers.autoreply import autoreply
from PluginTest import *
try:
import plugin.tuling as tuling
......@@ -34,7 +32,7 @@ def deal_with_msg(msg, s, client):
pluginOrder = [('vote', vote), ('autoreply', autoreply)]
getReply = False
for plugin in pluginOrder:
if plugin[0] in PluginTest.pluginList['msgdealers']:
if plugin[0] in pluginList['msgdealers']:
r = plugin[1](content, client.storageClass, msg['FromUserName'])
if r:
send_msg(client, msg['FromUserName'], r)
......
......@@ -27,8 +27,7 @@ def detectFiles(tableName):
fileName = qa[1][5:]
with open(os.path.join(FILE_DIR, fileName)): pass
except:
raise Exception('Error occured when loading "%s" in table %s, it should be in storage/upload'%(
fileName, tableName))
raise Exception('Error occured when loading "%s" in table %s, it should be in storage/upload'%(fileName, tableName))
def getreply():
regexAnsList = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册