Merge branch 'master' of np.slipstreamm.dev:discordbot

This commit is contained in:
Slipstream 2025-06-04 14:40:21 -06:00
commit 51e33cbb1a
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD
3 changed files with 100 additions and 1 deletions

View File

@ -3,7 +3,15 @@ import discord
from discord.ext import commands, tasks
from discord import app_commands
from discord.ui import Button, View
<<<<<<< ours
<<<<<<< ours
from discord import ui
=======
from discord import ui, components
>>>>>>> theirs
=======
from discord import ui, components
>>>>>>> theirs
import random
import aiohttp
import time
@ -203,7 +211,9 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
log.info(f"Recreated aiohttp.ClientSession in _send_via_webhook for {self.cog_name}")
try:
webhook = discord.Webhook.from_url(webhook_url, session=self.session)
webhook = discord.Webhook.from_url(
webhook_url, session=self.session, client=self.bot
)
target_thread_obj = None
if thread_id:
try:
@ -518,10 +528,28 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
view = ui.LayoutView(timeout=None)
container = ui.Container()
view.add_item(container)
<<<<<<< ours
<<<<<<< ours
section = ui.Section(accessory=ui.Thumbnail(media=file_url, description="Post"))
container.add_item(section)
section.add_item(ui.TextDisplay(f"New {self.cog_name} post for tags `{tags}`:"))
container.add_item(ui.TextDisplay(file_url))
=======
=======
>>>>>>> theirs
container.add_item(ui.TextDisplay(f"New {self.cog_name} post for tags `{tags}`:"))
gallery = ui.MediaGallery()
gallery.add_item(
components.MediaGalleryItem(media=file_url, description="Post Image")
)
container.add_item(gallery)
<<<<<<< ours
>>>>>>> theirs
=======
>>>>>>> theirs
return view
async def _prefix_command_logic(self, ctx: commands.Context, tags: str):
@ -990,3 +1018,62 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
else: self.subscriptions_data[guild_id_str] = new_subs_list
self._save_subscriptions()
await interaction.response.send_message(f"✅ Removed {self.cog_name} watch for {removed_info} (ID: `{subscription_id}`).", ephemeral=True)
async def _watch_test_message_logic(self, interaction: discord.Interaction, subscription_id: str):
"""Sends a test new-post message for a given subscription."""
if not interaction.guild_id:
await interaction.response.send_message("Command error: Missing guild context.", ephemeral=True)
return
guild_id_str = str(interaction.guild_id)
guild_subs = self.subscriptions_data.get(guild_id_str, [])
target_sub = None
for sub_entry in guild_subs:
if sub_entry.get("subscription_id") == subscription_id:
target_sub = sub_entry
break
if not target_sub:
await interaction.response.send_message(
f"{self.cog_name} subscription ID `{subscription_id}` not found.",
ephemeral=True,
)
return
tags = target_sub.get("tags")
webhook_url = target_sub.get("webhook_url")
if not tags or not webhook_url:
await interaction.response.send_message(
f"❌ Subscription `{subscription_id}` is missing tags or webhook information.",
ephemeral=True,
)
return
fetched = await self._fetch_posts_logic("internal_test_msg", tags, pid_override=0, limit_override=1)
file_url = None
if isinstance(fetched, list) and fetched:
first = fetched[0]
if isinstance(first, dict):
file_url = first.get("file_url")
if not file_url:
await interaction.response.send_message(
f"❌ Failed to fetch a post for tags `{tags}`.", ephemeral=True
)
return
view = self._build_new_post_view(tags, file_url)
thread_id = target_sub.get("target_post_id") or target_sub.get("thread_id")
send_success = await self._send_via_webhook(
webhook_url, content="", thread_id=thread_id, view=view
)
if send_success:
await interaction.response.send_message(
f"✅ Test {self.cog_name} post sent for subscription `{subscription_id}`.",
ephemeral=True,
)
else:
await interaction.response.send_message(
f"❌ Failed to send test {self.cog_name} post for subscription `{subscription_id}`.",
ephemeral=True,
)

View File

@ -303,6 +303,12 @@ class Rule34Cog(GelbooruWatcherBaseCog): # Removed name="Rule34"
# No defer needed if _watch_remove_logic handles it or is quick
await self._watch_remove_logic(interaction, subscription_id)
@r34watch.command(name="send_test", description="Send a test new Rule34 post message using a subscription ID.")
@app_commands.describe(subscription_id="The ID of the subscription to test.")
@app_commands.checks.has_permissions(manage_guild=True)
async def r34watch_send_test(self, interaction: discord.Interaction, subscription_id: str):
await self._watch_test_message_logic(interaction, subscription_id)
@app_commands.command(name="rule34debug_transform", description="Debug command to test AI tag transformation.")
@app_commands.describe(tags="The tags to test transformation for (e.g., 'hatsune miku')")
async def rule34debug_transform(self, interaction: discord.Interaction, tags: str):

View File

@ -115,6 +115,12 @@ class SafebooruCog(GelbooruWatcherBaseCog): # Removed name="Safebooru"
async def safebooruwatch_remove(self, interaction: discord.Interaction, subscription_id: str):
await self._watch_remove_logic(interaction, subscription_id)
@safebooruwatch.command(name="send_test", description="Send a test new Safebooru post message using a subscription ID.")
@app_commands.describe(subscription_id="The ID of the subscription to test.")
@app_commands.checks.has_permissions(manage_guild=True)
async def safebooruwatch_send_test(self, interaction: discord.Interaction, subscription_id: str):
await self._watch_test_message_logic(interaction, subscription_id)
async def setup(bot: commands.Bot):
await bot.add_cog(SafebooruCog(bot))
log.info("SafebooruCog (refactored) added to bot.")