stvtermux 1.0.6__py3-none-any.whl → 1.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
stvtermux/cli.py CHANGED
@@ -5,7 +5,7 @@ def main():
5
5
 
6
6
  print("===== 🌐 STVTermux Login System 🌐 =====")
7
7
  while True:
8
- choice = input("👉 Bạn muốn:\n(1) Đăng ký hay\n(2) Đăng nhập? ")
8
+ choice = input("👉 Bạn muốn:\n(1) Đăng ký hay\n(2) Đăng nhập ")
9
9
  if choice == "1":
10
10
  u = input("username: ")
11
11
  p = input("password: ")
stvtermux/core.py CHANGED
@@ -1,7 +1,6 @@
1
1
  import requests
2
2
  import json
3
3
  import subprocess
4
- import os
5
4
 
6
5
  FIREBASE_URL = "https://sever-login-ae5cc-default-rtdb.firebaseio.com/player.json"
7
6
 
@@ -29,20 +28,23 @@ class Auth:
29
28
  print("❌ Đăng ký thất bại!")
30
29
  return False
31
30
 
32
- def login(self, username: str, password: str) -> bool:
31
+ def login(self, username: str, password: str):
33
32
  res = requests.get(self.firebase_url)
34
33
  if res.status_code != 200:
35
34
  print("❌ Lỗi kết nối server!")
36
- return False
35
+ return None
37
36
 
38
37
  data = res.json() or {}
39
- for _, user in data.items():
38
+ for user_id, user in data.items():
40
39
  if user.get("username") == username and user.get("password") == password:
41
40
  print("✅ Đăng nhập thành công!")
42
- # 👉 Lấy đường dẫn tuyệt đối tới index.py trong package
43
- module_path = os.path.join(os.path.dirname(__file__), "index.py")
44
- subprocess.run(["python", module_path])
45
- return True
41
+ # Ghi user_id ra file tạm để nhom.py đọc
42
+ with open("user.json", "w", encoding="utf-8") as f:
43
+ json.dump({"user_id": user_id}, f)
44
+ subprocess.run(["python", "index.py"])
45
+ return user_id
46
46
 
47
47
  print("❌ Sai username hoặc password!")
48
- return False
48
+ return None
49
+
50
+
stvtermux/nhom.py CHANGED
@@ -1 +1,69 @@
1
- print("🎉 Xin chào! Bạn đã vào file nhóm.py")
1
+ import requests
2
+ import threading
3
+ import time
4
+ import json
5
+ import os
6
+
7
+ FIREBASE_CHAT = "https://sever-login-ae5cc-default-rtdb.firebaseio.com/chatnhom.json"
8
+ FIREBASE_PLAYER = "https://sever-login-ae5cc-default-rtdb.firebaseio.com/player.json"
9
+
10
+ # Lấy tên user từ player.json dựa vào user_id
11
+ def get_name(user_id: str) -> str:
12
+ try:
13
+ res = requests.get(FIREBASE_PLAYER)
14
+ if res.status_code != 200:
15
+ return "Ẩn danh"
16
+ data = res.json() or {}
17
+ user = data.get(user_id, {})
18
+ return user.get("username", "Ẩn danh")
19
+ except Exception:
20
+ return "Ẩn danh"
21
+
22
+ # Luồng hiển thị tin nhắn
23
+ def listen_messages():
24
+ last_data = None
25
+ while True:
26
+ try:
27
+ res = requests.get(FIREBASE_CHAT)
28
+ if res.status_code == 200:
29
+ data = res.json() or {}
30
+ if data != last_data:
31
+ os.system("clear")
32
+ print("===== 💬 Tin nhắn nhóm =====")
33
+ for _, msg in data.items():
34
+ print(f"[{msg.get('name')}] {msg.get('text')}")
35
+ print("============================")
36
+ last_data = data
37
+ except Exception as e:
38
+ print("❌ Lỗi khi lấy tin nhắn:", e)
39
+ time.sleep(2)
40
+
41
+ def chat():
42
+ # Đọc user_id từ file user.json
43
+ try:
44
+ with open("user.json", "r", encoding="utf-8") as f:
45
+ user_data = json.load(f)
46
+ user_id = user_data.get("user_id")
47
+ except FileNotFoundError:
48
+ print("❌ Bạn chưa đăng nhập!")
49
+ return
50
+
51
+ name = get_name(user_id)
52
+ print(f"👋 Xin chào {name}, bạn đã vào nhóm chat!")
53
+
54
+ threading.Thread(target=listen_messages, daemon=True).start()
55
+
56
+ while True:
57
+ text = input("✍️ Nhập tin nhắn: ")
58
+ if text.lower() in ["exit", "quit"]:
59
+ print("👋 Thoát nhóm chat...")
60
+ break
61
+
62
+ msg = {"name": name, "text": text}
63
+ try:
64
+ requests.post(FIREBASE_CHAT, data=json.dumps(msg))
65
+ except Exception as e:
66
+ print("❌ Lỗi gửi tin nhắn:", e)
67
+
68
+ if __name__ == "__main__":
69
+ chat()
@@ -1,5 +1,5 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stvtermux
3
- Version: 1.0.6
3
+ Version: 1.0.8
4
4
  Requires-Dist: requests
5
5
  Dynamic: requires-dist
@@ -0,0 +1,10 @@
1
+ stvtermux/__init__.py,sha256=bk7kIC3tSACeEbiYSYrJEpHxwr6DswGbO-18EF-MDwM,45
2
+ stvtermux/cli.py,sha256=hpK610GHWzm526R3M6H5zlFdxgcWjBcLbm7lXZdK5K4,543
3
+ stvtermux/core.py,sha256=WN6F7EBvZcgQMV5KHbGZGNXofUeuYm2qqLIHt624D4I,1809
4
+ stvtermux/index.py,sha256=QazhR3QhyKZO3Uc3x_TapRCduCStOtxWT2HY5xfQ5gY,999
5
+ stvtermux/nhom.py,sha256=QsGAp-hdTUa2HBaieG1XwQwLPTaG7cxjPdnMfDTDrXE,2262
6
+ stvtermux-1.0.8.dist-info/METADATA,sha256=oM6WAiRnewg8jwuVyvZ4Usegi0OhGnK8TnzkI_-HKRs,100
7
+ stvtermux-1.0.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ stvtermux-1.0.8.dist-info/entry_points.txt,sha256=7b0IuLqKSWL2VMJxcTdMLZXBaPfYT1atz6wwBTqco9Q,43
9
+ stvtermux-1.0.8.dist-info/top_level.txt,sha256=6krSSYES7OG83FeLt7MWD5vG8MOwzYh_K3ju8lBNqwg,10
10
+ stvtermux-1.0.8.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- stvtermux/__init__.py,sha256=bk7kIC3tSACeEbiYSYrJEpHxwr6DswGbO-18EF-MDwM,45
2
- stvtermux/cli.py,sha256=pmjeY6GyZMqPiXN_lzdrScaG5gBFtS7EHlhmb_Ld1PM,544
3
- stvtermux/core.py,sha256=mTFyeko7yw9b38ZV6mDMcWC7L83Rbn3cPjAJUi2xhHY,1798
4
- stvtermux/index.py,sha256=QazhR3QhyKZO3Uc3x_TapRCduCStOtxWT2HY5xfQ5gY,999
5
- stvtermux/nhom.py,sha256=lYBP6NHk-yN1eCiRwE5uPrM__ZUuzrdNYlDW6Icvs8Y,54
6
- stvtermux-1.0.6.dist-info/METADATA,sha256=kd93lyGgYs0cknwst0RmZQbB9OfkHx-miZcERom2e9s,100
7
- stvtermux-1.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- stvtermux-1.0.6.dist-info/entry_points.txt,sha256=7b0IuLqKSWL2VMJxcTdMLZXBaPfYT1atz6wwBTqco9Q,43
9
- stvtermux-1.0.6.dist-info/top_level.txt,sha256=6krSSYES7OG83FeLt7MWD5vG8MOwzYh_K3ju8lBNqwg,10
10
- stvtermux-1.0.6.dist-info/RECORD,,