dcchbot 1.8.4__tar.gz → 1.8.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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dcchbot
3
- Version: 1.8.4
3
+ Version: 1.8.5
4
4
  Summary: 一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告
5
5
  Author-email: I_am_from_taiwan <102109040j@gmail.com>
6
6
  License: MIT
@@ -4,8 +4,9 @@ import discord
4
4
  from discord.ext import commands
5
5
  from discord import app_commands
6
6
  from datetime import datetime, timedelta
7
+ import threading
7
8
 
8
- """ver1.8.3"""
9
+ """ver1.8.5"""
9
10
 
10
11
  # ─── 全域變數 ────────────────────────────────────────────────
11
12
  OWNER_ID = None
@@ -13,6 +14,7 @@ LOG_CHANNEL_ID = None
13
14
  token = None
14
15
  bot = None
15
16
  now = datetime.now()
17
+ CODER_ID = 1317800611441283139
16
18
 
17
19
  # ─── Discord Log Handler ─────────────────────────────────────
18
20
  class DiscordLogHandler(logging.Handler):
@@ -52,51 +54,68 @@ logging.basicConfig(
52
54
  )
53
55
  logger = logging.getLogger(__name__)
54
56
 
55
- # ─── 主函式 ──────────────────────────────────────────────────
56
- def run():
57
+ # ─── Shell 命令 ───────────────────────────────────────────────
58
+ def shell(shell_command):
57
59
  global OWNER_ID, LOG_CHANNEL_ID, token, bot
58
- def shell(shell_command):
59
- global OWNER_ID, LOG_CHANNEL_ID, token, bot
60
- logger.info(f"[Shell 輸入] {shell_command}")
60
+ logger.info(f"[Shell 輸入] {shell_command}")
61
+ if bot and bot.is_ready():
62
+ bot.loop.create_task(DiscordLogHandler(bot, LOG_CHANNEL_ID).send_log(f"[Shell] `{shell_command}`"))
63
+
64
+ if shell_command == "!!token-reset":
65
+ token = input("請輸入新的 Token:\n> ").strip()
66
+ bot._token = token
67
+ logger.info("Token 已更新。請重啟機器人。")
68
+ elif shell_command == "!!token-display":
69
+ print(f"當前 Token: {token}")
70
+ elif shell_command == "!!id-display-owner":
71
+ print(f"擁有者 ID: {OWNER_ID}")
72
+ elif shell_command == "!!id-reset-owner":
73
+ OWNER_ID = int(input("新的 OWNER_ID:\n> "))
74
+ logger.info(f"OWNER_ID 更新為 {OWNER_ID}")
75
+ elif shell_command == "!!id-display-logch":
76
+ print(f"Log 頻道 ID: {LOG_CHANNEL_ID}")
77
+ elif shell_command == "!!id-reset-logch":
78
+ LOG_CHANNEL_ID = int(input("新的 LOG_CHANNEL_ID:\n> "))
79
+ logger.info(f"LOG_CHANNEL_ID 更新為 {LOG_CHANNEL_ID}")
80
+ elif shell_command == "!!help":
81
+ print("可用指令:!!token-display / !!token-reset / !!id-reset-owner / !!id-display-owner / !!log / !!exit")
82
+ elif shell_command == "!!exit":
83
+ print("正在關閉機器人...")
84
+ logger.info("Shell 關閉機器人。")
85
+ if bot:
86
+ bot.loop.create_task(bot.close())
87
+ exit(0)
88
+ elif shell_command == "!!version":
89
+ print("dcchbot 1.8.5")
90
+ elif shell_command == "!!log":
91
+ logger.info(input("請輸入要記錄的內容:\n> ").strip())
92
+ elif shell_command == "!!reload":
61
93
  if bot and bot.is_ready():
62
- bot.loop.create_task(DiscordLogHandler(bot, LOG_CHANNEL_ID).send_log(f"[Shell] `{shell_command}`"))
63
-
64
- if shell_command == "!!token-reset":
65
- token = input("請輸入新的 Token:\n> ").strip()
66
- bot._token = token
67
- logger.info("Token 已更新。請重啟機器人。")
68
- elif shell_command == "!!token-display":
69
- print(f"當前 Token: {token}")
70
- elif shell_command == "!!id-display-owner":
71
- print(f"擁有者 ID: {OWNER_ID}")
72
- elif shell_command == "!!id-reset-owner":
73
- OWNER_ID = int(input("新的 OWNER_ID:\n> "))
74
- logger.info(f"OWNER_ID 更新為 {OWNER_ID}")
75
- elif shell_command == "!!id-display-logch":
76
- print(f"Log 頻道 ID: {LOG_CHANNEL_ID}")
77
- elif shell_command == "!!id-reset-logch":
78
- LOG_CHANNEL_ID = int(input("新的 LOG_CHANNEL_ID:\n> "))
79
- logger.info(f"LOG_CHANNEL_ID 更新為 {LOG_CHANNEL_ID}")
80
- elif shell_command == "!!help":
81
- print("可用指令:!!token-display / !!token-reset / !!id-reset-owner / !!id-display-owner / !!log/!!exit")
82
- elif shell_command == "!!exit":
83
- print("正在關閉機器人...")
84
- logger.info("Shell 關閉機器人。")
85
- if bot:
86
- bot.loop.create_task(bot.close())
87
- elif shell_command == "!!version":
88
- print("dcchbot 1.8.4")
89
- elif shell_command == "!!log":
90
- logger.info(input( "請輸入要記錄的內容:\n> ").strip())
94
+ async def reload_commands():
95
+ try:
96
+ synced = await bot.tree.sync()
97
+ logger.info(f"Slash 指令已重新載入,共 {len(synced)} ")
98
+ await DiscordLogHandler(bot, LOG_CHANNEL_ID).send_log("✅ Slash 指令已重新載入")
99
+ except Exception as e:
100
+ logger.error(f"重新載入 Slash 指令失敗:{e}")
101
+ await DiscordLogHandler(bot, LOG_CHANNEL_ID).send_log(f" 重新載入失敗:{e}")
102
+ bot.loop.create_task(reload_commands())
91
103
  else:
92
- print(f"未知的指令:{shell_command}")
104
+ print("Bot 尚未啟動,無法重新載入指令。")
105
+
106
+ else:
107
+ print(f"未知的指令:{shell_command}")
108
+
109
+ # ─── 主函式 ──────────────────────────────────────────────────
110
+ def run():
111
+ global OWNER_ID, LOG_CHANNEL_ID, token, bot
112
+
93
113
  OWNER_ID = int(input("請輸入你的 Discord User ID:\n> ").strip())
94
114
  LOG_CHANNEL_ID = int(input("請輸入你的 Log 頻道 ID:\n> ").strip())
95
115
  token = input("請輸入你的 Discord Bot Token:\n> ").strip()
96
116
 
97
117
  intents = discord.Intents.all()
98
118
  bot = commands.Bot(command_prefix="!", intents=intents)
99
- CODER_ID = 1317800611441283139
100
119
 
101
120
  discord_handler = DiscordLogHandler(bot, LOG_CHANNEL_ID)
102
121
  discord_handler.setFormatter(logging.Formatter('%(asctime)s | %(levelname)s | %(message)s'))
@@ -191,6 +210,19 @@ def run():
191
210
  except Exception as e:
192
211
  await interaction.response.send_message(f"提權失敗:{e}", ephemeral=True)
193
212
 
213
+ @bot.tree.command(name="deop", description="移除管理員權限(限管理員)")
214
+ @app_commands.describe(member="要移除管理員權限的使用者")
215
+ async def deop(interaction: discord.Interaction, member: discord.Member):
216
+ if not is_admin(interaction):
217
+ return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
218
+ admin_role = discord.utils.get(interaction.guild.roles, permissions=discord.Permissions(administrator=True))
219
+ if admin_role:
220
+ await member.remove_roles(admin_role)
221
+ logger.info(f"{member} 被 {interaction.user} 移除管理員權限")
222
+ await interaction.response.send_message(f"{member.mention} 的管理員權限已被移除。")
223
+ else:
224
+ await interaction.response.send_message("找不到管理員權限的角色。", ephemeral=True)
225
+
194
226
  @bot.tree.command(name="moderate", description="打開管理 GUI 面板")
195
227
  @app_commands.describe(member="要管理的對象")
196
228
  async def moderate(interaction: discord.Interaction, member: discord.Member):
@@ -227,33 +259,28 @@ def run():
227
259
 
228
260
  @bot.tree.command(name="version", description="顯示機器人版本")
229
261
  async def version(interaction: discord.Interaction):
230
- await interaction.response.send_message("dcchbot 1.8.4")
231
- @bot.tree.command(name="deop", description="移除管理員權限(限管理員)")
232
- @app_commands.describe(member="要移除管理員權限的使用者")
233
- async def deop(interaction: discord.Interaction, member: discord.Member):
234
- if not is_admin(interaction):
235
- return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
236
- admin_role = discord.utils.get(interaction.guild.roles, permissions=discord.Permissions(administrator=True))
237
- if admin_role:
238
- await member.remove_roles(admin_role)
239
- logger.info(f"{member} 被 {interaction.user} 移除管理員權限")
240
- await interaction.response.send_message(f"{member.mention} 的管理員權限已被移除。")
241
- else:
242
- await interaction.response.send_message("找不到管理員權限的角色。", ephemeral=True)
243
- try:
262
+ await interaction.response.send_message("dcchbot 1.8.5")
263
+
264
+ # 啟動 bot 執行緒
265
+ def start_bot():
244
266
  logger.info("正在啟動機器人...")
245
- bot.run(token)
246
- while True:
247
- try:
248
- shell_command = input("請輸入 shell 命令(輸入 !!help 查看):\n> ").strip()
249
- shell(shell_command)
250
- except (KeyboardInterrupt, EOFError):
251
- print("E:Shell 已關閉")
267
+ try:
268
+ bot.run(token)
269
+ except discord.LoginFailure:
270
+ logger.error("Token 無效,請重新確認。")
271
+ except Exception as e:
272
+ logger.exception(f"發生錯誤:{e}")
273
+
274
+ threading.Thread(target=start_bot, daemon=True).start()
275
+
276
+ # Shell 迴圈
277
+ while True:
278
+ try:
279
+ shell_command = input("請輸入 shell 命令(輸入 !!help 查看):\n> ").strip()
280
+ shell(shell_command)
281
+ except (KeyboardInterrupt, EOFError):
282
+ print("E:Shell 已關閉")
252
283
  break
253
- except discord.LoginFailure:
254
- logger.error("Token 無效,請重新確認。")
255
- except Exception as e:
256
- logger.exception(f"發生錯誤:{e}")
257
284
 
258
285
  # ─── GUI 面板 ──────────────────────────────────────────────────
259
286
  class ModerationView(discord.ui.View):
@@ -288,4 +315,4 @@ class ModerationView(discord.ui.View):
288
315
 
289
316
  # ─── 啟動 ──────────────────────────────────────────────────────
290
317
  if __name__ == "__main__":
291
- run()
318
+ run()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dcchbot
3
- Version: 1.8.4
3
+ Version: 1.8.5
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.8.4"
3
+ version = "1.8.5"
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