diff options
author | ElzorFox <elzorfox@ya.ru> | 2017-03-10 16:08:19 +0500 |
---|---|---|
committer | ElzorFox <elzorfox@ya.ru> | 2017-03-10 16:08:19 +0500 |
commit | bdbb894df1353ba2f5e8eb61a59acf901fd652e5 (patch) | |
tree | 0d0083130da959dbd1229ca1546d53395efc2942 /protocols | |
parent | 32e5ab92cc12b7274dc7fa71afede04d5145c899 (diff) |
VKontacte: code cleaning
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/VKontakte/src/vkjs.js | 306 |
1 files changed, 154 insertions, 152 deletions
diff --git a/protocols/VKontakte/src/vkjs.js b/protocols/VKontakte/src/vkjs.js index 7ef0f9a791..35be3e5852 100644 --- a/protocols/VKontakte/src/vkjs.js +++ b/protocols/VKontakte/src/vkjs.js @@ -22,8 +22,8 @@ // 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}; +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 @@ -35,28 +35,29 @@ return{"freeoffline":0,"norepeat":1,"usercount":res.length,"users":res}; // 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})}; - + 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})}; + 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 @@ -69,64 +70,64 @@ return{"freeoffline":0,"norepeat":Args.norepeat,"usercount":res.length,"users":r // 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 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 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}; +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 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}; +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}; +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 @@ -134,63 +135,64 @@ return{"dialogs":dlg, "users":users, "groups":groups.items}; // Args.statusmsg // ver 1 -var OldMsg=API.status.get(); -API.status.set({"text":"♫ " + Args.statusmsg}); +var OldMsg = API.status.get(); +API.status.set({ "text": "♫ " + 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; +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}); +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; +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="♫ "+Args.statusmsg; - API.status.set({"text":Track}); +if (Cnt == 0) { + Track = "♫ " + 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="♫ "+Args.statusmsg; - API.status.set({"text":Track}); - }else{ - Track=Tracks.items[j].owner_id+"_"+Tracks.items[j].id; - }; - API.audio.setBroadcast({"audio":Track}); + 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 = "♫ " + 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 @@ -201,16 +203,16 @@ return OldMsg; // 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}); +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; -}; +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 @@ -219,51 +221,51 @@ return 1; // 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;}; +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 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}); +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 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"}); +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}; +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 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; -}; +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
\ No newline at end of file |