-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
153 lines (127 loc) · 3.29 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"strings"
"syscall"
waSocket "github.com/amiruldev20/waSocket"
waProto "github.com/amiruldev20/waSocket/binary/proto"
"github.com/amiruldev20/waSocket/store"
"github.com/amiruldev20/waSocket/store/sqlstore"
"github.com/amiruldev20/waSocket/types/events"
message "github.com/danzok/Alice-wabot/system"
"github.com/joho/godotenv"
_ "github.com/mattn/go-sqlite3"
"github.com/mdp/qrterminal"
"github.com/probandula/figlet4go"
)
func main() {
//load yours variable in .env
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
//create you db sqlite3
container,
err := sqlstore.New("sqlite3", "file:yoursqlitefile.db?_foreign_keys=on", nil)
if err != nil {
log.Fatal(err)
}
// save the first device session
deviceStore,
err := container.GetFirstDevice()
if err != nil {
log.Fatal(err)
}
/* Setting env */
typeLogin := os.Getenv("TYPE_LOGIN")
numberBot := os.Getenv("NUMBER_BOT")
//client//
sock := waSocket.NewClient(deviceStore, nil)
eventHandler := registerHandler(sock)
sock.AddEventHandler(eventHandler)
/* what type of login */
if sock.Store.ID == nil {
/*type code */
if typeLogin == "code" {
fmt.Println("You login with pairing code")
fmt.Println("Bot Numer : " + numberBot)
err = sock.Connect()
if err != nil {
log.Fatal(err)
}
/* don't edit */
code,
err := sock.PairPhone(numberBot, true, waSocket.PairClientChrome, "Chrome (Alice-bot)")
if err != nil {
log.Fatal(err)
}
log.Println("Your code : " + code)
} else {
/*type qr*/
qrChan,
_ := sock.GetQRChannel(context.Background())
err = sock.Connect()
if err != nil {
panic(err)
}
for evt := range qrChan {
if evt.Event == "code" {
qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
log.Println("Please scan this QR...")
} else {
log.Println("Login successfully!! ✅")
}
}
}
} else {
/* Already logged in, just connect */
err = sock.Connect()
log.Println("Login Sucessfully!!")
if err != nil {
panic(err)
}
}
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
sock.Disconnect()
}
func init() {
ascii := figlet4go.NewAsciiRender()
options := figlet4go.NewRenderOptions()
options.FontColor = []figlet4go.Color{
// Colors can be given by default ansi color codes...
figlet4go.ColorGreen,
figlet4go.ColorYellow,
figlet4go.ColorCyan,
// ...or by an hex string...
//figlet4go.NewTrueColorFromHexString("885DBA"),
// ...or by an TrueColor object with rgb values
//figlet4go.TrueColor{136, 93, 186},
}
renderStr, _ := ascii.RenderOpts("Alice beta", options)
store.DeviceProps.PlatformType = waProto.DeviceProps_FIREFOX.Enum()
//store.DeviceProps.Os = proto.String(string(dxz))
fmt.Print(renderStr)
}
func registerHandler(sock *waSocket.Client) func(evt interface{}) {
return func(evt interface{}) {
switch v := evt.(type) {
case *events.Message:
if strings.HasPrefix(v.Info.ID, "BAE5") {
return
}
//function to view contact status
/*if v.Info.Chat.String() == "status@broadcast" {
sock.MarkRead([]types.MessageID{v.Info.ID}, v.Info.Timestamp, v.Info.Chat, v.Info.Sender)
//fmt.Println("")
}*/
go message.Msg(sock, v)
break
}
}
}