diff --git a/main.py b/main.py index 27e8530..3f4e98d 100644 --- a/main.py +++ b/main.py @@ -6,20 +6,31 @@ import telepot tele_enable=False sign='https://n.cg.163.com/api/v2/sign-today' current='https://n.cg.163.com/api/v2/client-settings/@current' -with open('cookie.txt','r') as f: - cookie=f.read() - f.close +cookie='' +try: + with open('cookie.txt','r') as f: + cookie=f.read() + f.close +except FileNotFoundError as e: + print('[网易云游戏自动签到]无法读取Cookie,请检查是否正确设置Cookie!错误回显为:\n{}'.format(e)) + sys.exit() +except Exception as e: + print('[网易云游戏自动签到]无法读取Cookie,回显为\n{}'.format(e)) + sys.exit() -with open('teleid.txt','r') as f: - teleid=f.read() - f.close() +try: + with open('teleid.txt','r') as f: + teleid=f.read() + f.close() -with open('teletoken.txt','r') as f: - teletoken=f.read() - f.close - -if teletoken!='' and teleid!='': + with open('teletoken.txt','r') as f: + teletoken=f.read() + f.close tele_enable=True +except: + tele_enable=False + +if tele_enable: bot=telepot.Bot(teletoken) @@ -70,6 +81,9 @@ def send(id,message): bot.sendMessage(id, message, parse_mode=None, disable_web_page_preview=None, disable_notification=None, reply_to_message_id=None, reply_markup=None) if __name__ == "__main__": + if cookie=='': + print('[网易云游戏自动签到]未设置Cookie!正在退出……') + sys.exit() me=getme(current,getheader) if(me.status_code!=200): message='[网易云游戏自动签到]签到失败!请检查Cookie是否过期!或者附上报错信息到 https://github.com/GamerNoTitle/wyycg-autosignin/issues 发起issue'