fix non-login too loud bug

This commit is contained in:
2017-08-31 00:37:03 +08:00
parent 0af291be07
commit 360f6b820b

12
bot.py
View File

@ -32,21 +32,21 @@ def on_chat(msg):
if content_type == 'text': if content_type == 'text':
# pre-treat the command # pre-treat the command
command = [msg['text']] command = [msg['text']]
if msg['text'][0] == '/': if msg['text'].startswith('/'):
command = msg['text'].replace(config.NAME, '').replace('_', ' ').lower().split(' ') command = msg['text'].replace(config.NAME, '').replace('_', ' ').lower().split(' ')
# first-time user # first-time user
if user.status == '第一次用': if user.status == '第一次用':
if chat_type == 'private': if chat_type == 'private':
user.new_user() user.new_user()
else: elif msg['text'].startswith('/'):
bot.sendMessage(chat_id, "請先私訊我登入 kCOJ", reply_to_message_id=msg['message_id']) bot.sendMessage(chat_id, "請先私訊我登入 kCOJ", reply_to_message_id=msg['message_id'])
# press password # press password
elif user.status == '輸入學號': elif user.status == '輸入學號':
if chat_type == 'private': if chat_type == 'private':
user.press_password(msg['text']) user.press_password(msg['text'])
else: elif msg['text'].startswith('/'):
bot.sendMessage(chat_id, "請先私訊我登入 kCOJ", reply_to_message_id=msg['message_id']) bot.sendMessage(chat_id, "請先私訊我登入 kCOJ", reply_to_message_id=msg['message_id'])
# login # login
@ -145,13 +145,9 @@ with open('users.json', 'r') as f:
MessageLoop(bot, on_chat).run_as_thread() MessageLoop(bot, on_chat).run_as_thread()
print("Started! Service is available.") print("Started! Service is available.")
count = 0
while True: while True:
time.sleep(1) time.sleep(1)
count += 1
if count == 5:
bot.getMe()
count = 0
# backup # backup
users_backup = {} users_backup = {}