feat: initial whatsmeow bot with command handler and context helpers
Core framework (Handler, Command, Default muxer) in core/ package. Command self-registration via init() with blank imports in cmds/. Context helpers (send, reply, download, upload) in context/ package. Permission system with GROUP_ONLY / PRIVATE_ONLY checks. WhatsApp client configured as Safari with history sync disabled.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"go.mau.fi/whatsmeow"
|
||||
waE2E "go.mau.fi/whatsmeow/proto/waE2E"
|
||||
)
|
||||
|
||||
func (c *Ctx) Download() ([]byte, error) {
|
||||
msg := getDownloadable(c.message)
|
||||
if msg == nil {
|
||||
return nil, fmt.Errorf("message has no downloadable media")
|
||||
}
|
||||
return c.client.Download(stdctx.Background(), msg)
|
||||
}
|
||||
|
||||
func (c *Ctx) DownloadQuoted() ([]byte, error) {
|
||||
quoted := GetQuotedMessage(c.event.Message)
|
||||
if quoted == nil {
|
||||
return nil, fmt.Errorf("no quoted message")
|
||||
}
|
||||
msg := getDownloadable(quoted)
|
||||
if msg == nil {
|
||||
return nil, fmt.Errorf("quoted message has no downloadable media")
|
||||
}
|
||||
return c.client.Download(stdctx.Background(), msg)
|
||||
}
|
||||
|
||||
func (c *Ctx) DownloadMessage(msg whatsmeow.DownloadableMessage) ([]byte, error) {
|
||||
return c.client.Download(stdctx.Background(), msg)
|
||||
}
|
||||
|
||||
func getDownloadable(m *waE2E.Message) whatsmeow.DownloadableMessage {
|
||||
switch {
|
||||
case m.GetImageMessage() != nil:
|
||||
return m.GetImageMessage()
|
||||
case m.GetVideoMessage() != nil:
|
||||
return m.GetVideoMessage()
|
||||
case m.GetAudioMessage() != nil:
|
||||
return m.GetAudioMessage()
|
||||
case m.GetDocumentMessage() != nil:
|
||||
return m.GetDocumentMessage()
|
||||
case m.GetStickerMessage() != nil:
|
||||
return m.GetStickerMessage()
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user