/
main.go
163 lines (146 loc) · 5.72 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
163
package main
import (
"math/rand"
"regexp"
"strconv"
"strings"
"test/vkapi"
"time"
)
var (
BOT_ID = "271741813" // ID бота (Panda Do-Do)
api = &vkapi.Api{}
)
func main() {
api.AccessToken = "token_here"
prefixes := []string{"Afina ", "Афина ", "бот ", "Afina, ", "Афина, ", "бот, ", "!", "0", ""}
p := make(map[string]string)
p["count"] = "1"
p["out"] = "0"
last_msg := 0
is_pause := 0
for {
m := api.Request("messages.get", p)
body := "no"
if len((vkapi.GetResponse(m, "body").(string))) != 0 {
body = (vkapi.GetResponse(m, "body").(string))
}
mid := int((vkapi.GetResponse(m, "mid")).(float64))
help_message := `=== Бот Афина ===
Доступные комманды:
` + "➡" + `Афина, помощь
` + "➡" + `Афина, привет
` + "➡" + `Афина, мику
` + "➡" + `Афина, 2Dняшку
` + "➡" + `Афина, 3Dняшку
` + "➡" + `Афина, мегумин
` + "➡" + `Афина, широ
` + "➡" + `Афина, создатель
` + "➡" + `Афина, кто
` + "➡" + `kappa, каппа, карра, KAPPA
` + "➡" + `0/, Hitler hitler
` + "➡" + `!сучкалинуса; !вайфулинуса
Author: Meryborn(https://vk.com/meryborn), 2016`
if mid > last_msg && body != "no" {
if is_pause == 0 {
for _, e := range prefixes {
switch body {
//
//Commands
//
case e + "help", e + "помощь", e + "старт":
send(help_message, "photo232317814_403576726")
case e + "hi", e + "hello":
send("Здравствуй, Семпай", "photo232317814_403576725")
case e + "создатель":
send("Meryborn(https://vk.com/meryborn)", "photo232317814_403576721")
case e + "3Dняшку":
random_photo("https://vk.com/album232317814_232070447", "Лови 3D няшку")
case e + "2Dняшку", e + "няшку":
random_photo("https://vk.com/album232317814_231917660", "Лови 2D няшку")
case e + "мику", e + "хатсуне", e + "хатсуне мику":
random_photo("https://vk.com/album232317814_231918384", "Лови Хатсуне Мику")
case e + "мегумин", e + "megumin":
random_photo("https://vk.com/album-54385020_174984625", "Лови Мегумин")
case e + "shiro", e + "широ", e + "waifu", e + "вайфу":
random_photo("vk.com/album232317814_229487221", "Лови Широ")
case e + "Hitler", e + "hitler", e + "/":
random_photo("vk.com/album232317814_232435013", "1488")
case e + "kappa", e + "каппа", e + "карра", e + "KAPPA", e + "Kappa":
random_photo("vk.com/album230766065_223378577", "SUPERKAPPA")
case e + "вайфулинуса", e + "сучкалинуса", e + "СучкаЛинуса":
random_photo("vk.com/album-90206250_213182965", "сучка подана, ссаный линус")
case e + "кто":
send("Рандомный юзер "+getRandUser(), "")
//
//Commands
//
}
last_msg = mid
}
}
}
time.Sleep(1000 * time.Millisecond)
}
}
func send(msg string, img string) {
k, v := GetUid()
api.Request("messages.send", map[string]string{k: v, "message": msg, "attachment": img})
}
func random_photo(url string, message string) {
album_id := strings.Split((strings.Split(url, "/a")[1]), "_")[1]
user_id := strings.Replace((strings.Split((strings.Split(url, "/a")[1]), "_")[0]), "lbum", "", 1)
photos_count := api.Request("photos.getAlbums", map[string]string{"owner_id": user_id, "album_ids": album_id})
size_regexp, _ := regexp.Compile("\"size\":([0-9]+)")
size, _ := strconv.Atoi(size_regexp.FindStringSubmatch(photos_count)[1])
offset := randInt(0, size-1)
p_id := api.Request("photos.get", map[string]string{"owner_id": user_id, "album_id": album_id, "offset": strconv.Itoa(offset)})
pid_regexp, _ := regexp.Compile("\"pid\":([0-9]+)")
photo_id_string := pid_regexp.FindStringSubmatch(p_id)[1]
//photo_id_int, _ := strconv.Atoi(photo_id_string)
k, v := GetUid()
api.Request("messages.send", map[string]string{"message": message,
// " №" + strconv.Itoa(offset),
k: v, "attachment": "photo" + user_id + "_" + photo_id_string})
}
//so randInt
func randInt(min int, max int) int {
rand.Seed(time.Now().UTC().UnixNano())
return min + rand.Intn(max-min)
}
//func get uid or chat id
func GetUid() (string, string) {
p := make(map[string]string)
p["count"] = "1"
p["out"] = "0"
m := api.Request("messages.get", p)
//uid
uid_regexp, _ := regexp.Compile("\"uid\":([0-9]+),\"read")
uid := uid_regexp.FindStringSubmatch(m)[1]
//uid
//chat_id
title := vkapi.GetResponse(m, "title")
if title != " ... " {
chat_id_regexp, _ := regexp.Compile("\"chat_id\":([0-9]+)")
chat_id := chat_id_regexp.FindStringSubmatch(m)[1]
return "chat_id", chat_id
} else {
return "user_id", uid
}
}
//func get random user from conference
func getRandUser() string {
params := make(map[string]string)
k, v := GetUid()
params[k] = v //chat_id : chat_number
chatUsers := api.Request("messages.getChatUsers", params)
users_regexp, _ := regexp.Compile("([0-9]+)")
users := users_regexp.FindAllStringSubmatch(chatUsers, 50)
user_id := users[rand.Intn(len(users))][0]
us_name := api.Request("users.get", map[string]string{"user_ids": user_id})
firstName_regexp, _ := regexp.Compile("\"first_name\":\"(.*)\",\"last")
lastName_regexp, _ := regexp.Compile("\"last_name\":\"(.*)\"}")
firstName := firstName_regexp.FindStringSubmatch(us_name)[1]
lastName := lastName_regexp.FindStringSubmatch(us_name)[1]
return firstName + " " + lastName // first_name.(string)
}