dcchbot 1.8.3__py3-none-any.whl → 1.8.5__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/main.py +83 -61
- {dcchbot-1.8.3.dist-info → dcchbot-1.8.5.dist-info}/METADATA +1 -1
- dcchbot-1.8.5.dist-info/RECORD +9 -0
- dcchbot-1.8.3.dist-info/RECORD +0 -9
- {dcchbot-1.8.3.dist-info → dcchbot-1.8.5.dist-info}/WHEEL +0 -0
- {dcchbot-1.8.3.dist-info → dcchbot-1.8.5.dist-info}/entry_points.txt +0 -0
- {dcchbot-1.8.3.dist-info → dcchbot-1.8.5.dist-info}/licenses/LICENSE +0 -0
- {dcchbot-1.8.3.dist-info → dcchbot-1.8.5.dist-info}/top_level.txt +0 -0
dcchbot/main.py
CHANGED
@@ -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.
|
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
|
57
|
+
# ─── Shell 命令 ───────────────────────────────────────────────
|
58
|
+
def shell(shell_command):
|
57
59
|
global OWNER_ID, LOG_CHANNEL_ID, token, bot
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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.3")
|
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(
|
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,26 +259,21 @@ 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.
|
231
|
-
|
232
|
-
|
233
|
-
|
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
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
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 迴圈
|
250
277
|
while True:
|
251
278
|
try:
|
252
279
|
shell_command = input("請輸入 shell 命令(輸入 !!help 查看):\n> ").strip()
|
@@ -286,11 +313,6 @@ class ModerationView(discord.ui.View):
|
|
286
313
|
await self.member.ban(reason="由管理員 GUI 操作封鎖")
|
287
314
|
await interaction.response.send_message(f"{self.member.mention} 已被封鎖。", ephemeral=True)
|
288
315
|
|
289
|
-
# ─── Shell 控制 ─────────────────────────────────────────────────
|
290
|
-
|
291
|
-
|
292
316
|
# ─── 啟動 ──────────────────────────────────────────────────────
|
293
317
|
if __name__ == "__main__":
|
294
318
|
run()
|
295
|
-
|
296
|
-
|
@@ -0,0 +1,9 @@
|
|
1
|
+
dcchbot/__init__.py,sha256=zp5WAMYJ8lMGsJsMRvHCjvTXVR426Satbz_orCtk990,105
|
2
|
+
dcchbot/__main__.py,sha256=5FwoJspcKFt5_1AlXoxlWROiQSp9wgnFEltU6ufz9QE,30
|
3
|
+
dcchbot/main.py,sha256=sHfm6lwIRVUAGl90jrkdcqFYARbdG1YC14fJrK94xT8,16771
|
4
|
+
dcchbot-1.8.5.dist-info/licenses/LICENSE,sha256=l3hyIOCB7NYorC-bjV5yZM0PgAJbMgAWNLE644dR7H4,1065
|
5
|
+
dcchbot-1.8.5.dist-info/METADATA,sha256=c5d15Nku2bL_deeqx-yuRn0IzLGDS0ykBy7_5i7uIt0,446
|
6
|
+
dcchbot-1.8.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
dcchbot-1.8.5.dist-info/entry_points.txt,sha256=90T16CGc_Tx-4pFaLCcbuuh7Vi9l4gsLovBkydqxP9Y,45
|
8
|
+
dcchbot-1.8.5.dist-info/top_level.txt,sha256=jiDTz8UmwZgXN9KzokwDRYhoWxsVmWcnqmrANeTFMck,8
|
9
|
+
dcchbot-1.8.5.dist-info/RECORD,,
|
dcchbot-1.8.3.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
dcchbot/__init__.py,sha256=zp5WAMYJ8lMGsJsMRvHCjvTXVR426Satbz_orCtk990,105
|
2
|
-
dcchbot/__main__.py,sha256=5FwoJspcKFt5_1AlXoxlWROiQSp9wgnFEltU6ufz9QE,30
|
3
|
-
dcchbot/main.py,sha256=66FMZZo-D8ZJsDXy1U57Y-mKrEsY_SP0U-ZBhBdcFYk,15971
|
4
|
-
dcchbot-1.8.3.dist-info/licenses/LICENSE,sha256=l3hyIOCB7NYorC-bjV5yZM0PgAJbMgAWNLE644dR7H4,1065
|
5
|
-
dcchbot-1.8.3.dist-info/METADATA,sha256=sp9XnuLGsyY98-kLqbWkI_F2wvxpcdVAjTn1lx0VJU8,446
|
6
|
-
dcchbot-1.8.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
-
dcchbot-1.8.3.dist-info/entry_points.txt,sha256=90T16CGc_Tx-4pFaLCcbuuh7Vi9l4gsLovBkydqxP9Y,45
|
8
|
-
dcchbot-1.8.3.dist-info/top_level.txt,sha256=jiDTz8UmwZgXN9KzokwDRYhoWxsVmWcnqmrANeTFMck,8
|
9
|
-
dcchbot-1.8.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|