dcchbot 1.9.3__tar.gz → 1.9.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dcchbot
3
- Version: 1.9.3
3
+ Version: 1.9.4
4
4
  Summary: 一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告
5
5
  Author-email: I_am_from_taiwan <102109040j@gmail.com>
6
6
  License: MIT
@@ -13,25 +13,54 @@ from discord.ext import commands
13
13
  from discord.utils import utcnow
14
14
  import random as rd
15
15
  package = "dcchbot"
16
- CURRENT_VERSION = "1.9.3"
17
- API_URL = f"https://pypi.org/pypi/{package}/json"
16
+ CURRENT_VERSION = "1.9.4"
17
+ API_PYPI_URL = f"https://pypi.org/pypi/{package}/json"
18
+ API_MY_URL = "10.112.101.32:194/dcchbot.json"
19
+ API_URL = None
20
+ if API_PYPI_URL <= API_MY_URL:
21
+ API_URL = API_MY_URL
22
+ elif API_PYPI_URL >= API_MY_URL:
23
+ API_URL = API_PYPI_URL
24
+ else:
25
+ API_URL = API_MY_URL
18
26
  test = rd.random()
19
27
  ttt = time.time()
20
28
  tb = tb
21
- try:
22
- response = requests.get(API_URL, timeout=5)
23
- response.raise_for_status() # HTTP 錯誤會直接丟例外
24
- data = response.json()
25
- latest_version = data["info"]["version"]
26
-
27
- if latest_version != CURRENT_VERSION:
28
- print(f"⚠ 有新版本可用: {latest_version}(目前版本 {CURRENT_VERSION})")
29
- else:
30
- print(f"✅ 目前已是最新版 {CURRENT_VERSION}")
31
-
32
- except Exception as e:
33
- latest_version = CURRENT_VERSION # 失敗時至少不讓變數缺失
34
- print(f"❌ 無法檢查更新:{e}")
29
+ def choose_api_url():
30
+ """優先使用內網 API,失敗則 fallback 到 PyPI"""
31
+ try:
32
+ r = requests.get(API_MY_URL, timeout=2)
33
+ if r.status_code == 200:
34
+ logger.info("使用內網 API 檢查更新")
35
+ return API_MY_URL
36
+ except Exception as e:
37
+ logger.warning(f"內網 API 無法連線,使用 PyPI:{e}")
38
+ return API_PYPI_URL
39
+
40
+ def check_update():
41
+ """檢查是否有新版本"""
42
+ api_url = choose_api_url()
43
+ try:
44
+ r = requests.get(api_url, timeout=5)
45
+ r.raise_for_status()
46
+ data = r.json()
47
+ latest_version = None
48
+
49
+ if api_url == API_PYPI_URL:
50
+ latest_version = data["info"]["version"]
51
+ else:
52
+ latest_version = data.get("version")
53
+
54
+ if latest_version and latest_version != CURRENT_VERSION:
55
+ logger.warning(f"發現新版本 {latest_version} (目前 {CURRENT_VERSION}),請更新!")
56
+ return latest_version
57
+ else:
58
+ logger.info("目前已是最新版本")
59
+ return CURRENT_VERSION
60
+ except Exception as e:
61
+ logger.error(f"檢查更新失敗:{e}")
62
+ return CURRENT_VERSION
63
+
35
64
  # ─── 全域參數 ─────────────────────────────────────────
36
65
  OWNER_ID = None
37
66
  LOG_CHANNEL_ID = None
@@ -39,9 +68,10 @@ token = None
39
68
  bot: commands.Bot | None = None
40
69
  CODER_ID = 1317800611441283139
41
70
  _now = datetime.now()
71
+ latest_version = "1.9.3"
42
72
  # thread-safe queue 用於在任意 thread 放 log,並由 bot loop 背景 worker 傳送到 Discord
43
73
  _log_queue: "queue.Queue[str]" = queue.Queue()
44
- now_version = "1.9.1"
74
+ now_version = "1.9.3"
45
75
  # ─── Logging 設定 ────────────────────────────────────
46
76
  os.makedirs("logs", exist_ok=True)
47
77
  logging.basicConfig(
@@ -480,3 +510,4 @@ class ModerationView(discord.ui.View):
480
510
  # ─── 程式進入點 ───────────────────────────────────────
481
511
  if __name__ == "__main__":
482
512
  run()
513
+ check_update()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dcchbot
3
- Version: 1.9.3
3
+ Version: 1.9.4
4
4
  Summary: 一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告
5
5
  Author-email: I_am_from_taiwan <102109040j@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dcchbot"
3
- version = "1.9.3"
3
+ version = "1.9.4"
4
4
  description = "一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告"
5
5
  readme = "README.md"
6
6
  license = {text = "MIT"}
File without changes
File without changes
File without changes
File without changes
File without changes