2017-01-23 4 views
1

저는 트 위치에 봇을 사용하고 있으며 사용자가 채널에서 보낸 시간을 추적합니다. !time You have spent 10 seconds in the stream. 그러나 여러 사용자가이 명령을 사용하는 경우 !time 각 사용자마다 별도의 '개수'가 없습니다. 예 :사용자가 목록에 얼마나 오랫동안 있었는지 테스트

Rustie: !time 
Bot: Rustie, you have 20 seconds in the stream. 
~1 minute later~ 
John: !time 
Bot: John, you have 1 minute 20 seconds in the stream. 

내 현재 코드 :

usersForTime = [] 

if "time" in message: 
    if user in usersForTime: 
     endTime = time.time() # I already made startTime in the !start command (which starts the time tracker in the first place) 
     ellapsed = (endTime - startTime) 
     sendMessage(s, user + ", you have " + "%.2f" % round(ellapsed, 2) + " seconds in the stream.") 
    else: 
     sendMessage(s ,"You need to start tracking your time with the !start command.") 

답변

0

당신은 startTime을 특정 사용자와 관련된 저장할 수 있습니다, 뭔가 찾기 위해 사전을 사용

userStart = {} 

if user in usersForTime: 
    ... 
    ellapsed = (endTime - userStart[user]) 

같은 개인의 startTime.

은 (!start에) 원래를 저장하려면

userStart[user] = time.time()