-
Notifications
You must be signed in to change notification settings - Fork 1
/
kakao.go
57 lines (46 loc) · 1.21 KB
/
kakao.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
package kakaogo
import (
"fmt"
"time"
)
func New(email, password string, skip ...bool) (kakao *Kakao, err error) {
kakao = &Kakao{
email: email,
password: password,
OnReady: func() {},
OnJoin: func(packet *Packet, channel *Channel) {},
OnQuit: func(packet *Packet, channel *Channel) {},
OnMessage: func(chat *Message) {},
OnRead: func(channel *Channel, body map[string]interface{}) {},
}
if len(skip) == 0 {
var checkReg string
fmt.Print("If you have not authenticated, please press 'y' within 10 seconds: ")
ch := make(chan int)
go func() {
_, _ = fmt.Scanln(&checkReg)
ch <- 1
}()
select {
case <-ch:
if checkReg == "y" {
if err := kakao.requestPasscode(); err != nil {
return nil, err
}
fmt.Print("Check the KakaoTalk verification code with your mobile phone and enter it: ")
_, _ = fmt.Scanln(&kakao.passcode)
if err := kakao.registerDevice(); err != nil {
return nil, err
}
fmt.Println("Verification completed!")
} else {
fmt.Println("Verification passed.")
}
case <-time.After(10 * time.Second):
fmt.Println("Timed out, continue.")
}
} else {
fmt.Println("Verification skipped.")
}
return kakao, nil
}