Skip to content

feat(community): add guild-scoped snippets - #71

Open
analeis wants to merge 1 commit into
Neon-Genesis-Linux:mainfrom
analeis:snippets
Open

analeis wants to merge 1 commit into
Neon-Genesis-Linux:mainfrom
analeis:snippets

Conversation

@analeis

@analeis analeis commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Server members can save short pieces of text and reuse them anywhere in the server. Snippet names and aliases are case-insensitive, and each name can only be used once per server.

  • Post: /snippet name:<name> or @pen-pen s <name> posts a snippet by name or alias without pinging anyone. The slash command offers autocomplete. Type @pen-pen s for help; use @pen-pen s show <name> if the name is also a shortcut, like l.
  • Create: /snippets create name:<name> text:<text> saves typed text. Omit text or use @pen-pen s c [name] to open the form. To save several messages, supply first_message and last_message in the slash command or the form. You can also right-click a message and choose Apps → Save as snippet to open the form with its text; when importing a range, the selected message is the default endpoint.
  • Browse: /snippets list [prefix] [tag] or @pen-pen s l [prefix] [tag:<tag>] finds snippets by name or alias and can filter by tag. Use Previous and Next to browse, select a snippet to read it, and press Send to post it. The mention command replies with an Open snippets button that only the requester can use. The list and previews are private.
  • Preview: /snippets preview name:<name> or @pen-pen s p <name> shows the snippet privately without starting its cooldown. If the snippet changes before you press Send, the bot shows the updated version and asks you to review it before sending.
  • Edit or delete: /snippets edit or @pen-pen s e <name> changes the text. /snippets delete or @pen-pen s d <name> asks for confirmation before deleting the snippet. Members can edit or delete their own unlocked snippets. Guild owners and members with server-wide Manage Messages or Administrator can manage any snippet.
  • Lock or unlock: /snippets lock or @pen-pen s lo <name> prevents the author from changing the snippet. /snippets unlock or @pen-pen s u <name> restores that access. Staff can still manage locked snippets, and members can still read and post them.
  • Aliases: /snippets alias add or @pen-pen s a add <snippet> <alias> adds another name for the same snippet. /snippets alias remove or @pen-pen s a remove <snippet> <alias> frees that name. Both update the alias list shown in the snippet’s footer. Aliases always point directly to the original, even when added through another alias, and share its 10-second posting cooldown. Deleting the original frees all of its aliases.
  • Tags: /snippets tag create or @pen-pen s t create <tag> creates a reusable server tag. /snippets tag attach or @pen-pen s t attach <snippet> <tag> adds it to a snippet; /snippets tag detach or @pen-pen s t detach <snippet> <tag> removes it from that snippet. Both update the Tags field on the snippet and what appears in filtered lists. Staff can remove a tag and all its assignments with /snippets tag delete or @pen-pen s t delete <tag>.

Posts and previews show the same text, owner, lock status, tags, and aliases. The embed accent is blue for posts, orange for private views and lists, green for creation, and red for removals.

Message ranges accept links or IDs from the current channel or forum post. Both the member and the bot need access to the source and its history. Text is saved oldest first and must fit within 1,000 characters. Once saved, it’s available server-wide, even if it came from a restricted channel.

Implements upstream issue #7.

AI disclosure and use:

I used OpenCode with GPT-6.2 Sol to help design and implement the commands, write the SQLite migrations and tests, and review the changes. The prompts covered issue #7, permissions, importing forum messages, mention shortcuts, browsing, aliases, tags, and deployment.

Vet, tests, race tests, custom-gcl, and a CGO-disabled build passed with Go 1.26.11. The docs build passed too. Tests use a Discord mock for forum imports, private browsing, and sending previews, and SQLite for migrations, name conflicts, and cleanup. Earlier rootless Podman smoke tests checked migration, volume persistence, and global and guild command sync against a local Discord mock.

@analeis

analeis commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

DO NOT MERGE

Work In Progress. Feel free to review and provide feedback.
Yet to test manually in local deployment but most obvious errors have been smoothened out.

@Uniolo1

Uniolo1 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

DO NOT MERGE

Work In Progress. Feel free to review and provide feedback. Yet to test manually in local deployment but most obvious errors have been smoothened out.

If it is a work in progress why isn't it a draft?

@Uniolo1

Uniolo1 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Also there should be a command for creating alias snippets

@analeis
analeis marked this pull request as draft December 2, 2026 23:11
@analeis

analeis commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

DO NOT MERGE

Work In Progress. Feel free to review and provide feedback. Yet to test manually in local deployment but most obvious errors have been smoothened out.

If it is a work in progress why isn't it a draft?

I knew I'd be updating the PR soon enough for it to be ready, but didn't want it to be kept away from folks reviewing.
I also actually never had reached for the draft button before haha

@analeis
analeis marked this pull request as ready for review December 3, 2026 00:47
@analeis
analeis marked this pull request as draft December 3, 2026 00:57
Let server members save short pieces of text and reuse them anywhere
in that server. Names and aliases share a case-insensitive namespace.

- `/snippets create` saves typed text or a range from the current
  channel or forum post. **Apps → Save as snippet** opens a form with
  the selected message and lets members choose a range instead.
- `/snippet name:<name>` and `@pen-pen s <name>` post by name or alias
  without pinging users, roles, or everyone. `@pen-pen s` shows help.
- `/snippets list` searches names and aliases, filters by tag, and
  lets members page through results, preview a snippet, and press
  Send to post it. `@pen-pen s l` opens the same private list through
  a button only the requester can use. `/snippets preview` also opens
  a private view without starting the cooldown.
- `/snippets edit`, `delete`, `lock`, and `unlock` manage snippets.
  Members can change their own unlocked snippets. Guild owners and
  members with server-wide Manage Messages or Administrator can
  manage any snippet. Locked snippets can still be read and posted.
- `/snippets alias` and `/snippets tag` manage alternate names and
  reusable tags. Aliases point directly to the original snippet.
  Removing an alias frees its name; deleting a snippet frees all of
  its aliases. Posts and previews use the same saved details,
  including tags and the alias list.

Enable Message Content Intent in the Discord Developer Portal before
starting the bot. Range import requires both the member and bot to
have access to the source and its history. It saves text oldest first,
up to 1,000 characters without truncation. Imported text becomes
server-wide, even when it came from a restricted channel.

SQLite migrations run at startup and preserve existing snippets.
Each snippet has one atomic 10-second posting cooldown, shared by
its aliases and all posting commands.

Implements upstream issue Neon-Genesis-Linux#7.

Verified with Go 1.26.11: vet, tests, race tests, custom-gcl, and a
CGO-disabled build. The docs build passed. Mocked Discord tests cover
forum import, private browsing, and sending a changed preview only
after review. Database tests cover migration and alias and tag cleanup.
Earlier rootless Podman smoke tests covered migration, volume
persistence, and global and guild sync against a local Discord mock.

AI disclosure: OpenCode with GPT-6.2 Sol assisted with design,
implementation, review, testing, and this description. Prompts covered
issue Neon-Genesis-Linux#7, permissions, forum import, mention shortcuts, private browsing,
aliases, tags, and Podman deployment. Generated code includes handlers,
SQLite migrations and queries, and regression tests.

Polish snippet handling after review: check posting permissions before
claiming the cooldown where available, bound mention work off the gateway
listener, make delete confirmations single-use, and return the canonical
record from edit and lock writes. Document commands and deployment setup.

Update Gorilla WebSocket to the version that fixes GO-2026-6278, include
the x/crypto and x/net updates, and refresh the Nix vendor hash.

OpenCode with GPT-6.2 Sol assisted with the audit follow-ups and dependency
verification. All pre-commit hooks, Go checks, and the Sphinx build passed;
govulncheck reported no vulnerabilities.
@analeis
analeis marked this pull request as ready for review December 3, 2026 01:31
@analeis

analeis commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Think I've been as extensive and thorough as possible over a 3 hour sprint.

Will return for more look throughs later.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants