瀏覽代碼

Adding idle timer

Kirk Trombley 5 年之前
父節點
當前提交
7ec1152526
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      app.py

+ 8 - 0
app.py

@@ -2,10 +2,13 @@
 
 from telnetlib import Telnet
 from collections import defaultdict
+from datetime import timedelta
 
 import toml
 from flask import Flask, jsonify, render_template_string
 
+IDLE_TIMEOUT = timedelta(minutes=5)
+
 app = Flask(__name__)
 
 
@@ -92,6 +95,11 @@ def get_users():
             audio_status.append("Sound muted")
         if len(audio_status) > 0:
             user_text += f" ({', '.join(audio_status)})"
+        idle = timedelta(milliseconds=int(info["client_info"].get("client_idle_time", "0")))
+        if idle >= IDLE_TIMEOUT:
+            # strip out the sub-second resolution
+            idle -= timedelta(microseconds=idle.microseconds)
+            user_text += f" (Idle for {idle})"
         users.append(user_text)
         channel_users[channels[info["cid"]]].append(user_text)