Update app.py
Browse files
app.py
CHANGED
|
@@ -14,14 +14,7 @@ from threading import Thread
|
|
| 14 |
from discord import app_commands, ui
|
| 15 |
# 导入数据库基础类
|
| 16 |
from mongo import MongoManager
|
| 17 |
-
|
| 18 |
-
'''from material import (
|
| 19 |
-
CATEGORIES,
|
| 20 |
-
upload_material_logic,
|
| 21 |
-
approve_material_logic,
|
| 22 |
-
delete_material_logic,
|
| 23 |
-
list_materials_logic
|
| 24 |
-
)'''
|
| 25 |
|
| 26 |
# 初始化数据库管理器
|
| 27 |
db_manager = MongoManager(os.getenv("MONGO_URL"), "Main")
|
|
@@ -117,40 +110,35 @@ client = MyBot()
|
|
| 117 |
client.db = db_manager
|
| 118 |
|
| 119 |
# --- 5. 指令定义 ---
|
| 120 |
-
|
| 121 |
async def announce(interaction: discord.Interaction, channel: discord.TextChannel, role_ids: str = None):
|
| 122 |
-
if not any(role.id in mod for role in interaction.user.roles):
|
| 123 |
-
await interaction.response.send_message("❌ **Access Denied**", ephemeral=True)
|
| 124 |
-
return
|
| 125 |
await interaction.response.send_modal(AnnounceModal(channel, role_ids))
|
| 126 |
|
| 127 |
@client.tree.command(name="announce_edit", description="Edit announcement")
|
| 128 |
async def announce_edit(interaction: discord.Interaction, channel: discord.TextChannel, message_id: str, new_role_ids: str = None):
|
| 129 |
-
if not any(role.id in mod for role in interaction.user.roles):
|
| 130 |
-
await interaction.response.send_message("❌ **Access Denied**", ephemeral=True)
|
| 131 |
-
return
|
| 132 |
try:
|
| 133 |
message = await channel.fetch_message(int(message_id))
|
| 134 |
await interaction.response.send_modal(EditAnnounceModal(message, new_role_ids))
|
| 135 |
except Exception as e:
|
| 136 |
await interaction.response.send_message(f"❌ Error: {e}", ephemeral=False)
|
| 137 |
|
| 138 |
-
@client.tree.command(name="
|
| 139 |
async def wismer_commands(interaction: discord.Interaction):
|
| 140 |
await interaction.response.send_message(
|
| 141 |
-
''**Avaliable Commands**:
|
| 142 |
`/announce`: Post an announcement.
|
| 143 |
-
`/announce_edit`: Edit an announcement.
|
| 144 |
-
`/mats`: Show all materials.
|
| 145 |
-
`/uploadmat`: Upload a material.
|
| 146 |
-
`/approvemat`: Approve a unapproved material. Only Mod+ can use it.
|
| 147 |
-
`/deletemat`: To delete or reject a material. Only Mod+ can use it.
|
| 148 |
-
`/unappmats`: To show unapprove materials. Only Mod+ can use it.',
|
| 149 |
ephemeral=False
|
| 150 |
)
|
| 151 |
|
| 152 |
-
ADMIN_LOG_CHANNEL_ID = 1468391869686878455
|
| 153 |
-
|
| 154 |
# 允许调用指令的用户名列表(或者 User ID)
|
| 155 |
ALLOWED_USERS = ["tonydong365"]
|
| 156 |
|
|
@@ -181,78 +169,7 @@ async def secret(interaction: discord.Interaction, content: str):
|
|
| 181 |
# 4. 调用另一个函数进行“无关联”发送
|
| 182 |
await send_anonymous_message(interaction.channel, content)
|
| 183 |
|
| 184 |
-
'''
|
| 185 |
|
| 186 |
-
@client.tree.command(name="uploadmat", description="Upload a study link")
|
| 187 |
-
@app_commands.choices(category=[app_commands.Choice(name=c, value=c) for c in CATEGORIES])
|
| 188 |
-
async def uploadmat(interaction: discord.Interaction, category: str, title: str, url: str):
|
| 189 |
-
await interaction.response.defer(ephemeral=True)
|
| 190 |
-
if not url.startswith(("http://", "https://")):
|
| 191 |
-
return await interaction.followup.send("❌ Invalid URL!", ephemeral=True)
|
| 192 |
-
try:
|
| 193 |
-
new_id = await upload_material_logic(client.db, category, title, url, interaction.user.id)
|
| 194 |
-
await interaction.followup.send(f"✅ Submitted! ID: `#{new_id}`.", ephemeral=True)
|
| 195 |
-
|
| 196 |
-
log_channel = client.get_channel(ADMIN_LOG_CHANNEL_ID)
|
| 197 |
-
if log_channel:
|
| 198 |
-
# --- ✅ 补全这里缺失的字段 ---
|
| 199 |
-
embed = discord.Embed(title="🔔 New Material Pending Approval", color=discord.Color.orange())
|
| 200 |
-
embed.add_field(name="Subject", value=category, inline=True)
|
| 201 |
-
embed.add_field(name="Index ID", value=f"`#{new_id}`", inline=True)
|
| 202 |
-
|
| 203 |
-
# 补上消失的 Title, URL 和 Uploader
|
| 204 |
-
embed.add_field(name="Title", value=title, inline=False)
|
| 205 |
-
embed.add_field(name="URL", value=url, inline=False)
|
| 206 |
-
embed.add_field(name="Uploader", value=interaction.user.mention, inline=False)
|
| 207 |
-
|
| 208 |
-
# 加个小提示方便 Mod 操作
|
| 209 |
-
embed.set_footer(text="Use /approvemat to authorize this link.")
|
| 210 |
-
|
| 211 |
-
await log_channel.send(embed=embed)
|
| 212 |
-
except Exception as e:
|
| 213 |
-
await interaction.followup.send(f"❌ Error: {e}", ephemeral=True)
|
| 214 |
-
|
| 215 |
-
@client.tree.command(name="approvemat", description="[Mod Only] Approve material")
|
| 216 |
-
@app_commands.choices(category=[app_commands.Choice(name=c, value=c) for c in CATEGORIES])
|
| 217 |
-
async def approvemat(interaction: discord.Interaction, category: str, index_id: str):
|
| 218 |
-
await interaction.response.defer(ephemeral=False)
|
| 219 |
-
if not any(role.id in mod for role in interaction.user.roles):
|
| 220 |
-
return await interaction.followup.send("❌ Access Denied", ephemeral=True)
|
| 221 |
-
await approve_material_logic(client.db, category, index_id)
|
| 222 |
-
await interaction.followup.send(f"✅ Approved **{category}** `#{index_id}`.")
|
| 223 |
-
|
| 224 |
-
@client.tree.command(name="deletemat", description="[Mod Only] Delete material")
|
| 225 |
-
@app_commands.choices(category=[app_commands.Choice(name=c, value=c) for c in CATEGORIES])
|
| 226 |
-
async def deletemat(interaction: discord.Interaction, category: str, index_id: str):
|
| 227 |
-
await interaction.response.defer(ephemeral=False)
|
| 228 |
-
if not any(role.id in mod for role in interaction.user.roles):
|
| 229 |
-
return await interaction.followup.send("❌ Access Denied", ephemeral=True)
|
| 230 |
-
await delete_material_logic(client.db, category, index_id)
|
| 231 |
-
await interaction.followup.send(f"🗑️ Deleted ID `#{index_id}`.")
|
| 232 |
-
|
| 233 |
-
@client.tree.command(name="mats", description="View approved materials")
|
| 234 |
-
@app_commands.choices(category=[app_commands.Choice(name=c, value=c) for c in CATEGORIES])
|
| 235 |
-
async def mats(interaction: discord.Interaction, category: str):
|
| 236 |
-
await interaction.response.defer(ephemeral=False)
|
| 237 |
-
materials = await list_materials_logic(client.db, category, status="approved")
|
| 238 |
-
if not materials:
|
| 239 |
-
return await interaction.followup.send(f"📭 No materials in **{category}**.")
|
| 240 |
-
list_text = "\n".join([f"`#{m['_id']}` [{m['title']}]({m['url']})" for m in materials])
|
| 241 |
-
embed = discord.Embed(title=f"📚 {category}", description=list_text, color=discord.Color.blue())
|
| 242 |
-
await interaction.followup.send(embed=embed)
|
| 243 |
-
|
| 244 |
-
@client.tree.command(name="unappmats", description="[Mod Only] View pending")
|
| 245 |
-
@app_commands.choices(category=[app_commands.Choice(name=c, value=c) for c in CATEGORIES])
|
| 246 |
-
async def unappmats(interaction: discord.Interaction, category: str):
|
| 247 |
-
await interaction.response.defer(ephemeral=False)
|
| 248 |
-
if not any(role.id in mod for role in interaction.user.roles):
|
| 249 |
-
return await interaction.followup.send("❌ Access Denied", ephemeral=True)
|
| 250 |
-
materials = await list_materials_logic(client.db, category, status="pending")
|
| 251 |
-
if not materials:
|
| 252 |
-
return await interaction.followup.send(f"✅ No pending items.")
|
| 253 |
-
list_text = "\n".join([f"`#{m['_id']}` **{m['title']}**\n🔗 {m['url']}" for m in materials])
|
| 254 |
-
embed = discord.Embed(title=f"⏳ {category} Pending", description=list_text, color=discord.Color.orange())
|
| 255 |
-
await interaction.followup.send(embed=embed)'''
|
| 256 |
|
| 257 |
@client.tree.command(name="hi")
|
| 258 |
async def hi(interaction: discord.Interaction):
|
|
|
|
| 14 |
from discord import app_commands, ui
|
| 15 |
# 导入数据库基础类
|
| 16 |
from mongo import MongoManager
|
| 17 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# 初始化数据库管理器
|
| 20 |
db_manager = MongoManager(os.getenv("MONGO_URL"), "Main")
|
|
|
|
| 110 |
client.db = db_manager
|
| 111 |
|
| 112 |
# --- 5. 指令定义 ---
|
| 113 |
+
@client.tree.command(name="announce", description="Post announcement")
|
| 114 |
async def announce(interaction: discord.Interaction, channel: discord.TextChannel, role_ids: str = None):
|
| 115 |
+
#if not any(role.id in mod for role in interaction.user.roles):
|
| 116 |
+
#await interaction.response.send_message("❌ **Access Denied**", ephemeral=True)
|
| 117 |
+
#return
|
| 118 |
await interaction.response.send_modal(AnnounceModal(channel, role_ids))
|
| 119 |
|
| 120 |
@client.tree.command(name="announce_edit", description="Edit announcement")
|
| 121 |
async def announce_edit(interaction: discord.Interaction, channel: discord.TextChannel, message_id: str, new_role_ids: str = None):
|
| 122 |
+
#if not any(role.id in mod for role in interaction.user.roles):
|
| 123 |
+
#await interaction.response.send_message("❌ **Access Denied**", ephemeral=True)
|
| 124 |
+
#return
|
| 125 |
try:
|
| 126 |
message = await channel.fetch_message(int(message_id))
|
| 127 |
await interaction.response.send_modal(EditAnnounceModal(message, new_role_ids))
|
| 128 |
except Exception as e:
|
| 129 |
await interaction.response.send_message(f"❌ Error: {e}", ephemeral=False)
|
| 130 |
|
| 131 |
+
@client.tree.command(name="commands", description="Show all avaliable commands")
|
| 132 |
async def wismer_commands(interaction: discord.Interaction):
|
| 133 |
await interaction.response.send_message(
|
| 134 |
+
'''**Avaliable Commands**:
|
| 135 |
`/announce`: Post an announcement.
|
| 136 |
+
`/announce_edit`: Edit an announcement.''',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
ephemeral=False
|
| 138 |
)
|
| 139 |
|
| 140 |
+
#ADMIN_LOG_CHANNEL_ID = 1468391869686878455
|
| 141 |
+
|
| 142 |
# 允许调用指令的用户名列表(或者 User ID)
|
| 143 |
ALLOWED_USERS = ["tonydong365"]
|
| 144 |
|
|
|
|
| 169 |
# 4. 调用另一个函数进行“无关联”发送
|
| 170 |
await send_anonymous_message(interaction.channel, content)
|
| 171 |
|
|
|
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
@client.tree.command(name="hi")
|
| 175 |
async def hi(interaction: discord.Interaction):
|