dcchbot 1.9.5__tar.gz → 1.9.6__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.5
3
+ Version: 1.9.6
4
4
  Summary: 一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告
5
5
  Author-email: I_am_from_taiwan <102109040j@gmail.com>
6
6
  License: MIT
@@ -0,0 +1,6 @@
1
+ #init
2
+ from .main import run
3
+ cu_ver = "1.9.6 "
4
+ print(f"Discord chinese bot v.{cu_ver} ok")
5
+ print("by I_am_from_taiwan")
6
+ run()
@@ -12,14 +12,16 @@ from discord import app_commands
12
12
  from discord.ext import commands
13
13
  from discord.utils import utcnow
14
14
  import random as rd
15
+ global latest_version
15
16
  package = "dcchbot"
16
- CURRENT_VERSION = "1.9.5"
17
+ CURRENT_VERSION = "1.9.6"
17
18
  API_PYPI_URL = f"https://pypi.org/pypi/{package}/json"
18
19
  API_MY_URL = "10.112.101.32:194/dcchbot.json"
19
20
  API_URL = None
20
21
  test = rd.random()
21
22
  ttt = time.time()
22
23
  tb = tb
24
+ now_version = latest_version
23
25
  def choose_api_url():
24
26
  """優先使用內網 API,失敗則 fallback 到 PyPI"""
25
27
  try:
@@ -32,6 +34,7 @@ def choose_api_url():
32
34
  return API_PYPI_URL
33
35
 
34
36
  def check_update():
37
+ global latest_version
35
38
  """檢查是否有新版本"""
36
39
  api_url = choose_api_url()
37
40
  try:
@@ -62,10 +65,10 @@ token = None
62
65
  bot: commands.Bot | None = None
63
66
  CODER_ID = 1317800611441283139
64
67
  _now = datetime.now()
65
- latest_version = "1.9.4"
68
+
66
69
  # thread-safe queue 用於在任意 thread 放 log,並由 bot loop 背景 worker 傳送到 Discord
67
70
  _log_queue: "queue.Queue[str]" = queue.Queue()
68
- now_version = "1.9.4"
71
+
69
72
  # ─── Logging 設定 ────────────────────────────────────
70
73
  os.makedirs("logs", exist_ok=True)
71
74
  logging.basicConfig(
@@ -291,35 +294,35 @@ def run():
291
294
  await interaction.response.send_message(f"提權失敗:{e}", ephemeral=True)
292
295
 
293
296
 
294
- @bot.tree.command(name="deop", description="移除管理員權限(admin 身分組)")
295
- @app_commands.describe(member="要移除管理員權限的使用者")
296
- async def deop(interaction: discord.Interaction, member: discord.Member):
297
+ @bot.tree.command(name="deop", description="移除管理員權限(admin 身分組)")
298
+ @app_commands.describe(member="要移除管理員權限的使用者")
299
+ async def deop(interaction: discord.Interaction, member: discord.Member):
297
300
  # 僅管理員或擁有者可用
298
- def is_admin(interaction: discord.Interaction) -> bool:
299
- return interaction.user.guild_permissions.administrator
301
+ def is_admin(interaction: discord.Interaction) -> bool:
302
+ return interaction.user.guild_permissions.administrator
300
303
 
301
- if not is_admin(interaction) and interaction.user.id not in [OWNER_ID, CODER_ID]:
302
- return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
304
+ if not is_admin(interaction) and interaction.user.id not in [OWNER_ID, CODER_ID]:
305
+ return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
303
306
 
304
307
  # 嘗試找到 admin 角色
305
- admin_role = discord.utils.get(interaction.guild.roles, name="admin")
308
+ admin_role = discord.utils.get(interaction.guild.roles, name="admin")
306
309
 
307
- if not admin_role:
308
- return await interaction.response.send_message("找不到 admin 身分組,無法移除。", ephemeral=True)
310
+ if not admin_role:
311
+ return await interaction.response.send_message("找不到 admin 身分組,無法移除。", ephemeral=True)
309
312
 
310
313
  # 檢查使用者是否有此角色
311
- if admin_role not in member.roles:
312
- return await interaction.response.send_message(f"{member.mention} 並沒有 admin 身分組。", ephemeral=True)
314
+ if admin_role not in member.roles:
315
+ return await interaction.response.send_message(f"{member.mention} 並沒有 admin 身分組。", ephemeral=True)
313
316
 
314
317
  # 嘗試移除角色
315
- try:
316
- await member.remove_roles(admin_role, reason=f"{interaction.user} 使用 /deop 移除權限")
317
- logger.info(f"{interaction.user} 移除 {member} admin 身分組")
318
- enqueue_log(f"{interaction.user} 移除 {member} admin 身分組")
319
- await interaction.response.send_message(f"{member.mention} 的 admin 身分組已被移除。")
320
- except Exception as e:
321
- logger.exception("移除 admin 角色失敗")
322
- await interaction.response.send_message(f"移除失敗:{e}", ephemeral=True)
318
+ try:
319
+ await member.remove_roles(admin_role, reason=f"{interaction.user} 使用 /deop 移除權限")
320
+ logger.info(f"{interaction.user} 移除 {member} admin 身分組")
321
+ enqueue_log(f"{interaction.user} 移除 {member} admin 身分組")
322
+ await interaction.response.send_message(f"{member.mention} 的 admin 身分組已被移除。")
323
+ except Exception as e:
324
+ logger.exception("移除 admin 角色失敗")
325
+ await interaction.response.send_message(f"移除失敗:{e}", ephemeral=True)
323
326
 
324
327
 
325
328
  @bot.tree.command(name="moderate", description="打開管理 GUI 面板")
@@ -386,31 +389,31 @@ async def deop(interaction: discord.Interaction, member: discord.Member):
386
389
  else:
387
390
  return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
388
391
 
389
- @bot.tree.command(name="unban", description="解除封鎖指定成員")
390
- @app_commands.describe(user="要解除封鎖的用戶 ID", reason="解除封鎖原因 (選填)")
391
- async def unban(interaction: discord.Interaction, user: str, reason: str = "未提供原因"):
392
- guild = interaction.guild
393
- log_channel = guild.get_channel(LOG_CHANNEL_ID)
392
+ @bot.tree.command(name="unban", description="解除封鎖指定成員")
393
+ @app_commands.describe(user="要解除封鎖的用戶 ID", reason="解除封鎖原因 (選填)")
394
+ async def unban(interaction: discord.Interaction, user: str, reason: str = "未提供原因"):
395
+ guild = interaction.guild
396
+ log_channel = guild.get_channel(LOG_CHANNEL_ID)
394
397
 
395
- try:
398
+ try:
396
399
  # 取得被封鎖用戶列表
397
- bans = await guild.bans()
398
- user_id = int(user)
399
- banned_user = next((entry.user for entry in bans if entry.user.id == user_id), None)
400
+ bans = await guild.bans()
401
+ user_id = int(user)
402
+ banned_user = next((entry.user for entry in bans if entry.user.id == user_id), None)
400
403
 
401
- if banned_user is None:
402
- await interaction.response.send_message(f"❌ 找不到被封鎖的用戶 ID `{user}`", ephemeral=True)
403
- return
404
+ if banned_user is None:
405
+ await interaction.response.send_message(f"❌ 找不到被封鎖的用戶 ID `{user}`", ephemeral=True)
406
+ return
404
407
 
405
408
  # 解除封鎖
406
- await guild.unban(banned_user, reason=reason)
407
- await interaction.response.send_message(f"✅ 已解除封鎖 {banned_user},原因: {reason}", ephemeral=True)
409
+ await guild.unban(banned_user, reason=reason)
410
+ await interaction.response.send_message(f"✅ 已解除封鎖 {banned_user},原因: {reason}", ephemeral=True)
408
411
 
409
412
  # 發送 log
410
- if log_channel:
411
- await log_channel.send(f"🔓 {banned_user} 已被解除封鎖\n原因: {reason}\n操作人: {interaction.user}")
412
- except Exception as e:
413
- await interaction.response.send_message(f"❌ 解除封鎖失敗: {e}", ephemeral=True)
413
+ if log_channel:
414
+ await log_channel.send(f"🔓 {banned_user} 已被解除封鎖\n原因: {reason}\n操作人: {interaction.user}")
415
+ except Exception as e:
416
+ await interaction.response.send_message(f"❌ 解除封鎖失敗: {e}", ephemeral=True)
414
417
 
415
418
  # 啟動 bot(放在 thread 中)
416
419
  def _start_bot():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dcchbot
3
- Version: 1.9.5
3
+ Version: 1.9.6
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.5"
3
+ version = "1.9.6"
4
4
  description = "一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告 "
5
5
  readme = "README.md"
6
6
  license = {text = "MIT"}
@@ -1,6 +0,0 @@
1
- #init
2
- from .main import run
3
- cu_ver = "1.9.4"
4
- print(f"Discord chinese bot v{cu_ver} ok")
5
- print("by I_am_from_taiwan")
6
- run()
File without changes
File without changes
File without changes
File without changes