2017-01-23 9 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() 
関連する問題