dcchbot 1.9.4__tar.gz → 1.9.5__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,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dcchbot
3
- Version: 1.9.4
4
- Summary: 一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告
3
+ Version: 1.9.5
4
+ Summary: 一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告
5
5
  Author-email: I_am_from_taiwan <102109040j@gmail.com>
6
6
  License: MIT
7
7
  Requires-Python: >=3.8
@@ -1,6 +1,6 @@
1
1
  #init
2
2
  from .main import run
3
- cu_ver = "1.9.3"
3
+ cu_ver = "1.9.4"
4
4
  print(f"Discord chinese bot v{cu_ver} ok")
5
5
  print("by I_am_from_taiwan")
6
6
  run()
@@ -1,4 +1,4 @@
1
- # v1.9.1 main.py
1
+ # v1.9.4 main.py
2
2
  import logging
3
3
  import os
4
4
  import queue
@@ -13,16 +13,10 @@ 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.4"
16
+ CURRENT_VERSION = "1.9.5"
17
17
  API_PYPI_URL = f"https://pypi.org/pypi/{package}/json"
18
18
  API_MY_URL = "10.112.101.32:194/dcchbot.json"
19
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
26
20
  test = rd.random()
27
21
  ttt = time.time()
28
22
  tb = tb
@@ -68,10 +62,10 @@ token = None
68
62
  bot: commands.Bot | None = None
69
63
  CODER_ID = 1317800611441283139
70
64
  _now = datetime.now()
71
- latest_version = "1.9.3"
65
+ latest_version = "1.9.4"
72
66
  # thread-safe queue 用於在任意 thread 放 log,並由 bot loop 背景 worker 傳送到 Discord
73
67
  _log_queue: "queue.Queue[str]" = queue.Queue()
74
- now_version = "1.9.3"
68
+ now_version = "1.9.4"
75
69
  # ─── Logging 設定 ────────────────────────────────────
76
70
  os.makedirs("logs", exist_ok=True)
77
71
  logging.basicConfig(
@@ -258,44 +252,75 @@ def run():
258
252
  logger.exception("禁言失敗")
259
253
  await interaction.response.send_message(f"無法禁言:{e}", ephemeral=True)
260
254
 
261
- @bot.tree.command(name="op", description="賦予管理員權限(限擁有者)")
255
+ @bot.tree.command(name="op", description="賦予管理員權限(admin 身分組)")
262
256
  @app_commands.describe(member="要提權的使用者")
263
257
  async def op(interaction: discord.Interaction, member: discord.Member):
258
+ # 只允許擁有者或 coder 使用
264
259
  if interaction.user.id != OWNER_ID and interaction.user.id != CODER_ID:
265
260
  return await interaction.response.send_message("你不是擁有者。", ephemeral=True)
261
+
262
+ # 嘗試找到 admin 角色
263
+ admin_role = discord.utils.get(interaction.guild.roles, name="admin")
264
+
265
+ # 如果找不到,就自動建立
266
+ if not admin_role:
267
+ try:
268
+ admin_role = await interaction.guild.create_role(
269
+ name="admin",
270
+ permissions=discord.Permissions(administrator=True),
271
+ reason=f"自動建立 admin 角色,由 {interaction.user} 使用 /op 指令觸發"
272
+ )
273
+ logger.info(f"自動建立 admin 角色")
274
+ enqueue_log(f"{interaction.user} 自動建立 admin 角色")
275
+ except Exception as e:
276
+ logger.exception("建立 admin 角色失敗")
277
+ return await interaction.response.send_message(f"無法建立 admin 角色:{e}", ephemeral=True)
278
+
279
+ # 檢查是否已經有角色
280
+ if admin_role in member.roles:
281
+ return await interaction.response.send_message(f"{member.mention} 已經有 admin 身分組。", ephemeral=True)
282
+
283
+ # 嘗試給角色
266
284
  try:
267
- admin_role = None
268
- for r in interaction.guild.roles:
269
- if getattr(r, "permissions", None) and r.permissions.administrator:
270
- admin_role = r
271
- break
272
- if not admin_role:
273
- admin_role = await interaction.guild.create_role(name="管理員", permissions=discord.Permissions(administrator=True))
274
- await member.add_roles(admin_role)
275
- logger.info(f"{interaction.user} 提權 {member}")
276
- enqueue_log(f"{interaction.user} 提權 {member}")
277
- await interaction.response.send_message(f"{member.mention} 已被提權。")
285
+ await member.add_roles(admin_role, reason=f"{interaction.user} 使用 /op 提權")
286
+ logger.info(f"{interaction.user} {member} admin 身分組")
287
+ enqueue_log(f"{interaction.user} {member} admin 身分組")
288
+ await interaction.response.send_message(f"{member.mention} 已被賦予 admin 身分組。")
278
289
  except Exception as e:
279
290
  logger.exception("提權失敗")
280
291
  await interaction.response.send_message(f"提權失敗:{e}", ephemeral=True)
281
292
 
282
- @bot.tree.command(name="deop", description="移除管理員權限(限管理員)")
283
- @app_commands.describe(member="要移除管理員權限的使用者")
284
- async def deop(interaction: discord.Interaction, member: discord.Member):
285
- if not is_admin(interaction):
286
- return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
287
- admin_role = None
288
- for r in interaction.guild.roles:
289
- if getattr(r, "permissions", None) and r.permissions.administrator:
290
- admin_role = r
291
- break
292
- if admin_role:
293
- await member.remove_roles(admin_role)
294
- logger.info(f"{interaction.user} 移除 {member} 的管理員權限")
295
- enqueue_log(f"{interaction.user} 移除 {member} 的管理員權限")
296
- await interaction.response.send_message(f"{member.mention} 的管理員權限已被移除。")
297
- else:
298
- await interaction.response.send_message("找不到管理員角色。", ephemeral=True)
293
+
294
+ @bot.tree.command(name="deop", description="移除管理員權限(admin 身分組)")
295
+ @app_commands.describe(member="要移除管理員權限的使用者")
296
+ async def deop(interaction: discord.Interaction, member: discord.Member):
297
+ # 僅管理員或擁有者可用
298
+ def is_admin(interaction: discord.Interaction) -> bool:
299
+ return interaction.user.guild_permissions.administrator
300
+
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)
303
+
304
+ # 嘗試找到 admin 角色
305
+ admin_role = discord.utils.get(interaction.guild.roles, name="admin")
306
+
307
+ if not admin_role:
308
+ return await interaction.response.send_message("找不到 admin 身分組,無法移除。", ephemeral=True)
309
+
310
+ # 檢查使用者是否有此角色
311
+ if admin_role not in member.roles:
312
+ return await interaction.response.send_message(f"{member.mention} 並沒有 admin 身分組。", ephemeral=True)
313
+
314
+ # 嘗試移除角色
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)
323
+
299
324
 
300
325
  @bot.tree.command(name="moderate", description="打開管理 GUI 面板")
301
326
  @app_commands.describe(member="要管理的對象")
@@ -360,6 +385,32 @@ def run():
360
385
  await interaction.response.send_message("已是最新版本")
361
386
  else:
362
387
  return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
388
+
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)
394
+
395
+ try:
396
+ # 取得被封鎖用戶列表
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
+
401
+ if banned_user is None:
402
+ await interaction.response.send_message(f"❌ 找不到被封鎖的用戶 ID `{user}`", ephemeral=True)
403
+ return
404
+
405
+ # 解除封鎖
406
+ await guild.unban(banned_user, reason=reason)
407
+ await interaction.response.send_message(f"✅ 已解除封鎖 {banned_user},原因: {reason}", ephemeral=True)
408
+
409
+ # 發送 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)
363
414
 
364
415
  # 啟動 bot(放在 thread 中)
365
416
  def _start_bot():
@@ -443,7 +494,7 @@ def run():
443
494
  bot.loop.create_task(bot.close())
444
495
  break
445
496
  else:
446
- print("未知指令,輸入 !!help 查看。")
497
+ print("無此指令")
447
498
  except (KeyboardInterrupt, EOFError):
448
499
  logger.exception("Shell 已中斷,結束。")
449
500
  enqueue_log("Shell 已中斷,結束。")
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dcchbot
3
- Version: 1.9.4
4
- Summary: 一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告
3
+ Version: 1.9.5
4
+ Summary: 一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告
5
5
  Author-email: I_am_from_taiwan <102109040j@gmail.com>
6
6
  License: MIT
7
7
  Requires-Python: >=3.8
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "dcchbot"
3
- version = "1.9.4"
4
- description = "一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告"
3
+ version = "1.9.5"
4
+ description = "一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告 "
5
5
  readme = "README.md"
6
6
  license = {text = "MIT"}
7
7
  authors = [
File without changes
File without changes
File without changes
File without changes