Skip to content

Refactor project layout; add centralized media providers, command factory, and deploy/validate scripts#2

Open
SyntaxGhost404 wants to merge 2 commits into
experimentalfrom
codex/inspect-and-analyze-repository-for-issues
Open

Refactor project layout; add centralized media providers, command factory, and deploy/validate scripts#2
SyntaxGhost404 wants to merge 2 commits into
experimentalfrom
codex/inspect-and-analyze-repository-for-issues

Conversation

@SyntaxGhost404

Copy link
Copy Markdown
Owner

Motivation

  • Modernize and reorganize the bot into a clear src/ layout with centralized media provider logic and a command factory for consistent behavior.
  • Introduce a safe deployment workflow for slash commands and a validation step to ensure commands and providers are wired correctly.
  • Keep the original pre-rewrite code available by moving it to archive/original/ while updating top-level documentation and ignore rules.

Description

  • Reorganized repository into src/ with entrypoint src/index.js, event handlers in src/events/, commands in src/commands/, service layers in src/services/, and utilities in src/utils/.
  • Implemented centralized media fetching in src/services/mediaProviders.js with multiple provider adapters (including porngifsTv), an HTTP client in src/services/http.js, and a fetchWithFallback strategy.
  • Added a command factory src/commands/mediaFactory.js driven by src/config/mediaCatalog.js, a special /gif command, and utility commands (help, invite, ping, solo, threesome) with consistent NSFW/context handling and refresh buttons via src/utils/discord.js.
  • Added environment validation (src/config/env.js), startup logging (src/utils/logger.js), event registration (src/events/index.js), and a scripts folder with scripts/deploy-commands.js and scripts/validate-commands.js for safe global slash command deployment and validation.
  • Updated package.json (name -> discord-nsfw-media-bot, bumped version to 2.0.0, added start, deploy:commands, check, and test scripts), refined top-level README.md, added .gitignore entries (.env, *.log, .DS_Store, npm-debug.log*), and moved the original codebase into archive/original/.
  • Added a lightweight unit test test/catalog.test.js to assert command payload serialization and uniqueness.

Testing

  • Added unit test test/catalog.test.js to validate command payload serialization and unique command names; the test file is included but was not executed as part of this rollout.
  • No automated test runs were performed during this change; run npm run check and npm test (or node --test) locally or in CI to execute the new validations and tests.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dbe6b0fcc6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +19 to +20
const url = data?.url || data?.message || data?.image;
return ok({ url, provider: 'abd' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Parse ABD responses with the actual URL fields

Commands whose only source is abd (for example /breeding, /buttplug, /cages, /legs, /petgirls, /smothering, and /socks) now always fail because this adapter ignores the url_japan/url_usa fields used by the n-sfw API in archive/original/utils/api.js::fetchABD; ok() receives undefined and there is no fallback provider for those commands. It also drops the previous buffering workaround for that CDN, so this should restore those fields and buffer handling.

Useful? React with 👍 / 👎.

Comment on lines +57 to +59
async function fetchSexcom({ category }) {
const encoded = encodeURIComponent(category || 'Hardcore');
return ok({ url: `https://www.sex.com/gifs/${encoded}/`, provider: 'sexcom' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return actual Sex.com media instead of a page

When /gif reaches the sexcom source, this constructed category page is treated as successful media and passed to EmbedBuilder#setImage, but Discord cannot render an HTML listing page as an image/GIF and fetchWithFallback stops before trying later providers. The previous adapter called the Sex.com GIF search API and returned a selected CDN media URL, so this path should fetch a real item instead of returning /gifs/<category>/.

Useful? React with 👍 / 👎.

Comment on lines +61 to +63
async function fetchPorngifs() {
const id = Math.floor(Math.random() * 9000000) + 1000000;
return ok({ url: `https://cdn.porngifs.com/img/${id}`, provider: 'porngifs' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore Porngifs fetching and validation

When /gif reaches the porngifs fallback, this returns a random seven-digit CDN path without checking that an object exists or attaching the bytes. The archived implementation and study limit direct IDs to roughly 1-39239 and explicitly fetched the buffer because Discord's proxy often cannot render extensionless CDN URLs; with the new range most picks are dead URLs and fallback stops on them as if they succeeded.

Useful? React with 👍 / 👎.

Comment on lines +30 to +32
const { data } = await client.get('https://api.waifu.im/images', {
params: { included_tags: tag, is_nsfw: 'true' },
headers: { Authorization: `ApiKey ${process.env.WAIFU_IM_KEY}`, 'Accept-Version': 'v7' }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use Waifu.im's documented filter parameters

For any command using waifuIm with a configured key, these query names are no longer the API's documented filters (IncludedTags/IsNsfw; see https://docs.waifu.im/docs/getting-started), so the request can be served as an unfiltered default SFW/random image instead of the requested NSFW tag. This affects /ero, /uniform, and the Waifu.im fallback in several other media commands; restore the documented parameter names before deploying.

Useful? React with 👍 / 👎.

Comment on lines +39 to +40
const headers = process.env.NEKOBOT_AUTH ? { Authorization: process.env.NEKOBOT_AUTH } : undefined;
const { data } = await client.get('https://nekobot.xyz/api/image', { params: { type }, headers });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require NekoBot auth for NekoBot-only commands

On deployments that follow the new README and do not set the optional NEKOBOT_AUTH, this stops sending the Authorization header that the previous adapter always included, even though NekoBot's image docs mark auth as required for certain image types. Commands whose only provider is NekoBot, such as /4k, /gonewild, /kitsune, /midriff, /tentacle, and /thigh, can therefore fail outright instead of returning media; either require the env var or keep a working default/fallback for these commands.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant