-
Notifications
You must be signed in to change notification settings - Fork 5
/
exapmple_test.go
55 lines (41 loc) · 1.54 KB
/
exapmple_test.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
package govkbot_test
import (
"fmt"
"log"
"github.com/nikepan/govkbot/v2"
)
func helpHandler(m *govkbot.Message) (reply string) {
return "Available commands: /help, /me\nYou message" + m.Body
}
func errorHandler(msg *govkbot.Message, err error) {
// Check gor VK Error code
if _, ok := err.(*govkbot.VKError); !ok {
log.Fatal(
err.(govkbot.VKError).ErrorCode,
err.Error(), msg.Body)
}
log.Fatal(err.Error(), msg.Body)
}
func addFriendHandler(m *govkbot.Message) (reply string) {
log.Printf("friend %+v added\n", m.UserID)
govkbot.NotifyAdmin(fmt.Sprintf("user vk.com/id%+v add me to friends", m.UserID))
return reply
}
func ExampleListen() {
//govkbot.HandleMessage("/", anyHandler) // any commands starts with "/"
//govkbot.HandleMessage("/me", meHandler)
govkbot.HandleMessage("/help", helpHandler) // any commands starts with "/help"
//govkbot.HandleAction("chat_invite_user", inviteHandler)
//govkbot.HandleAction("chat_kick_user", kickHandler)
govkbot.HandleAction("friend_add", addFriendHandler)
//govkbot.HandleAction("friend_delete", deleteFriendHandler)
govkbot.HandleError(errorHandler)
govkbot.SetAutoFriend(true) // enable auto accept/delete friends
govkbot.SetDebug(true) // log debug messages
// Optional Direct VK API access
govkbot.SetAPI("!!!!VK_TOKEN!!!!", "", "") // Need only before Listen, if you use direct API
me, _ := govkbot.API.Me() // call API method
log.Printf("current user: %+v\n", me.FullName())
// Optional end
govkbot.Listen("!!!!VK_TOKEN!!!!", "", "", 12345678) // start bot
}