stvtermux 1.0.7__tar.gz → 1.0.8__tar.gz
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-1.0.7 → stvtermux-1.0.8}/PKG-INFO +1 -1
- {stvtermux-1.0.7 → stvtermux-1.0.8}/setup.py +1 -1
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux/cli.py +1 -1
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux/core.py +11 -9
- stvtermux-1.0.8/stvtermux/nhom.py +69 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux.egg-info/PKG-INFO +1 -1
- stvtermux-1.0.7/stvtermux/nhom.py +0 -53
- {stvtermux-1.0.7 → stvtermux-1.0.8}/README.md +0 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/pyproject.toml +0 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/setup.cfg +0 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux/__init__.py +0 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux/index.py +0 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux.egg-info/SOURCES.txt +0 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux.egg-info/dependency_links.txt +0 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux.egg-info/entry_points.txt +0 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux.egg-info/requires.txt +0 -0
- {stvtermux-1.0.7 → stvtermux-1.0.8}/stvtermux.egg-info/top_level.txt +0 -0
@@ -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: ")
|
@@ -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)
|
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
|
35
|
+
return None
|
37
36
|
|
38
37
|
data = res.json() or {}
|
39
|
-
for
|
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
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
48
|
+
return None
|
49
|
+
|
50
|
+
|
@@ -0,0 +1,69 @@
|
|
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,53 +0,0 @@
|
|
1
|
-
import requests
|
2
|
-
import json
|
3
|
-
import threading
|
4
|
-
import time
|
5
|
-
import os
|
6
|
-
import sys
|
7
|
-
|
8
|
-
FIREBASE_URL = "https://sever-login-ae5cc-default-rtdb.firebaseio.com/chatnhom.json"
|
9
|
-
|
10
|
-
def listen_messages():
|
11
|
-
last_seen = None
|
12
|
-
while True:
|
13
|
-
try:
|
14
|
-
res = requests.get(FIREBASE_URL)
|
15
|
-
if res.status_code == 200:
|
16
|
-
data = res.json() or {}
|
17
|
-
sorted_msgs = sorted(data.items(), key=lambda x: x[0])
|
18
|
-
for k, v in sorted_msgs:
|
19
|
-
if last_seen is None or k > last_seen:
|
20
|
-
print(f"\n💬 {v.get('name')}: {v.get('msg')}")
|
21
|
-
last_seen = k
|
22
|
-
except Exception:
|
23
|
-
pass
|
24
|
-
time.sleep(2)
|
25
|
-
|
26
|
-
def send_message(name):
|
27
|
-
while True:
|
28
|
-
msg = input("")
|
29
|
-
if msg.strip() == "":
|
30
|
-
continue
|
31
|
-
data = {"name": name, "msg": msg}
|
32
|
-
try:
|
33
|
-
requests.post(FIREBASE_URL, data=json.dumps(data))
|
34
|
-
except Exception:
|
35
|
-
print("❌ Lỗi gửi tin nhắn!")
|
36
|
-
|
37
|
-
def main():
|
38
|
-
os.system("clear")
|
39
|
-
print("══════════════════════════════════════")
|
40
|
-
print("🌐 CHAT NHÓM STVTermux (Realtime) 🌐")
|
41
|
-
print("══════════════════════════════════════")
|
42
|
-
|
43
|
-
# 👉 lấy tên từ sys.argv (username đã login)
|
44
|
-
name = sys.argv[1] if len(sys.argv) > 1 else "Ẩn danh"
|
45
|
-
|
46
|
-
t = threading.Thread(target=listen_messages, daemon=True)
|
47
|
-
t.start()
|
48
|
-
|
49
|
-
print(f"✨ {name}, bắt đầu trò chuyện...")
|
50
|
-
send_message(name)
|
51
|
-
|
52
|
-
if __name__ == "__main__":
|
53
|
-
main()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|