summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src/vkjs.js
blob: 7ef0f9a791608c486e3ddb270f185361ffb39c55 (plain)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Copyright (c) 2013-17 Miranda NG project (http://miranda-ng.org)
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation version 2
// of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

// Instruction:
// 1. Go to https://vk.com/editapp?id=3917910&section=functions
// 2. Create a stored procedure with the appropriate name
// 3. Copy&Paste procedure code to code field. Save it.
// 4. Create additional version(s) stored procedure (if required)


// Stored procedure name: RetrieveUserInfo = Begin
// Arguments:
// Args.userid 
// Args.fields

var res=API.users.get({"user_ids":Args.userid,"fields":Args.fields,"name_case":"nom"});
return{"freeoffline":0,"norepeat":1,"usercount":res.length,"users":res};
// Stored procedure name: RetrieveUserInfo = End

// Stored procedure name: RetrieveUsersInfo = Begin
// Arguments:
// Args.userids 
// Args.fields
// Args.norepeat 
// Args.setonline

// ver 1 
if (Args.setonline == 1)
	API.account.setOnline();
var US=[];
var res=API.users.get({"user_ids":API.friends.getOnline(),"fields":Args.fields,"name_case":"nom"});
var t=10;
while(t>0){
	US=API.users.get({"user_ids":Args.userids,"fields":Args.fields,"name_case":"nom"});
	var index=US.length;
	while(index>0){
		index=index-1;
		if(US[index].online!=0){
			res.push(US[index]);
		};
	};
	t=t-1;
	if(res.length>0)t=0;};
return{"freeoffline":1,"norepeat":Args.norepeat,"usercount":res.length,"users":res,"requests":API.friends.getRequests({"extended":0,"need_mutual":0,"out":0})};
	
// ver 2
if (Args.setonline == 1)
	API.account.setOnline();
var res=API.users.get({"user_ids":Args.userids,"fields":Args.fields,"name_case":"nom"});
return{"freeoffline":0,"norepeat":Args.norepeat,"usercount":res.length,"users":res,"requests":API.friends.getRequests({"extended":0,"need_mutual":0,"out":0})};
// Stored procedure name: RetrieveUsersInfo = End


// Stored procedure name: GetServerHistory = Begin
// Arguments:
// Args.userid
// Args.offset
// Args.reqcount
// Args.time
// Args.lastmid
// Args.once

var Hist=API.messages.getHistory({"user_id":Args.userid,"count":Args.reqcount,"offset":Args.offset});
var ext=Hist.items.length;
var index=0;
while(ext!=0) {
	if(Hist.items[index].date > Args.time) {
		if(Hist.items[index].id > Args.lastmid) {
			index=index+1;
			ext=ext-1;
		} else 
			ext=0;
	} else 
		ext=0;
	};
var ret=Hist.items.slice(0,index);
var FMsgs=ret@.fwd_messages;
var Idx=0;
var Uids=[];
while(Idx < FMsgs.length) {
	var Jdx=0;
	var CFMsgs=parseInt(FMsgs[Idx].length);
	while(Jdx<CFMsgs) {
		Uids.unshift(FMsgs[Idx][Jdx].user_id);
		Jdx=Jdx+1;
	};
	Idx=Idx+1;
};
var FUsers=API.users.get({"user_ids":Uids,"name_case":"gen"});
return{"count":index,"datetime":Args.time,"items":ret,"fwd_users":FUsers,"once":Args.once,"rcount":Args.reqcount};
// Stored procedure name: GetServerHistory = End

// Stored procedure name: RetrieveMessagesByIds = Begin
// Arguments:
// Args.mids

var Msgs=API.messages.getById({"message_ids": Args.mids});
var FMsgs=Msgs.items@.fwd_messages;
var Idx=0;
var Uids=[];
while(Idx<FMsgs.length) {
	var Jdx=0;
	var CFMsgs=parseInt(FMsgs[Idx].length);
	while(Jdx<CFMsgs) {
		Uids.unshift(FMsgs[Idx][Jdx].user_id);
		Jdx=Jdx+1;
	};
	Idx=Idx+1;
};
var FUsers=API.users.get({"user_ids":Uids,"name_case":"gen"});
return{"Msgs":Msgs,"fwd_users":FUsers};
// Stored procedure name: RetrieveMessagesByIds = End

// Stored procedure name: RetrieveUnreadMessages = Begin
// Arguments: no

var dlg=API.messages.getDialogs({"count":200});
var users=API.friends.areFriends({"user_ids":dlg.items@.message@.user_id});
var groups=API.groups.get();
return{"dialogs":dlg, "users":users, "groups":groups.items};
// Stored procedure name: RetrieveUnreadMessages = End

// Stored procedure name: RetrieveStatusMusic = Begin
// Arguments: 
// Args.statusmsg

// ver 1
var OldMsg=API.status.get();
API.status.set({"text":"&#9835; " + Args.statusmsg});
return OldMsg;

// ver 2
var CntLmt=100;
var OldMsg=API.status.get();
var Tracks=API.audio.search({"q":Args.statusmsg,"count":CntLmt,"search_own":1});
var Cnt=Tracks.count;
if(Cnt>CntLmt){ 
	Cnt=CntLmt;
}
if(Cnt==0) {
	API.audio.setBroadcast();
} else{
	var i=0;
	var j=0;
	var Track=" ";
	while(i<Cnt){
		Track=Tracks.items[i].artist+" - "+Tracks.items[i].title;
		if(Track == Args.statusmsg){
			j=i;}i=i+1;
		}
		Track=Tracks.items[j].owner_id+"_"+Tracks.items[j].id;
		API.audio.setBroadcast({"audio":Track});
};
return OldMsg;

// ver 3
var CntLmt=100;
var Track=" ";
var OldMsg=API.status.get();
var Tracks=API.audio.search({"q":Args.statusmsg,"count":CntLmt,"search_own":1});
var Cnt=Tracks.count;
if(Cnt>CntLmt){
	Cnt=CntLmt;
}
if(Cnt==0){
	Track="&#9835; "+Args.statusmsg;
	API.status.set({"text":Track});
} else {
	var i=0;
	var j=-1;
	while(i<Cnt){
		Track=Tracks.items[i].artist+" - "+Tracks.items[i].title;
		if(Track == Args.statusmsg){
			j=i;
		}
		i=i+1;
	}
	if(j==-1){
		Track="&#9835; "+Args.statusmsg;
		API.status.set({"text":Track});
	}else{
		Track=Tracks.items[j].owner_id+"_"+Tracks.items[j].id;
	};
	API.audio.setBroadcast({"audio":Track});
};
return OldMsg;
// Stored procedure name: RetrieveStatusMusic = End


// Stored procedure name: DestroyChat = Begin
// Arguments: 
// Args.chatid
// Args.userid

API.messages.removeChatUser({"chat_id": Args.chatid, "user_id": Args.userid});
var Hist = API.messages.getHistory({"chat_id":Args.chatid, "count":200});
var countMsg = Hist.count;
var itemsMsg = Hist.items@.id; 
while (countMsg > 0) { 
	API.messages.delete({"message_ids":itemsMsg});
	Hist=API.messages.getHistory({"chat_id":Args.chatid, "count":200});
	countMsg = Hist.count;
	itemsMsg = Hist.items@.id;
}; 
return 1;
// Stored procedure name: DestroyChat = End

// Stored procedure name: RetrieveChatInfo = Begin
// Arguments: 
// Args.chatid

// ver 1
var Info=API.messages.getChat({"chat_id": Args.chatid});
var ChatUsers=API.messages.getChatUsers({"chat_id":Args.chatid,"fields":"id,first_name,last_name"});
return {"info":Info,"users":ChatUsers;};


// ver 2
var Info=API.messages.getChat({"chat_id": Args.chatid});
var ChatUsers=API.messages.getChatUsers({"chat_id": Args.chatid, "fields": "id,first_name,last_name"});
var ChatMsg=API.messages.getHistory({"chat_id": Args.chatid,"count":20,"rev":0});
var UR = parseInt(ChatMsg.unread);
if(UR>20){
	if(UR>200)
		UR=200;
	ChatMsg=API.messages.getHistory({"chat_id":Args.chatid,"count":UR,"rev":0});
};
var FMsgs = ChatMsg.items@.fwd_messages;
var Idx = 0;
var Uids =[];
while (Idx < FMsgs.length){
	var Jdx = 0;
	var CFMsgs = parseInt(FMsgs[Idx].length);
	while (Jdx < CFMsgs){
		Uids.unshift(FMsgs[Idx][Jdx].user_id);
		Jdx = Jdx + 1;
	};
	Idx = Idx + 1;
};
var FUsers = API.users.get({"user_ids": Uids, "name_case":"gen"});
var MsgUsers=API.users.get({"user_ids":ChatMsg.items@.user_id,"fields":"id,first_name,last_name"});

return {"info":Info,"users":ChatUsers ,"msgs":ChatMsg,"fwd_users":FUsers,"msgs_users":MsgUsers};
// Stored procedure name: RetrieveChatInfo = End

// Stored procedure name: DestroyKickChat = Begin
// Arguments: 
// Args.chatid

var Hist = API.messages.getHistory({"chat_id":Args.chatid, "count":200});
var countMsg = Hist.count;
var itemsMsg = Hist.items@.id;
while (countMsg > 0) { 
	API.messages.delete({"message_ids":itemsMsg});
	Hist=API.messages.getHistory({"chat_id":Args.chatid, "count":200});
	countMsg = Hist.count;
	itemsMsg = Hist.items@.id;
}; 
return 1;
// Stored procedure name: DestroyKickChat = End