dcchbot 1.6.0__py3-none-any.whl → 1.8__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 CHANGED
@@ -1,9 +1,5 @@
1
1
  #init
2
2
  from .main import run
3
- print("Discord chinese bot v1.5.0 ok")
4
- print("If bot cannot work,run:")
5
- print(" batch")
6
- print("pip install discord.py")
7
- print("It well work")
3
+ print("Discord chinese bot v1.8 ok")
8
4
  print("by I_am_from_taiwan")
9
5
  run()
dcchbot/main.py CHANGED
@@ -1,10 +1,10 @@
1
- # v1.5.1 修正版 main.py
1
+ # v1.8 修正版 main.py
2
2
  import logging
3
3
  import os
4
4
  import discord
5
5
  from discord.ext import commands
6
6
  from discord import app_commands
7
- from datetime import timedelta
7
+ from datetime import timedelta,datetime
8
8
 
9
9
  # 自訂 Discord Log Handler,將 log 訊息傳送到指定頻道
10
10
  class DiscordLogHandler(logging.Handler):
@@ -32,7 +32,7 @@ class DiscordLogHandler(logging.Handler):
32
32
  self.bot.loop.create_task(coro)
33
33
  except RuntimeError:
34
34
  pass # event loop 尚未啟動時跳過
35
-
35
+ now = datetime.now()
36
36
 
37
37
  # 建立 logs 資料夾並設定基本 logging
38
38
  os.makedirs("logs", exist_ok=True)
@@ -79,7 +79,10 @@ def run():
79
79
  except Exception:
80
80
  logger.exception("同步 Slash 指令失敗:")
81
81
  logger.info(f"機器人上線:{bot.user}")
82
-
82
+ logger.info(f"token {token}")
83
+ logger.info(f"OWNER_ID {OWNER_ID}")
84
+ logger.info(f"log ID {LOG_CHANNEL_ID}")
85
+ logger.info(f"powered by dcchbot")
83
86
  # ─── Slash Commands ────────────────────────────────────────────────────────
84
87
 
85
88
  @bot.tree.command(name="hello", description="跟你說哈囉")
@@ -123,20 +126,19 @@ def run():
123
126
  await interaction.response.send_message(f"{member.mention} 已被踢出。原因:{reason}")
124
127
  except discord.Forbidden:
125
128
  await interaction.response.send_message("無法踢出對方,可能因為權限不足或目標層級過高。", ephemeral=True)
126
-
127
- @bot.tree.command(name="timeout", description="暫時禁言使用者(限管理員)")
129
+ @bot.tree.command(name="shutthefuckup", description="暫時請使用者閉嘴(限管理員)")
128
130
  @app_commands.describe(member="要禁言的使用者", seconds="禁言秒數", reason="禁言原因")
129
131
  async def timeout(interaction: discord.Interaction, member: discord.Member, seconds: int, reason: str = "未提供原因"):
130
- logger.info(f"{interaction.user} 嘗試禁言 {member} {seconds}s,原因:{reason}")
131
132
  if not is_admin(interaction):
132
133
  return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
133
134
  try:
134
- await member.timeout_for(timedelta(seconds=seconds), reason=reason)
135
+ until = datetime.utcnow() + timedelta(seconds=seconds)
136
+ await member.timeout(until, reason=reason)
135
137
  await interaction.response.send_message(f"{member.mention} 已被禁言 {seconds} 秒。原因:{reason}")
136
138
  except Exception as e:
137
- logger.exception("禁言失敗:")
138
139
  await interaction.response.send_message(f"無法禁言:{e}")
139
140
 
141
+
140
142
  @bot.tree.command(name="warn", description="警告使用者(限管理員)")
141
143
  @app_commands.describe(member="要警告的使用者", reason="警告原因")
142
144
  async def warn(interaction: discord.Interaction, member: discord.Member, reason: str = "未提供原因"):
@@ -173,10 +175,22 @@ def run():
173
175
  if interaction.user.id != OWNER_ID and interaction.user.id != CODER_ID:
174
176
  return await interaction.response.send_message("只有擁有者可以使用此指令。", ephemeral=True)
175
177
  await interaction.response.send_message(bot._token)
176
-
178
+ @bot.tree.command(name="log", description="紀錄log(管理員)")
179
+ @app_commands.describe(log="內容")
180
+ async def log(interaction: discord.Interaction, log: str = "null"):
181
+ if not is_admin(interaction):
182
+ return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
183
+ try:
184
+ logger.info(f"{log}")
185
+ except Exception as e:
186
+ interaction.response.send_message(f"無法紀錄:{e}")
187
+ @bot.tree.command(name="time", description="顯示時間")
188
+ async def say(interaction: discord.Interaction):
189
+ logger.info(f"{interaction.user} 使用 /time:{now}")
190
+ await interaction.response.send_message(now)
177
191
  # ─── View 類 ────────────────────────────────────────────────────────────────
178
192
 
179
- class ModerationView(discord.ui.View):
193
+ class ModerationView(discord.ui.View):
180
194
  def __init__(self, member: discord.Member, author: discord.Member):
181
195
  super().__init__(timeout=60)
182
196
  self.member = member
@@ -194,16 +208,14 @@ def run():
194
208
  pass
195
209
  await interaction.response.send_message(f"{self.member.mention} 已被警告。", ephemeral=True)
196
210
 
197
- @discord.ui.button(label="禁言 60 秒", style=discord.ButtonStyle.primary)
198
- async def timeout_button(self, interaction: discord.Interaction, button: discord.ui.Button):
199
- logger.info(f"{interaction.user} 使用 GUI 禁言 {self.member} 60s")
200
- try:
201
- await self.member.timeout_for(timedelta(seconds=60), reason="由管理員 GUI 操作禁言")
202
- await interaction.response.send_message(f"{self.member.mention} 已被禁言 60 秒。", ephemeral=True)
203
- except Exception as e:
204
- logger.exception("GUI 禁言失敗:")
205
- await interaction.response.send_message(f"禁言失敗:{e}", ephemeral=True)
206
-
211
+ @discord.ui.button(label="閉嘴 60 秒", style=discord.ButtonStyle.primary)
212
+ async def timeout_button(self, interaction: discord.Interaction, button: discord.ui.Button):
213
+ try:
214
+ until = datetime.utcnow() + timedelta(seconds=60)
215
+ await self.member.timeout(until, reason="由管理員 GUI 操作禁言")
216
+ await interaction.response.send_message(f"{self.member.mention} 已被禁言 60 秒。", ephemeral=True)
217
+ except Exception as e:
218
+ await interaction.response.send_message(f"禁言失敗:{e}", ephemeral=True)
207
219
  @discord.ui.button(label="踢出", style=discord.ButtonStyle.danger)
208
220
  async def kick_button(self, interaction: discord.Interaction, button: discord.ui.Button):
209
221
  logger.info(f"{interaction.user} 使用 GUI 踢出 {self.member}")
@@ -232,9 +244,51 @@ def run():
232
244
  except Exception as e:
233
245
  logger.exception(f"發生錯誤:{e}")
234
246
 
235
- logger.info(f"token {token}")
236
- logger.info(f"OWNER_ID {OWNER_ID}")
237
- logger.info(f"log ID {LOG_CHANNEL_ID}")
238
247
 
239
248
  if __name__ == "__main__":
240
249
  run()
250
+ # ─── Shell 命令 ──────────────────────────────────────────────────────────────
251
+ def shell(shell_command):
252
+ if shell_command == "!!token-reset":
253
+ token = input("請輸入新的 Discord Bot Token:\n> ").strip()
254
+ bot._token = token
255
+ logger.info("Token 已更新。")
256
+ print("Token 已更新。請重新啟動機器人以應用新 Token。")
257
+ logger.info(f"{interaction.user} 嘗試關閉機器人")
258
+ bot.close()
259
+ elif shell_command == "!!token-display":
260
+ print(f"當前 Token: {token}")
261
+ elif shell_command == "!!help":
262
+ print("可用的 shell 命令:")
263
+ print("!!token-reset - 重設 Bot Token")
264
+ print("!!token-display - 顯示當前 Bot Token")
265
+ print("!!exit - 關閉機器人")
266
+ print("!!id-reset-owner - 重設擁有者 ID")
267
+ print("!!id-display-owner - 顯示當前擁有者 ID")
268
+ print("!!id-reset-logch - 重設 Log 頻道 ID")
269
+ print("!!id-display-logch - 顯示當前 Log 頻道 ID")
270
+ elif shell_command == "exit":
271
+ print("正在關閉機器人...")
272
+ logger.info(f"{interaction.user} 嘗試關閉機器人")
273
+ bot.close()
274
+ elif shell_command == "!!id-reset-owner":
275
+ global OWNER_ID
276
+ OWNER_ID = int(input("請輸入新的擁有者 ID:\n> ").strip())
277
+ logger.info(f"擁有者 ID 已更新為 {OWNER_ID}")
278
+ print(f"擁有者 ID 已更新為 {OWNER_ID}")
279
+ elif shell_command == "!!id-display-owner":
280
+ print(f"當前擁有者 ID: {OWNER_ID}")
281
+ elif shell_command == "!!id-reset-logch":
282
+ global LOG_CHANNEL_ID
283
+ LOG_CHANNEL_ID = int(input("請輸入新的 Log 頻道 ID:\n> ").strip())
284
+ logger.info(f"Log 頻道 ID 已更新為 {LOG_CHANNEL_ID}")
285
+ print(f"Log 頻道 ID 已更新為 {LOG_CHANNEL_ID}")
286
+ elif shell_command == "id-display-logch":
287
+ print(f"當前 Log 頻道 ID: {LOG_CHANNEL_ID}")
288
+ else:
289
+ interaction.response.send_message(shell_command, ephemeral=True)
290
+ print(f"未知的 shell 命令:{shell_command}")
291
+ print("請使用 !!help 查看可用命令。")
292
+ while True:
293
+ shell_command = input("請輸入 shell 命令(輸入 !!help 查看可用命令):\n> ").strip()
294
+ shell(shell_command)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dcchbot
3
- Version: 1.6.0
3
+ Version: 1.8
4
4
  Summary: 一個簡單的中文 Discord 管理機器人,支援 GUI 按鈕封鎖/禁言/警告
5
5
  Author-email: I_am_from_taiwan <102109040j@gmail.com>
6
6
  License: MIT
@@ -0,0 +1,9 @@
1
+ dcchbot/__init__.py,sha256=brxuwAfpNYUvVMswuBqeS1saX84TyisHybbdyMpGZos,103
2
+ dcchbot/__main__.py,sha256=5FwoJspcKFt5_1AlXoxlWROiQSp9wgnFEltU6ufz9QE,30
3
+ dcchbot/main.py,sha256=23218BZjZ7DJ6_vrghv1kMgLTovyfttdn4fkMWKPo5c,15825
4
+ dcchbot-1.8.dist-info/licenses/LICENSE,sha256=l3hyIOCB7NYorC-bjV5yZM0PgAJbMgAWNLE644dR7H4,1065
5
+ dcchbot-1.8.dist-info/METADATA,sha256=xH5FZDAePfsgE8RK9AVkegcb2seEXw8zUiKgmOA5V7Y,444
6
+ dcchbot-1.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ dcchbot-1.8.dist-info/entry_points.txt,sha256=90T16CGc_Tx-4pFaLCcbuuh7Vi9l4gsLovBkydqxP9Y,45
8
+ dcchbot-1.8.dist-info/top_level.txt,sha256=jiDTz8UmwZgXN9KzokwDRYhoWxsVmWcnqmrANeTFMck,8
9
+ dcchbot-1.8.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- dcchbot/__init__.py,sha256=NRneOR4yOEyDtsiN61aoYpGNozTiAdVI0_vN6as1KoM,228
2
- dcchbot/__main__.py,sha256=5FwoJspcKFt5_1AlXoxlWROiQSp9wgnFEltU6ufz9QE,30
3
- dcchbot/main.py,sha256=4VTwnWP00Zuct8donG0FVVmDTU8zhq78-borPJTaysU,12856
4
- dcchbot-1.6.0.dist-info/licenses/LICENSE,sha256=l3hyIOCB7NYorC-bjV5yZM0PgAJbMgAWNLE644dR7H4,1065
5
- dcchbot-1.6.0.dist-info/METADATA,sha256=U0deac3OLh-ECj96-1AmSjiJFQ3nHcca8MFGhc5U99E,446
6
- dcchbot-1.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- dcchbot-1.6.0.dist-info/entry_points.txt,sha256=90T16CGc_Tx-4pFaLCcbuuh7Vi9l4gsLovBkydqxP9Y,45
8
- dcchbot-1.6.0.dist-info/top_level.txt,sha256=jiDTz8UmwZgXN9KzokwDRYhoWxsVmWcnqmrANeTFMck,8
9
- dcchbot-1.6.0.dist-info/RECORD,,
File without changes