-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
162 lines (138 loc) Β· 4.82 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
154
155
156
157
158
159
160
161
162
package main
import (
"context"
"fmt"
"math/rand"
"os"
"strings"
"time"
"os/signal"
"syscall"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/types/events"
waLog "go.mau.fi/whatsmeow/util/log"
_ "github.com/mattn/go-sqlite3"
"github.com/mdp/qrterminal"
)
func main() {
NewBot("", func(k string) { //masukkan nomor kamu yang ingin di pasangkan auto read story wa
println(k)
})
}
func registerHandler(client *whatsmeow.Client) func(evt interface{}) {
return func(evt interface{}) {
switch v := evt.(type) {
case *events.Message:
if v.Info.Chat.String() == "status@broadcast" {
if v.Info.Type != "reaction" {
sender := v.Info.Sender.String()
allowedSenders := []string{ //disini isi nomer yang ingin agar bot tidak otomatis read sw dari list nomor dibawah
}
if contains(allowedSenders, sender) {
return
}
//time.Sleep(2 * time.Minute) //ini agar 2 menit kedepan akan otomatis dibaca tiap sw
emojis := []string{"π₯", "β¨", "π", "π", "π", "π", "πΊ"} // ini terserah mau nambah emoji
rand.Seed(time.Now().UnixNano())
randomEmoji := emojis[rand.Intn(len(emojis))]
reaction := client.BuildReaction(v.Info.Chat, v.Info.Sender, v.Info.ID, randomEmoji)
extras := []whatsmeow.SendRequestExtra{}
client.MarkRead([]types.MessageID{v.Info.ID}, v.Info.Timestamp, v.Info.Chat, v.Info.Sender)
client.SendMessage(context.Background(), v.Info.Chat, reaction, extras...)
fmt.Println("Berhasil melihat status", v.Info.PushName)
}
}
}
}
}
func NewBot(id string, callback func(string)) *whatsmeow.Client {
if id == "" {
callback("Nomor ?")
return nil
}
id = strings.ReplaceAll(id, "admin", "")
dbLog := waLog.Stdout("Database", "ERROR", true)
container, err := sqlstore.New("sqlite3", "file:"+id+".db?_foreign_keys=on", dbLog)
if err != nil {
callback("Kesalahan (error)\n" + fmt.Sprintf("%s", err))
return nil
}
deviceStore, err := container.GetFirstDevice()
if err != nil {
callback("Kesalahan (error)\n" + fmt.Sprintf("%s", err))
return nil
}
clientLog := waLog.Stdout("Client", "ERROR", true)
client := whatsmeow.NewClient(deviceStore, clientLog)
client.AddEventHandler(registerHandler(client))
err = client.Connect()
if err != nil {
callback("Kesalahan (error)\n" + fmt.Sprintf("%s", err))
return nil
}
if client.Store.ID == nil {
switch int(questLogin()) {
case 1:
if err := client.Connect();
err != nil {
fmt.Println(err)
}
code, err := client.PairPhone(id, true, whatsmeow.PairClientChrome, "Chrome (Linux)")
if err != nil {
fmt.Println(err)
}
fmt.Println("Kode verifikasi anda adalah: " + code)
break
case 2:
qrChan, _ := client.GetQRChannel(context.Background())
if err := client.Connect();
err != nil {
fmt.Println(err)
}
for evt := range qrChan {
switch string(evt.Event) {
case "code":
qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
fmt.Println("Scan Qrnya!!")
break
}
}
break
default:
fmt.Println("Pilih apa?")
}
} else {
fmt.Println("Connected to readsw!!")
}
// Listen to Ctrl+C (you can also do something else that prevents the program from exiting)
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
client.Disconnect()
return client
}
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
func questLogin() int {
fmt.Println("Silahkan Pilih Opsi Login:")
fmt.Println("1. Pairing Code")
fmt.Println("2. Qr")
fmt.Print("Pilih : ")
var input int
_, err := fmt.Scanln(&input)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 0
}
return input
}