Embed autoresponder message in package variable
This commit is contained in:
parent
0453f7001d
commit
bb673b18b8
24
cmd/main.go
24
cmd/main.go
@ -5,41 +5,21 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.mau.fi/whatsmeow"
|
"go.mau.fi/whatsmeow"
|
||||||
"go.mau.fi/whatsmeow/store/sqlstore"
|
"go.mau.fi/whatsmeow/store/sqlstore"
|
||||||
"go.mau.fi/whatsmeow/types"
|
"go.mau.fi/whatsmeow/types"
|
||||||
waLog "go.mau.fi/whatsmeow/util/log"
|
waLog "go.mau.fi/whatsmeow/util/log"
|
||||||
|
|
||||||
|
waautoresponder "git.sangeeth.dev/wa-autoresponder"
|
||||||
"git.sangeeth.dev/wa-autoresponder/internal"
|
"git.sangeeth.dev/wa-autoresponder/internal"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var lastResponseTimeMap map[string]string = map[string]string{}
|
|
||||||
|
|
||||||
func areSameDay(t1, t2 time.Time) bool {
|
|
||||||
y1, m1, d1 := t1.Date()
|
|
||||||
y2, m2, d2 := t2.Date()
|
|
||||||
|
|
||||||
return y1 == y2 && m1 == m2 && d1 == d2
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// |------------------------------------------------------------------------------------------------------|
|
|
||||||
// | NOTE: You must also import the appropriate DB connector, e.g. github.com/mattn/go-sqlite3 for SQLite |
|
|
||||||
// |------------------------------------------------------------------------------------------------------|
|
|
||||||
autoResponderMessageBytes, err := os.ReadFile("message.md")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("error reading message.md: %w", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
autoResponderMessage := string(autoResponderMessageBytes)
|
|
||||||
|
|
||||||
fmt.Println("Auto responder message body:")
|
fmt.Println("Auto responder message body:")
|
||||||
fmt.Println(autoResponderMessage)
|
fmt.Println(waautoresponder.AutoResponderMessage)
|
||||||
|
|
||||||
dbLog := waLog.Stdout("Database", "DEBUG", true)
|
dbLog := waLog.Stdout("Database", "DEBUG", true)
|
||||||
container, err := sqlstore.New("sqlite3", "file:whatsapp.db?_foreign_keys=on", dbLog)
|
container, err := sqlstore.New("sqlite3", "file:whatsapp.db?_foreign_keys=on", dbLog)
|
||||||
|
6
embed.go
Normal file
6
embed.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package waautoresponder
|
||||||
|
|
||||||
|
import _ "embed"
|
||||||
|
|
||||||
|
//go:embed message.md
|
||||||
|
var AutoResponderMessage string
|
@ -9,6 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
waautoresponder "git.sangeeth.dev/wa-autoresponder"
|
||||||
"github.com/mdp/qrterminal"
|
"github.com/mdp/qrterminal"
|
||||||
"go.mau.fi/whatsmeow"
|
"go.mau.fi/whatsmeow"
|
||||||
"go.mau.fi/whatsmeow/proto/waE2E"
|
"go.mau.fi/whatsmeow/proto/waE2E"
|
||||||
@ -26,12 +27,6 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(waClient *whatsmeow.Client) *Client {
|
func NewClient(waClient *whatsmeow.Client) *Client {
|
||||||
autoResponderMessageBytes, err := os.ReadFile("message.md")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("error reading message.md: %w", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
autoResponseTimeMap := map[string]string{}
|
autoResponseTimeMap := map[string]string{}
|
||||||
|
|
||||||
fileInfo, _ := os.Stat(autoResponseTimeMapJsonFileName)
|
fileInfo, _ := os.Stat(autoResponseTimeMapJsonFileName)
|
||||||
@ -56,7 +51,7 @@ func NewClient(waClient *whatsmeow.Client) *Client {
|
|||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
WAClient: waClient,
|
WAClient: waClient,
|
||||||
message: string(autoResponderMessageBytes),
|
message: waautoresponder.AutoResponderMessage,
|
||||||
autoResponseTimeMap: autoResponseTimeMap,
|
autoResponseTimeMap: autoResponseTimeMap,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user