测试用户在列表中的时间
Testing how long a user has been in a list
我正在使用 twitch 机器人,它会跟踪用户在频道中花费的时间。 !time You have spent 10 seconds in the stream
。但是,当多个用户使用此命令时 !time
它没有为每个用户单独的 'count'。例如:
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.")
您需要存储与特定用户关联的开始时间,例如
userStart = {}
if user in usersForTime:
...
ellapsed = (endTime - userStart[user])
它使用字典来查找个人的开始时间。
原始存储(在!start
):
userStart[user] = time.time()
我正在使用 twitch 机器人,它会跟踪用户在频道中花费的时间。 !time You have spent 10 seconds in the stream
。但是,当多个用户使用此命令时 !time
它没有为每个用户单独的 'count'。例如:
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.")
您需要存储与特定用户关联的开始时间,例如
userStart = {}
if user in usersForTime:
...
ellapsed = (endTime - userStart[user])
它使用字典来查找个人的开始时间。
原始存储(在!start
):
userStart[user] = time.time()