Python 测试用户在列表中的时间

Python 测试用户在列表中的时间,python,bots,twitch,Python,Bots,Twitch,我正在使用twitch的机器人,它跟踪用户在频道中花费的时间!您在流中花费10秒的时间。但是,当多个用户使用此命令时,!时间对于每个用户,它没有单独的“计数”。例: 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

我正在使用twitch的机器人,它跟踪用户在频道中花费的时间<代码>!您在流中花费10秒的时间。但是,当多个用户使用此命令时,
!时间
对于每个用户,它没有单独的“计数”。例:

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.")

您需要存储与特定用户关联的startTime,例如

userStart = {}

if user in usersForTime:
  ...
  ellapsed = (endTime - userStart[user])
它使用字典查找个人的起始时间

要最初存储它(在
!start
)中,请执行以下操作:


您需要存储与特定用户关联的startTime,例如

userStart = {}

if user in usersForTime:
  ...
  ellapsed = (endTime - userStart[user])
它使用字典查找个人的起始时间

要最初存储它(在
!start
)中,请执行以下操作: