dcchbot 1.9.1__py3-none-any.whl → 1.9.4__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.
- dcchbot/__init__.py +2 -1
- dcchbot/main.py +66 -35
- {dcchbot-1.9.1.dist-info → dcchbot-1.9.4.dist-info}/METADATA +1 -1
- dcchbot-1.9.4.dist-info/RECORD +9 -0
- dcchbot-1.9.1.dist-info/RECORD +0 -9
- {dcchbot-1.9.1.dist-info → dcchbot-1.9.4.dist-info}/WHEEL +0 -0
- {dcchbot-1.9.1.dist-info → dcchbot-1.9.4.dist-info}/entry_points.txt +0 -0
- {dcchbot-1.9.1.dist-info → dcchbot-1.9.4.dist-info}/licenses/LICENSE +0 -0
- {dcchbot-1.9.1.dist-info → dcchbot-1.9.4.dist-info}/top_level.txt +0 -0
dcchbot/__init__.py
CHANGED
dcchbot/main.py
CHANGED
@@ -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.
|
17
|
-
|
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
|
-
tb = tb
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
tb = tb
|
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,11 +68,10 @@ token = None
|
|
39
68
|
bot: commands.Bot | None = None
|
40
69
|
CODER_ID = 1317800611441283139
|
41
70
|
_now = datetime.now()
|
42
|
-
|
43
|
-
tmp_log_channel_id = None
|
71
|
+
latest_version = "1.9.3"
|
44
72
|
# thread-safe queue 用於在任意 thread 放 log,並由 bot loop 背景 worker 傳送到 Discord
|
45
73
|
_log_queue: "queue.Queue[str]" = queue.Queue()
|
46
|
-
now_version = "1.9.
|
74
|
+
now_version = "1.9.3"
|
47
75
|
# ─── Logging 設定 ────────────────────────────────────
|
48
76
|
os.makedirs("logs", exist_ok=True)
|
49
77
|
logging.basicConfig(
|
@@ -110,23 +138,25 @@ async def _discord_log_worker(bot_instance: commands.Bot, channel_id: int):
|
|
110
138
|
|
111
139
|
# ─── Bot 程式主體與指令 ─────────────────────────────────
|
112
140
|
def run():
|
113
|
-
global OWNER_ID, LOG_CHANNEL_ID, token, bot
|
141
|
+
global OWNER_ID, LOG_CHANNEL_ID, token, bot
|
114
142
|
|
115
143
|
# 互動式輸入(你也可以改成從環境變數讀取)
|
116
|
-
|
117
|
-
|
118
|
-
OWNER_ID
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
LOG_CHANNEL_ID =
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
144
|
+
while True:
|
145
|
+
OWNER_ID = input("請輸入你的 Discord User ID:\n> ").strip()
|
146
|
+
if not OWNER_ID or not str(OWNER_ID).isdigit():
|
147
|
+
print("格式錯誤,請重新輸入")
|
148
|
+
logger.error("E:vError ownerid")
|
149
|
+
else:
|
150
|
+
OWNER_ID=int(OWNER_ID)
|
151
|
+
break
|
152
|
+
while True:
|
153
|
+
LOG_CHANNEL_ID = input("請輸入你的 Log 頻道 ID:\n> ").strip()
|
154
|
+
if not LOG_CHANNEL_ID or not str(LOG_CHANNEL_ID).isdigit():
|
155
|
+
print("格式錯誤,請重新輸入")
|
156
|
+
logger.error("E:vError channelid")
|
157
|
+
else:
|
158
|
+
LOG_CHANNEL_ID = int(LOG_CHANNEL_ID)
|
159
|
+
break
|
130
160
|
token = input("請輸入你的 Discord Bot Token:\n> ").strip()
|
131
161
|
|
132
162
|
intents = discord.Intents.all()
|
@@ -480,3 +510,4 @@ class ModerationView(discord.ui.View):
|
|
480
510
|
# ─── 程式進入點 ───────────────────────────────────────
|
481
511
|
if __name__ == "__main__":
|
482
512
|
run()
|
513
|
+
check_update()
|
@@ -0,0 +1,9 @@
|
|
1
|
+
dcchbot/__init__.py,sha256=TuQRGtSD8Z8WeNCtlvqz-fVxh2ZS87QSmN4VCJent0s,127
|
2
|
+
dcchbot/__main__.py,sha256=5FwoJspcKFt5_1AlXoxlWROiQSp9wgnFEltU6ufz9QE,30
|
3
|
+
dcchbot/main.py,sha256=k-3M5NdSnd5jeGxFCs_QrTiem5hIxD91uHvz_0zwrCY,26150
|
4
|
+
dcchbot-1.9.4.dist-info/licenses/LICENSE,sha256=_5HM5sddbG63Amw1X9WfCK-_5xBLHlAV_HaUKBqeTpE,1063
|
5
|
+
dcchbot-1.9.4.dist-info/METADATA,sha256=GVqWpKsSokVweXEL5JTmR2FZrTbkV3lAKCFriNuyXYY,440
|
6
|
+
dcchbot-1.9.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
dcchbot-1.9.4.dist-info/entry_points.txt,sha256=90T16CGc_Tx-4pFaLCcbuuh7Vi9l4gsLovBkydqxP9Y,45
|
8
|
+
dcchbot-1.9.4.dist-info/top_level.txt,sha256=jiDTz8UmwZgXN9KzokwDRYhoWxsVmWcnqmrANeTFMck,8
|
9
|
+
dcchbot-1.9.4.dist-info/RECORD,,
|
dcchbot-1.9.1.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
dcchbot/__init__.py,sha256=qGk3E_IN6HKlEC4mc6W-Oj2hkq_-Q9YDUldjiQAwOoY,105
|
2
|
-
dcchbot/__main__.py,sha256=5FwoJspcKFt5_1AlXoxlWROiQSp9wgnFEltU6ufz9QE,30
|
3
|
-
dcchbot/main.py,sha256=rCvSnc60i3vQzvMvrWlh0g5EY_whH1_trPmCpA2gX_0,25240
|
4
|
-
dcchbot-1.9.1.dist-info/licenses/LICENSE,sha256=_5HM5sddbG63Amw1X9WfCK-_5xBLHlAV_HaUKBqeTpE,1063
|
5
|
-
dcchbot-1.9.1.dist-info/METADATA,sha256=sKgnRRGj1swr9IIhohAv6o9dt1E8Jj6I3ByzRBnD3CI,440
|
6
|
-
dcchbot-1.9.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
-
dcchbot-1.9.1.dist-info/entry_points.txt,sha256=90T16CGc_Tx-4pFaLCcbuuh7Vi9l4gsLovBkydqxP9Y,45
|
8
|
-
dcchbot-1.9.1.dist-info/top_level.txt,sha256=jiDTz8UmwZgXN9KzokwDRYhoWxsVmWcnqmrANeTFMck,8
|
9
|
-
dcchbot-1.9.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|