From 2a13b954ea9a3fd460d9248d0ec3ba562e803326 Mon Sep 17 00:00:00 2001 From: Fdvkey Date: Wed, 15 Jul 2026 16:51:27 +0700 Subject: [PATCH] chore: clean up log files and temp document structures --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 3 +- cmds/media/sticker.go | 2 +- cmds/register.go | 1 + .../plans/2026-07-15-sticker-refactor-plan.md | 59 ----- .../plans/2026-07-15-unified-sticker-plan.md | 246 ------------------ .../2026-07-15-unified-sticker-design.md | 16 -- temp/.gitignore | 2 + 8 files changed, 6 insertions(+), 323 deletions(-) create mode 100644 .DS_Store delete mode 100644 docs/superpowers/plans/2026-07-15-sticker-refactor-plan.md delete mode 100644 docs/superpowers/plans/2026-07-15-unified-sticker-plan.md delete mode 100644 docs/superpowers/specs/2026-07-15-unified-sticker-design.md create mode 100644 temp/.gitignore diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..83e7b6466fb7b90c1a2b2a658b6b151e4963fbfc GIT binary patch literal 6148 zcmeHK!D>@M6g|^CY*3K8QbA;Jp$nl}@dKVU?h66IRco8j23~xjHXyjk4+t*0aG~Nt z5kJ6%KcIE#Qe685N>{CT?#v{)llKCyL}UhL&UABf zo0=kasg<%2dMwenF^1@%TWqhix5|ol>PQMC1^zV!EE8J9GPY3QKGgTyAE;DkJo;s; zwON##^k{y(y#M~k@uyqWar$NF54;9DvRg!K8S~jj4|{$m@wSDd^S8+{vFRMHeO_+A zXdFlm%06YUvuoalSz{;~RA7LfW(Ce(m|8UF;oVDLp8Rt24sm+ERjcL$tng)2z0V!< zVa#Y>X`AM}vi9xt%kexztY)pV$GmP)7s*@V0rt?vqgZ9&=2x=Mc<3D7;ojAs8&e%ztY)vX$Glc}Phf`%6kPKzcH=e3 zKFr!R|MA7<_h+6z8bjwW&nM19&Rx!b$hGL9h;y*dwN3NyufKhB;MZUhtGVm!G4FNZ z<(Vy|dCFsIlLASBq`*W0*&i&cU>69i}9gE zA8NuC!}xIa+u)Z69C`HNFpiny1ZER%D8{j~-#T}g++%8!0!e{bfrfuwlJox#zu`Ie z|2QbUB?XcK|CItJYqeXeoKiSjE0dG6*0OG}N)f-2M;F2-9LMfKj^cByuFz)XftUvz Td1Mbu`Xk_ENKI1UuPX2x$8-1F literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore index 8ea1796..e84476c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.db .env doc.json -neo \ No newline at end of file +neo +testing/ \ No newline at end of file diff --git a/cmds/media/sticker.go b/cmds/media/sticker.go index d04e7c9..d6a8e3f 100644 --- a/cmds/media/sticker.go +++ b/cmds/media/sticker.go @@ -18,7 +18,7 @@ var Sticker = &core.Command{ Category: "media", Description: "Create sticker from image/video or rewrite existing sticker EXIF", Run: func(ctx *hc.Ctx) { - ctx.React("👌") + // go ctx.React("👌") exifPath, cleanupExif := helper.ResolveExif(ctx.Arguments()) defer func() { diff --git a/cmds/register.go b/cmds/register.go index 2d3716e..fd6ffa2 100644 --- a/cmds/register.go +++ b/cmds/register.go @@ -2,5 +2,6 @@ package cmds import ( _ "neo/cmds/download" + _ "neo/cmds/media" _ "neo/cmds/misc" ) diff --git a/docs/superpowers/plans/2026-07-15-sticker-refactor-plan.md b/docs/superpowers/plans/2026-07-15-sticker-refactor-plan.md deleted file mode 100644 index 9bc992d..0000000 --- a/docs/superpowers/plans/2026-07-15-sticker-refactor-plan.md +++ /dev/null @@ -1,59 +0,0 @@ -# Sticker Refactor Implementation Plan - -> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. - -**Goal:** Move EXIF generation and WebP conversion helpers out of sticker.go into helper packages. - -**Architecture:** -1. Create `helper/exif.go` handling exif metadata extraction. -2. Create `helper/media_convert.go` abstracting commands like `cwebp` and `ffmpeg` wrappers to convert byte slices to webp. -3. Simplify `cmds/media/sticker.go` to depend on these new exports. - -**Tech Stack:** Go, exec, Neo Context, `waProto` - -## Global Constraints -- Only use standard library inside `helper/` where possible (no whatsapp dependencies except general bytes handling). -- The behavior of the `/Users/fd/Documents/perf/cmds/media/sticker.go` command should remain functionally identical. - ---- - -### Task 1: Migrate Exif Support to Helper - -**Files:** -- Create: `/Users/fd/Documents/perf/helper/exif.go` -- Modify: `/Users/fd/Documents/perf/cmds/media/sticker.go` - -**Interfaces:** -- Produces: `helper.CreateDynamicExif(args []string) (exifPath string, cleanup bool)` - -- [ ] **Step 1: Write `exif.go`** -Extract `exifData`, `webpExif`, `getOrCreateDefaultExif`, and `resolveExif` into `helper/exif.go`. Make `resolveExif` exported as `ResolveExif`. Ensure it uses the existing env logic. Keep `uuid` dependency. - -- [ ] **Step 2: Update `sticker.go` EXIF usage** -Remove the exif functions/structs from `sticker.go` and update `Sticker.Run` to call `helper.ResolveExif(ctx.Arguments())`. - -- [ ] **Step 3: Commit** - -### Task 2: Abstract Conversion Functions - -**Files:** -- Create: `/Users/fd/Documents/perf/helper/media_convert.go` -- Modify: `/Users/fd/Documents/perf/cmds/media/sticker.go` - -**Interfaces:** -- Produces: - `ConvertImageToSticker(imgData []byte, exifPath string) ([]byte, error)` - `ConvertVideoToSticker(vidData []byte, exifPath string) ([]byte, error)` - `RewriteStickerExif(webpData []byte, exifPath string) ([]byte, error)` - -- [ ] **Step 1: Create `media_convert.go`** -Implement the three conversion functions. Each should take bytes (downloaded media) and an `exifPath`, do the conversion via `exec.Command`, inject exif via `webpmux`, clean up its own internal temp files, and return the final `[]byte` of the webp ready to send. (They don't need Whatsapp Context). - -- [ ] **Step 2: Update `sticker.go` media usage** -Remove `cmdStickerImage`, `cmdStickerVideo`, and `cmdStickerRewrite` from `sticker.go`. Instead, in `Sticker.Run`, download the bytes directly using `ctx.Client().Download(...)`, then pass those bytes to the `helper.ConvertX` functions, and `ctx.SendSticker()` the returned bytes. - -- [ ] **Step 3: Test build** -Run `go build ./...` - -- [ ] **Step 4: Commit** -`git commit -m "refactor: extract media conversion logic to helper"` diff --git a/docs/superpowers/plans/2026-07-15-unified-sticker-plan.md b/docs/superpowers/plans/2026-07-15-unified-sticker-plan.md deleted file mode 100644 index 64a9ce9..0000000 --- a/docs/superpowers/plans/2026-07-15-unified-sticker-plan.md +++ /dev/null @@ -1,246 +0,0 @@ -# Unified Sticker Command Implementation Plan - -> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. - -**Goal:** Create a single `.sticker` command that natively handles images, videos, existing stickers, boot-managed Exif generation, and inline watermark arguments. - -**Architecture:** A single command definition in `cmds/media/sticker.go` that extracts Exif checking/generation to the init loop (or a lazy helper), processes args to create ephemeral Exif files, performs the webpmux conversion, handles upload and cleanup. - -**Tech Stack:** Go (whatsmeow, local `ffmpeg`, `imagemagick`/convert, `webpmux`), internal `Roxy/command` framework. - -## Global Constraints -- Target file: `/Users/fd/Documents/perf/cmds/media/sticker.go` -- Clean up other files: `/Users/fd/Documents/perf/Lara/src/cmd/media/stickerwm.go` and `/Users/fd/Documents/perf/Lara/src/cmd/media/wm.go` must be deleted (or un-registered). Wait, we are editing in `cmds/media/` not `Lara/src/cmd/media/`. We will overwrite `/Users/fd/Documents/perf/cmds/media/sticker.go` and ensure we aren't duplicating Lara source. Let's adapt the plan to just rewrite `/Users/fd/Documents/perf/cmds/media/sticker.go`. -- DB (`repo.WMRepository`) usage for sticker command is removed. -- `temp/default.exif` behavior on boot or on-demand when empty. - ---- - -### Task 1: Rewrite cmds/media/sticker.go Support Functions - -**Files:** -- Modify:`/Users/fd/Documents/perf/cmds/media/sticker.go` - -**Interfaces:** -- Produces: `getExif(args string) (string, bool)` helper, `processMedia` generic handler. - -- [ ] **Step 1: Write the Exif resolution helper** -```go -package media - -import ( - "bytes" - "os" - "strings" - - "github.com/itzngga/Lara/src/cmd/constant" - util2 "github.com/itzngga/Lara/util" - "github.com/itzngga/Lara/util/metadata" - "github.com/itzngga/Lara/util/scrapper" - "github.com/itzngga/Roxy/command" - "github.com/itzngga/Roxy/embed" - "github.com/itzngga/Roxy/util" - "github.com/itzngga/Roxy/util/cli" - cmdchain "github.com/rainu/go-command-chain" - waProto "go.mau.fi/whatsmeow/binary/proto" -) - -// getOrCreateDefaultExif ensures temp/default.exif exists using ENV variables -func getOrCreateDefaultExif() string { - path := "temp/default.exif" - if _, err := os.Stat(path); os.IsNotExist(err) { - name := os.Getenv("STICKER_NAME") - if name == "" { - name = "Sticker" - } - pub := os.Getenv("STICKER_PUBLISHER") - if pub == "" { - pub = "Roxy" - } - b := metadata.CreateMetadata(metadata.StickerMetadata{ - Name: name, - Publisher: pub, - }) - _ = os.WriteFile(path, b, os.ModePerm) - } - return path -} - -// resolveExif returns the filepath to the exif to use, and a boolean true if it's a temp file that should be deleted -func resolveExif(args []string) (string, bool) { - if len(args) == 0 { - return getOrCreateDefaultExif(), false - } - - joined := strings.Join(args, " ") - parts := strings.Split(joined, "|") - name := strings.TrimSpace(parts[0]) - pub := "" - if len(parts) > 1 { - pub = strings.TrimSpace(parts[1]) - } - - b := metadata.CreateMetadata(metadata.StickerMetadata{ - Name: name, - Publisher: pub, - }) - - tmpPath := "temp/" + util2.MakeMD5UUID() + ".exif" - _ = os.WriteFile(tmpPath, b, os.ModePerm) - return tmpPath, true -} -``` - -- [ ] **Step 2: Commit helper functions** -```bash -git add /Users/fd/Documents/perf/cmds/media/sticker.go -git commit -m "feat: add exif resolution helpers to sticker command" -``` - -### Task 2: Implement Media Conversions in sticker.go - -**Files:** -- Modify:`/Users/fd/Documents/perf/cmds/media/sticker.go` - -**Interfaces:** -- Produces: `cmdStickerImage`, `cmdStickerVideo`, `cmdStickerRewrite` - -- [ ] **Step 1: Write specific converters** -```go -func cmdStickerImage(ctx *command.RunFuncContext, img *waProto.ImageMessage, exifPath string, webpPath string) error { - data, err := ctx.Client.Download(img) - if err != nil { - return err - } - reader := bytes.NewReader(data) - return cmdchain.Builder(). - Join("convert", "-", "-resize", "512x512", "-background", "none", "-compose", "Copy", "-gravity", "center", "-extent", "512x512", "-quality", "100", "png:-"). - WithInjections(reader).ForwardError(). - Join("cwebp", "-quiet", "-mt", "-exact", "-q", "100", "-m", "6", "-alpha_q", "100", "-o", "-", "--", "-"). - Join("webpmux", "-set", "exif", exifPath, "-", "-o", webpPath). - Finalize().WithError(os.Stderr).Run() -} - -func cmdStickerVideo(ctx *command.RunFuncContext, video *waProto.VideoMessage, exifPath string, webpPath string) error { - data, err := ctx.Client.Download(video) - if err != nil { - return err - } - - // Convert straight to webp then mux - tmpWebp := webpPath + ".tmp.webp" - defer os.Remove(tmpWebp) - - _, err = cli.ExecPipeline("ffmpeg", data, - "-y", "-hide_banner", "-loglevel", "error", - "-i", "pipe:0", "-f", "mp4", - "-ss", "00:00:00", "-t", "00:00:15", - "-vf", "fps=10,scale=720:-1:flags=lanczos:force_original_aspect_ratio=increase,crop=512:512,pad=512:512:(ow-iw)/2:(oh-ih)/2:color=#00000000,setsar=1", - "-compression_level", "6", - "-q:v", "60", "-loop", "0", - "-preset", "picture", "-an", "-fps_mode", "auto", - "-f", "webp", tmpWebp, - ) - if err != nil { - return err - } - - return cmdchain.Builder(). - Join("webpmux", "-set", "exif", exifPath, tmpWebp, "-o", webpPath). - Finalize().Run() -} - -func cmdStickerRewrite(ctx *command.RunFuncContext, exifPath string, webpPath string) error { - _, err := ctx.DownloadToFile(true, webpPath) - if err != nil { - return err - } - return cmdchain.Builder(). - Join("webpmux", "-set", "exif", exifPath, webpPath, "-o", webpPath). - Finalize().Run() -} -``` - -- [ ] **Step 2: Commit media converters** -```bash -git add /Users/fd/Documents/perf/cmds/media/sticker.go -git commit -m "feat: add unified media conversion functions for sticker" -``` - -### Task 3: Assemble the Main Command Registration - -**Files:** -- Modify:`/Users/fd/Documents/perf/cmds/media/sticker.go` - -**Interfaces:** -- Produces: `var sticker = &command.Command{...}` and `init()` - -- [ ] **Step 1: Write main command mapping** -```go -func init() { - embed.Commands.Add(sticker) -} - -var sticker = &command.Command{ - Name: "sticker", - Aliases: []string{"s", "stiker"}, - Category: constant.MEDIA_CATEGORY, - Description: "Create sticker from image/video or rewrite existing sticker EXIF", - RunFunc: func(ctx *command.RunFuncContext) *waProto.Message { - defer scrapper.TimeElapsed("Sticker Maker")() - ctx.SendEmoji("👌") - - exifPath, cleanupExif := resolveExif(ctx.Arguments) - defer func() { - if cleanupExif { - os.Remove(exifPath) - } - }() - - webpPath := "temp/" + util2.MakeMD5UUID() + ".webp" - defer os.Remove(webpPath) - - msg := ctx.Message - quoted := util.ParseQuotedMessage(msg) - - var err error - if msg.GetImageMessage() != nil { - err = cmdStickerImage(ctx, msg.GetImageMessage(), exifPath, webpPath) - } else if quoted.GetImageMessage() != nil { - err = cmdStickerImage(ctx, quoted.GetImageMessage(), exifPath, webpPath) - } else if msg.GetVideoMessage() != nil { - err = cmdStickerVideo(ctx, msg.GetVideoMessage(), exifPath, webpPath) - } else if quoted.GetVideoMessage() != nil { - err = cmdStickerVideo(ctx, quoted.GetVideoMessage(), exifPath, webpPath) - } else if quoted.GetStickerMessage() != nil { - err = cmdStickerRewrite(ctx, exifPath, webpPath) - } else { - return ctx.GenerateReplyMessage("error: reply to image/video/sticker or send with caption") - } - - if err != nil { - return ctx.GenerateReplyMessage("error: " + err.Error()) - } - - webpMsg, err := ctx.UploadStickerMessageFromPath(webpPath) - if err != nil { - return ctx.GenerateReplyMessage("error: " + err.Error()) - } - - return ctx.GenerateReplyMessage(webpMsg) - }, -} -``` - -- [ ] **Step 2: Remove redundant legacy files if they exist locally on perf** -Run `rm -f /Users/fd/Documents/perf/cmds/media/stickerwm.go /Users/fd/Documents/perf/cmds/media/wm.go` just in case they were copied over here (though wait, we only rewrite cmds/media/sticker.go per prompt). - -- [ ] **Step 3: Build/Test via standard go build to ensure compilation.** -Run: `go build ./...` - -- [ ] **Step 4: Commit main command registration** -```bash -git add /Users/fd/Documents/perf/cmds/media/sticker.go -git commit -m "feat: assemble and register unified sticker command" -``` - diff --git a/docs/superpowers/specs/2026-07-15-unified-sticker-design.md b/docs/superpowers/specs/2026-07-15-unified-sticker-design.md deleted file mode 100644 index a4ec862..0000000 --- a/docs/superpowers/specs/2026-07-15-unified-sticker-design.md +++ /dev/null @@ -1,16 +0,0 @@ -# Unified Sticker Maker Design - -## 1. Boot Exif -Generates temp/default.exif on boot using STICKER_NAME and STICKER_PUBLISHER environment variables if missing. - -## 2. Parameter Parsing -- Empty: uses default.exif -- 'name': Custom exif with given name -- 'name|publisher': Custom exif with parsed name and publisher. - -## 3. Media Capabilities -Detects Images, Video, and existing Stickers via Message or QuotedMessage. Converts with webpmux and uploads. - -## 4. Cleanup -Custom exifs are deleted on action deferred. Default exif persists. - diff --git a/temp/.gitignore b/temp/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/temp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file