dcchbot 1.9.4__py3-none-any.whl → 1.9.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/__init__.py +1 -1
- dcchbot/main.py +91 -40
- {dcchbot-1.9.4.dist-info → dcchbot-1.9.5.dist-info}/METADATA +2 -2
- dcchbot-1.9.5.dist-info/RECORD +9 -0
- dcchbot-1.9.4.dist-info/RECORD +0 -9
- {dcchbot-1.9.4.dist-info → dcchbot-1.9.5.dist-info}/WHEEL +0 -0
- {dcchbot-1.9.4.dist-info → dcchbot-1.9.5.dist-info}/entry_points.txt +0 -0
- {dcchbot-1.9.4.dist-info → dcchbot-1.9.5.dist-info}/licenses/LICENSE +0 -0
- {dcchbot-1.9.4.dist-info → dcchbot-1.9.5.dist-info}/top_level.txt +0 -0
dcchbot/__init__.py
CHANGED
dcchbot/main.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# v1.9.
|
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.
|
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.
|
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.
|
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 =
|
268
|
-
|
269
|
-
|
270
|
-
|
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
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
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("
|
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
|
-
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
|
@@ -0,0 +1,9 @@
|
|
1
|
+
dcchbot/__init__.py,sha256=8MGpV-Ot9o82uA2LP-M3n-oR6ZPrA4lyeS57Vf33lp0,127
|
2
|
+
dcchbot/__main__.py,sha256=5FwoJspcKFt5_1AlXoxlWROiQSp9wgnFEltU6ufz9QE,30
|
3
|
+
dcchbot/main.py,sha256=ygfZfFTR1RYgCpU0FQcU1cdmR4GQpmdu4rQl_rx2ajc,28635
|
4
|
+
dcchbot-1.9.5.dist-info/licenses/LICENSE,sha256=_5HM5sddbG63Amw1X9WfCK-_5xBLHlAV_HaUKBqeTpE,1063
|
5
|
+
dcchbot-1.9.5.dist-info/METADATA,sha256=eiJ4vGli3b__8FLrqfKaT25XtqFIRJp5sGbAZDdjH24,448
|
6
|
+
dcchbot-1.9.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
dcchbot-1.9.5.dist-info/entry_points.txt,sha256=90T16CGc_Tx-4pFaLCcbuuh7Vi9l4gsLovBkydqxP9Y,45
|
8
|
+
dcchbot-1.9.5.dist-info/top_level.txt,sha256=jiDTz8UmwZgXN9KzokwDRYhoWxsVmWcnqmrANeTFMck,8
|
9
|
+
dcchbot-1.9.5.dist-info/RECORD,,
|
dcchbot-1.9.4.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
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,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|